List of usage examples for org.springframework.security.authentication TestingAuthenticationProvider TestingAuthenticationProvider
TestingAuthenticationProvider
From source file:org.apache.wicket.security.examples.springsecurity.SpringSecureWicketTestApplication.java
@Override public void init() { ApplicationContextMock appctx = new ApplicationContextMock(); // Make injection of spring beans in wicket-related classes possible using // @SpringBean. addComponentInstantiationListener(new SpringComponentInjector(this, appctx, true)); ProviderManager authMan = new ProviderManager(); List<TestingAuthenticationProvider> providerList = new ArrayList<TestingAuthenticationProvider>(); providerList.add(new TestingAuthenticationProvider()); authMan.setProviders(providerList);// ww w . j a v a 2 s .co m // appctx.putBean("testAuthenticationProvider", authProvider); // appctx.putBean("authenticationManager", authMan); this.authenticationManager = authMan; this.setupStrategyFactory(); this.setupActionFactory(); this.setUpHive(); // this one should be called automatically ? // Wicket markup setting. getMarkupSettings().setStripComments(false); getMarkupSettings().setStripWicketTags(false); getMarkupSettings().setDefaultBeforeDisabledLink(""); getMarkupSettings().setDefaultAfterDisabledLink(""); }
From source file:ubc.pavlab.aspiredb.server.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 ww w .j ava 2 s.com*/ 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); }
From source file:ubc.pavlab.aspiredb.server.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);//from w w w. ja v a 2s.c o m putTokenInContext(token); }
From source file:ubc.pavlab.aspiredb.server.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 */// w ww .java 2 s . c o m 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); }
From source file:ubic.gemma.core.util.test.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. * * @param ctx context//from w w w .j a va 2s.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", Arrays.asList(new GrantedAuthority[] { new SimpleGrantedAuthority(AuthorityConstants.ADMIN_GROUP_AUTHORITY) })); token.setAuthenticated(true); AuthenticationTestingUtil.putTokenInContext(token); }
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);//from ww w. jav a 2 s. co 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 w w w. j a va2 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. */// w w w . java2 s . 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); }