Example usage for org.springframework.security.authentication ProviderManager getProviders

List of usage examples for org.springframework.security.authentication ProviderManager getProviders

Introduction

In this page you can find the example usage for org.springframework.security.authentication ProviderManager getProviders.

Prototype

public List<AuthenticationProvider> getProviders() 

Source Link

Usage

From source file:ubic.gemma.core.util.test.BaseSpringContextTest.java

protected void logOut(ApplicationContext ctx) {
    ProviderManager providerManager = (ProviderManager) ctx.getBean("authenticationManager");
    providerManager.getProviders().add(new TestingAuthenticationProvider());

    TestingAuthenticationToken token = new TestingAuthenticationToken(AuthorityConstants.ANONYMOUS_USER_NAME,
            null, Arrays.asList(new GrantedAuthority[] {
                    new SimpleGrantedAuthority(AuthorityConstants.ANONYMOUS_GROUP_AUTHORITY) }));

    token.setAuthenticated(false);/*  w  ww  .j av  a  2  s .  c  o m*/

    AuthenticationTestingUtil.putTokenInContext(token);
}

From source file:ubic.gemma.core.util.test.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
 *
 * @param ctx      context//from   www.  j  a  v a 2 s.  co  m
 * @param username user name
 */
protected void switchToUser(ApplicationContext ctx, String username) {

    UserDetails user = userManager.loadUserByUsername(username);

    List<GrantedAuthority> grantedAuthorities = new ArrayList<>(user.getAuthorities());

    ProviderManager providerManager = (ProviderManager) ctx.getBean("authenticationManager");
    providerManager.getProviders().add(new TestingAuthenticationProvider());

    TestingAuthenticationToken token = new TestingAuthenticationToken(username, "testing", grantedAuthorities);
    token.setAuthenticated(true);

    AuthenticationTestingUtil.putTokenInContext(token);
}

From source file:ubic.gemma.testing.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.
 *//*from  w w w  .j  a  v  a2s . c o  m*/
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",
            new GrantedAuthority[] { new GrantedAuthorityImpl("GROUP_ADMIN") });

    token.setAuthenticated(true);

    putTokenInContext(token);
}