当前位置: 首页>>代码示例>>Java>>正文


Java SecurityContextImpl.setAuthentication方法代码示例

本文整理汇总了Java中org.springframework.security.core.context.SecurityContextImpl.setAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContextImpl.setAuthentication方法的具体用法?Java SecurityContextImpl.setAuthentication怎么用?Java SecurityContextImpl.setAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.core.context.SecurityContextImpl的用法示例。


在下文中一共展示了SecurityContextImpl.setAuthentication方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Before
public void setup() {
	resource = new ResourceOwnerPasswordResourceDetails();

	resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
	resource.setClientId("my-trusted-client");
	resource.setId("sparklr");
	resource.setScope(Arrays.asList("trust"));
	resource.setUsername("marissa");
	resource.setPassword("koala");

	OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
	existingToken = template.getAccessToken();
	((DefaultOAuth2AccessToken) existingToken).setExpiration(new Date(0L));

	SecurityContextImpl securityContext = new SecurityContextImpl();
	securityContext.setAuthentication(new TestingAuthenticationToken("marissa", "koala", "ROLE_USER"));
	SecurityContextHolder.setContext(securityContext);

}
 
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:21,代码来源:RefreshTokenGrantTests.java

示例2: shouldExtractPrincipalNameFromAuthentication

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Test
public void shouldExtractPrincipalNameFromAuthentication() throws Exception {

	// given
	MongoSession toSerialize = new MongoSession();
	String principalName = "john_the_springer";
	SecurityContextImpl context = new SecurityContextImpl();
	context.setAuthentication(
			new UsernamePasswordAuthenticationToken(principalName, null));
	toSerialize.setAttribute("SPRING_SECURITY_CONTEXT", context);

	// when
	DBObject dbObject = convertToDBObject(toSerialize);

	// then
	assertThat(dbObject.get("principal")).isEqualTo(principalName);
}
 
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:18,代码来源:JdkMongoSessionConverterTest.java

示例3: setUpMockAuthenticationContext

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
    // initialise the context with the user identified by the email 
    // "[email protected]" seen as authenticated
    
    Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
    TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
    
    mockAuthentication = createMock(Authentication.class);
    SecurityContextImpl securityContextImpl = new SecurityContextImpl();
    securityContextImpl.setAuthentication(mockAuthentication);
    SecurityContextHolder.setContext(securityContextImpl);
    
    expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
    expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
    expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
    
    replay(mockAuthentication);
    
    mockAuthenticationDetails = createMock(AuthenticationDetails.class);
    expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
    replay(mockAuthenticationDetails);
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:23,代码来源:AuditSetUpControllerTest.java

示例4: setUpMockAuthenticationContext

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
    // initialise the context with the user identified by the email 
    // "[email protected]" seen as authenticated
    Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
    TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
    
    mockAuthentication = createMock(Authentication.class);
    SecurityContextImpl securityContextImpl = new SecurityContextImpl();
    securityContextImpl.setAuthentication(mockAuthentication);
    SecurityContextHolder.setContext(securityContextImpl);
    
    expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
    expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
    expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
    replay(mockAuthentication);
    
    mockAuthenticationDetails = createMock(AuthenticationDetails.class);
    expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
    replay(mockAuthenticationDetails);
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:21,代码来源:HomeControllerTest.java

示例5: setUpMockAuthenticationContext

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
    // initialise the context with the user identified by the email 
    // "[email protected]" seen as authenticated
    Collection<GrantedAuthority> gac = new ArrayList();
    TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
    
    mockAuthentication = createMock(Authentication.class);
    SecurityContextImpl securityContextImpl = new SecurityContextImpl();
    securityContextImpl.setAuthentication(mockAuthentication);
    SecurityContextHolder.setContext(securityContextImpl);
    expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
    expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
    expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
    replay(mockAuthentication);
    
    mockAuthenticationDetails = createMock(AuthenticationDetails.class);
    expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
    replay(mockAuthenticationDetails);
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:20,代码来源:ContractControllerTest.java

示例6: setUpMockAuthenticationContext

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private void setUpMockAuthenticationContext(){
    // initialise the context with the user identified by the email 
    // "[email protected]" seen as authenticated
    Collection<GrantedAuthority> gac = new ArrayList<GrantedAuthority>();
    TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockAdminUser);
    mockAuthentication = createMock(Authentication.class);
    
    SecurityContextImpl securityContextImpl = new SecurityContextImpl();
    securityContextImpl.setAuthentication(mockAuthentication);
    SecurityContextHolder.setContext(securityContextImpl);
    
    expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
    expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
    expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
    
    replay(mockAuthentication);
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:18,代码来源:UserManagementControllerTest.java

示例7: setUpMockAuthenticationContext

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
/**
 * 
 */
private void setUpMockAuthenticationContext(){
    // initialise the context with the user identified by the email 
    // "[email protected]" seen as authenticated
    Collection<GrantedAuthority> gac = new ArrayList();
    TgolUserDetails tud = new TgolUserDetails("[email protected]", "", true, false, true, true, gac, mockUser);
    mockAuthentication = createMock(Authentication.class);
    SecurityContextImpl securityContextImpl = new SecurityContextImpl();
    securityContextImpl.setAuthentication(mockAuthentication);
    SecurityContextHolder.setContext(securityContextImpl);
    expect(mockAuthentication.getName()).andReturn("[email protected]").anyTimes();
    expect(mockAuthentication.getPrincipal()).andReturn(tud).anyTimes();
    expect(mockAuthentication.getAuthorities()).andReturn(null).anyTimes();
    replay(mockAuthentication);
    
    mockAuthenticationDetails = createMock(AuthenticationDetails.class);
    expect(mockAuthenticationDetails.getContext()).andReturn("[email protected]").anyTimes();
    replay(mockAuthenticationDetails);
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:22,代码来源:PageListControllerTest.java

示例8: shouldExtractName

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Test
public void shouldExtractName() {

	// given
	String principalName = "john_the_springer";
	SecurityContextImpl context = new SecurityContextImpl();
	context.setAuthentication(new UsernamePasswordAuthenticationToken(principalName, null));

	// when
	String extractedName = AuthenticationParser.extractName(context);

	// then
	assertThat(extractedName).isEqualTo(principalName);
}
 
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:15,代码来源:AuthenticationParserTest.java

示例9: replaceContext

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
/**
 * Put new information in SecurityContextHolder.
 * 
 * @param context
 *            the security context to update.
 * @param newPrincipal
 *            the new principal to place.
 */
private void replaceContext(final SecurityContext context, final UserDetails newPrincipal) {
	final PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(newPrincipal, null);
	authentication.setDetails(newPrincipal);
	context.setAuthentication(authentication);
	final SecurityContextImpl securityContextImpl = new SecurityContextImpl();
	securityContextImpl.setAuthentication(authentication);

	// Replace the old context
	SecurityContextHolder.setContext(securityContextImpl);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:19,代码来源:SecurityHelper.java

示例10: successfulAuthentication

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult)
        throws IOException, ServletException {
    System.err.println("successfulAuthentication");
    final SecurityContextImpl sCtx = new SecurityContextImpl();
    sCtx.setAuthentication(authResult);

    // SecurityContextHolder.getContext().setAuthentication(authResult);
    final String sessionToken = sessionToken();

    hazelcastInstance.getMap("userTokenMap").put(sessionToken, sCtx);

    try (PrintWriter out = response.getWriter()) {

        final LoginResponse loginResponse = new LoginResponse();
        loginResponse.setAccessToken(sessionToken);

        if (authResult.getPrincipal() instanceof User) {
            final User user = (User) authResult.getPrincipal();
            loginResponse.setName(user.getUsername());
            loginResponse.setName(user.getUsername());
        }
        out.write(jacksonObjectMapper.writeValueAsString(loginResponse));
    }

    System.err.println("############  SUCCESSS ################");

}
 
开发者ID:tvajjala,项目名称:interview-preparation,代码行数:29,代码来源:JSONPayloadAuthenticationFilter.java

示例11: init

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Before
public void init() {
	context = new SecurityContextImpl();
	User principal = new User("USER1", "USER1", Arrays.asList(new SimpleGrantedAuthority(ROLE_MAX_WORDS + 100)));
	Authentication authentication = new TestingAuthenticationToken(principal , null,ROLE_MAX_WORDS + 100);
	context.setAuthentication(authentication);
	SecurityContextHolder.setContext(context);
}
 
开发者ID:ishaigor,项目名称:rest-retro-sample,代码行数:9,代码来源:RangeEnforcerTest.java

示例12: testRangeNoInfo

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Test
public void testRangeNoInfo() {
	context = new SecurityContextImpl();
	User principal = new User("USER1", "USER1", new ArrayList<GrantedAuthority>());
	Authentication authentication = new TestingAuthenticationToken(principal , null);
	context.setAuthentication(authentication);
	SecurityContextHolder.setContext(context);

	String queryString = "?from=101&to=150";
	String result = enforcer.enrichQueryString(queryString);
	assertThat(result).isEqualTo("?from=101&to=150");
}
 
开发者ID:ishaigor,项目名称:rest-retro-sample,代码行数:13,代码来源:RangeEnforcerTest.java

示例13: createSession

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
private Session createSession(String sessionId, String userName,
		Instant lastAccessed) {
	MapSession session = new MapSession(sessionId);
	session.setLastAccessedTime(lastAccessed);
	Authentication authentication = mock(Authentication.class);
	when(authentication.getName()).thenReturn(userName);
	SecurityContextImpl securityContext = new SecurityContextImpl();
	securityContext.setAuthentication(authentication);
	session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
	return session;
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:12,代码来源:SpringSessionBackedSessionRegistryTest.java

示例14: runAsAdmin

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Override
public <T> Supplier<T> runAsAdmin(Supplier<T> supplier) {
    // Gets the current account (if any)
    Account account = getCurrentAccount();
    // Creates a temporary admin context
    SecurityContextImpl adminContext = new SecurityContextImpl();
    adminContext.setAuthentication(new RunAsAdminAuthentication(account));
    // Returns a callable that sets the context before running the target callable
    return withSecurityContext(supplier, adminContext);
}
 
开发者ID:nemerosa,项目名称:ontrack,代码行数:11,代码来源:SecurityServiceImpl.java

示例15: setUp

import org.springframework.security.core.context.SecurityContextImpl; //导入方法依赖的package包/类
@Before
public void setUp() {
	m_databasePopulator.populateDatabase();
	m_context = new SecurityContextImpl();
	
	validAdmin = new User(USERNAME, PASS, true, true, true, true,
			Arrays.asList(new GrantedAuthority[] { ROLE_ADMIN }));
	
	/*
	invalidAdmin = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_ADMIN });
	
	validProvision = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_PROVISION });
	invalidProvision = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_PROVISION });
	
	validUser = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_USER });
	invalidUser = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_USER });

	validPower = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_ADMIN, ROLE_PROVISION });
	invalidPower = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_USER, ROLE_PROVISION });
			*/

	m_auth = new PreAuthenticatedAuthenticationToken(validAdmin, new Object());
	m_context.setAuthentication(m_auth);
	SecurityContextHolder.setContext(m_context);
	// m_securityContextService = new SpringSecurityContextService();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:34,代码来源:AssetServiceImplTest.java


注:本文中的org.springframework.security.core.context.SecurityContextImpl.setAuthentication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。