use of org.springframework.security.authentication.AnonymousAuthenticationProvider in project spring-security by spring-projects.
the class AnonymousAuthenticationProviderTests method testNormalOperation.
@Test
public void testNormalOperation() throws Exception {
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("qwerty", "Test", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
Authentication result = aap.authenticate(token);
assertThat(token).isEqualTo(result);
}
use of org.springframework.security.authentication.AnonymousAuthenticationProvider in project spring-security by spring-projects.
the class AnonymousAuthenticationProviderTests method testGettersSetters.
@Test
public void testGettersSetters() throws Exception {
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
assertThat(aap.getKey()).isEqualTo("qwerty");
}
use of org.springframework.security.authentication.AnonymousAuthenticationProvider in project spring-security by spring-projects.
the class AnonymousAuthenticationProviderTests method testIgnoresClassesItDoesNotSupport.
@Test
public void testIgnoresClassesItDoesNotSupport() throws Exception {
AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider("qwerty");
TestingAuthenticationToken token = new TestingAuthenticationToken("user", "password", "ROLE_A");
assertThat(aap.supports(TestingAuthenticationToken.class)).isFalse();
// Try it anyway
assertThat(aap.authenticate(token)).isNull();
}
use of org.springframework.security.authentication.AnonymousAuthenticationProvider in project spring-security-oauth by spring-projects.
the class ResourceServerConfiguration method configure.
@Override
protected void configure(HttpSecurity http) throws Exception {
ResourceServerSecurityConfigurer resources = new ResourceServerSecurityConfigurer();
ResourceServerTokenServices services = resolveTokenServices();
if (services != null) {
resources.tokenServices(services);
} else {
if (tokenStore != null) {
resources.tokenStore(tokenStore);
} else if (endpoints != null) {
resources.tokenStore(endpoints.getEndpointsConfigurer().getTokenStore());
}
}
if (eventPublisher != null) {
resources.eventPublisher(eventPublisher);
}
for (ResourceServerConfigurer configurer : configurers) {
configurer.configure(resources);
}
// @formatter:off
http.authenticationProvider(new AnonymousAuthenticationProvider("default")).exceptionHandling().accessDeniedHandler(resources.getAccessDeniedHandler()).and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().csrf().disable();
// @formatter:on
http.apply(resources);
if (endpoints != null) {
// Assume we are in an Authorization Server
http.requestMatcher(new NotOAuthRequestMatcher(endpoints.oauth2EndpointHandlerMapping()));
}
for (ResourceServerConfigurer configurer : configurers) {
// Delegates can add authorizeRequests() here
configurer.configure(http);
}
if (configurers.isEmpty()) {
// Add anyRequest() last as a fall back. Spring Security would
// replace an existing anyRequest() matcher with this one, so to
// avoid that we only add it if the user hasn't configured anything.
http.authorizeRequests().anyRequest().authenticated();
}
}
use of org.springframework.security.authentication.AnonymousAuthenticationProvider in project spring-security by spring-projects.
the class AnonymousConfigurer method init.
@Override
public void init(H http) throws Exception {
if (authenticationProvider == null) {
authenticationProvider = new AnonymousAuthenticationProvider(getKey());
}
if (authenticationFilter == null) {
authenticationFilter = new AnonymousAuthenticationFilter(getKey(), principal, authorities);
}
authenticationProvider = postProcess(authenticationProvider);
http.authenticationProvider(authenticationProvider);
}
Aggregations