Search in sources :

Example 1 with AnonymousAuthenticationProvider

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);
}
Also used : Authentication(org.springframework.security.core.Authentication) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) AnonymousAuthenticationProvider(org.springframework.security.authentication.AnonymousAuthenticationProvider)

Example 2 with AnonymousAuthenticationProvider

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");
}
Also used : AnonymousAuthenticationProvider(org.springframework.security.authentication.AnonymousAuthenticationProvider)

Example 3 with AnonymousAuthenticationProvider

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();
}
Also used : TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) AnonymousAuthenticationProvider(org.springframework.security.authentication.AnonymousAuthenticationProvider)

Example 4 with AnonymousAuthenticationProvider

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();
    }
}
Also used : ResourceServerSecurityConfigurer(org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer) ResourceServerTokenServices(org.springframework.security.oauth2.provider.token.ResourceServerTokenServices) AnonymousAuthenticationProvider(org.springframework.security.authentication.AnonymousAuthenticationProvider)

Example 5 with AnonymousAuthenticationProvider

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);
}
Also used : AnonymousAuthenticationFilter(org.springframework.security.web.authentication.AnonymousAuthenticationFilter) AnonymousAuthenticationProvider(org.springframework.security.authentication.AnonymousAuthenticationProvider)

Aggregations

AnonymousAuthenticationProvider (org.springframework.security.authentication.AnonymousAuthenticationProvider)7 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)2 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 ResourceServerSecurityConfigurer (org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer)1 ResourceServerTokenServices (org.springframework.security.oauth2.provider.token.ResourceServerTokenServices)1 AnonymousAuthenticationFilter (org.springframework.security.web.authentication.AnonymousAuthenticationFilter)1