本文整理汇总了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);
}
示例2: tearDown
import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@After
public void tearDown() {
if (originalContext != null) {
SecurityContextHolder.setContext(originalContext);
}
verifyNoMoreInteractions(chain);
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例7: afterAll
import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@AfterClass
public static void afterAll() {
SecurityContextHolder.setContext(originalContext);
}
示例8: tearDown
import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
if (originalSecurityContext != null) {
SecurityContextHolder.setContext(originalSecurityContext);
}
}
示例9: teardown
import org.springframework.security.context.SecurityContextHolder; //导入方法依赖的package包/类
@After public void teardown() throws Exception {
if (originalSecurityContext != null) {
SecurityContextHolder.setContext(originalSecurityContext);
}
configHelper.onTearDown();
}
示例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);
}