Java 类org.springframework.security.authentication.TestingAuthenticationProvider 实例源码

项目:modinvreg    文件:BaseSpringContextTest.java   
/**
 * 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 );
}
项目:modinvreg    文件:BaseSpringContextTest.java   
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 );
}
项目:configurable-single-user-spring-boot-starter    文件:UserDetailsServiceConfigurationTest.java   
@Bean
public AuthenticationProvider authenticationProvider() {
    return new TestingAuthenticationProvider();
}
项目:modinvreg    文件:BaseSpringContextTest.java   
/**
 * 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 );
}