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


Java SecurityContextHolder.setContext方法代码示例

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


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

示例1: setUp

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    securityContext = mock(SecurityContext.class);
    SecurityContextHolder.setContext(securityContext);
    authenticationManager = mock(AuthenticationManager.class);
    filter = new OauthAuthenticationFilter(authenticationManager);
    req = mock(HttpServletRequest.class);
    res = mock(HttpServletResponse.class);
    chain = mock(FilterChain.class);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:11,代码来源:OauthAuthenticationFilterTest.java

示例2: tearDown

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@After
public void tearDown() {
    if (originalContext != null) {
        SecurityContextHolder.setContext(originalContext);
    }
    verifyNoMoreInteractions(chain);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:8,代码来源:UserEnabledCheckFilterTest.java

示例3: stubSecurityContextForGrantedAuthorities

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
private static void stubSecurityContextForGrantedAuthorities(GrantedAuthority[] grantedAuthorities) {
    SecurityContext context = mock(SecurityContext.class);
    Authentication authentication = mock(Authentication.class);
    when(context.getAuthentication()).thenReturn(authentication);
    when(authentication.getAuthorities()).thenReturn(grantedAuthorities);
    SecurityContextHolder.setContext(context);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:8,代码来源:UserHelperTest.java

示例4: setUp

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
	SecurityContext context = new SecurityContextImpl();
	User principal = new User(USERNAME, PASS, true, true, true, true,
			new GrantedAuthority[] { ROLE_ADMIN, ROLE_PROVISION });
	Authentication auth = new PreAuthenticatedAuthenticationToken(
			principal, new Object());
	context.setAuthentication(auth);
	SecurityContextHolder.setContext(context);
	this.m_securityContextService = new SpringSecurityContextService();
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:12,代码来源:SpringSecurityContextServiceTest.java

示例5: setUp

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@Before
public void setUp() {
	m_databasePopulator.populateDatabase();
	m_context = new SecurityContextImpl();
	
	validAdmin = new User(USERNAME, PASS, true, true, true, true,
			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:vishwaabhinav,项目名称:OpenNMS,代码行数:34,代码来源:AssetServiceImplTest.java

示例6: setCurrentUserWithAuthorities

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
public static void setCurrentUserWithAuthorities(String username, final GrantedAuthority[] authorities) {
    SecurityContextImpl context = new SecurityContextImpl();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User(username, "", true, authorities), null, authorities));
    SecurityContextHolder.setContext(context);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:6,代码来源:SecurityContextHelper.java

示例7: afterAll

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@AfterClass
public static void afterAll() {
    SecurityContextHolder.setContext(originalContext);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:5,代码来源:OauthAuthenticationFilterTest.java

示例8: tearDown

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
    if (originalSecurityContext != null) {
        SecurityContextHolder.setContext(originalSecurityContext);
    }
}
 
开发者ID:gocd,项目名称:gocd,代码行数:7,代码来源:UserHelperTest.java

示例9: teardown

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@After public void teardown() throws Exception {
    if (originalSecurityContext != null) {
        SecurityContextHolder.setContext(originalSecurityContext);
    }
    configHelper.onTearDown();
}
 
开发者ID:gocd,项目名称:gocd,代码行数:7,代码来源:GoConfigAdministrationControllerIntegrationTest.java

示例10: setCurrentUser

import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
private void setCurrentUser(String username) {
    SecurityContextImpl context = new SecurityContextImpl();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User(username, "", true, new GrantedAuthority[]{}), null));
    SecurityContextHolder.setContext(context);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:6,代码来源:GoConfigAdministrationControllerIntegrationTest.java


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