/**
* Grant authority to a test user, with admin privileges, and put the token in the context. This means your tests
* will be authorized to do anything an administrator would be able to do.
*/
protected void grantAdminAuthority( ApplicationContext ctx ) {
ProviderManager providerManager = ( ProviderManager ) ctx.getBean( "authenticationManager" );
providerManager.getProviders().add( new TestingAuthenticationProvider() );
// Grant all roles to test user.
TestingAuthenticationToken token = new TestingAuthenticationToken( "administrator", "administrator",
Arrays.asList( new GrantedAuthority[] { new SimpleGrantedAuthority(
AuthorityConstants.ADMIN_GROUP_AUTHORITY ) } ) );
token.setAuthenticated( true );
putTokenInContext( token );
}
java类org.springframework.security.authentication.TestingAuthenticationProvider的实例源码
BaseSpringContextTest.java 文件源码
项目:modinvreg
阅读 31
收藏 0
点赞 0
评论 0
BaseSpringContextTest.java 文件源码
项目:modinvreg
阅读 31
收藏 0
点赞 0
评论 0
protected void grantAnonAuthority( ApplicationContext ctx ) {
ProviderManager providerManager = ( ProviderManager ) ctx.getBean( "authenticationManager" );
providerManager.getProviders().add( new TestingAuthenticationProvider() );
// Grant all roles to test user.
TestingAuthenticationToken token = new TestingAuthenticationToken( "anon", "anon",
Arrays.asList( new GrantedAuthority[] { new SimpleGrantedAuthority(
AuthorityConstants.IS_AUTHENTICATED_ANONYMOUSLY ) } ) );
token.setAuthenticated( true );
putTokenInContext( token );
}
UserDetailsServiceConfigurationTest.java 文件源码
项目:configurable-single-user-spring-boot-starter
阅读 31
收藏 0
点赞 0
评论 0
@Bean
public AuthenticationProvider authenticationProvider() {
return new TestingAuthenticationProvider();
}
BaseSpringContextTest.java 文件源码
项目:modinvreg
阅读 36
收藏 0
点赞 0
评论 0
/**
* Grant authority to a test user, with regular user privileges, and put the token in the context. This means your
* tests will be authorized to do anything that user could do
*/
protected void switchToUser( ApplicationContext ctx, String username ) {
UserDetails user = userManager.loadUserByUsername( username );
List<GrantedAuthority> authrs = new ArrayList<GrantedAuthority>( user.getAuthorities() );
ProviderManager providerManager = ( ProviderManager ) ctx.getBean( "authenticationManager" );
providerManager.getProviders().add( new TestingAuthenticationProvider() );
TestingAuthenticationToken token = new TestingAuthenticationToken( username, "testing", authrs );
token.setAuthenticated( true );
putTokenInContext( token );
}