Search in sources :

Example 1 with OAuth2AuthenticationProcessingFilter

use of org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter in project spring-security-oauth by spring-projects.

the class ResourceServerBeanDefinitionParserTests method testAuthenticationManager.

@Test
public void testAuthenticationManager() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext(getClass(), "resource-server-authmanager-context.xml");
    // System.err.println(Arrays.asList(context.getBeanDefinitionNames()));
    assertTrue(context.containsBeanDefinition("oauth2ProviderFilter"));
    OAuth2AuthenticationProcessingFilter filter = context.getBean(OAuth2AuthenticationProcessingFilter.class);
    assertEquals(context.getBean(AuthenticationManager.class), ReflectionTestUtils.getField(filter, "authenticationManager"));
    assertNotNull(ReflectionTestUtils.getField(filter, "tokenExtractor"));
    context.close();
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) OAuth2AuthenticationProcessingFilter(org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Example 2 with OAuth2AuthenticationProcessingFilter

use of org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter in project spring-security-oauth by spring-projects.

the class ResourceServerSecurityConfigurer method configure.

@Override
public void configure(HttpSecurity http) throws Exception {
    AuthenticationManager oauthAuthenticationManager = oauthAuthenticationManager(http);
    resourcesServerFilter = new OAuth2AuthenticationProcessingFilter();
    resourcesServerFilter.setAuthenticationEntryPoint(authenticationEntryPoint);
    resourcesServerFilter.setAuthenticationManager(oauthAuthenticationManager);
    if (eventPublisher != null) {
        resourcesServerFilter.setAuthenticationEventPublisher(eventPublisher);
    }
    if (tokenExtractor != null) {
        resourcesServerFilter.setTokenExtractor(tokenExtractor);
    }
    resourcesServerFilter = postProcess(resourcesServerFilter);
    resourcesServerFilter.setStateless(stateless);
    // @formatter:off
    http.authorizeRequests().expressionHandler(expressionHandler).and().addFilterBefore(resourcesServerFilter, AbstractPreAuthenticatedProcessingFilter.class).exceptionHandling().accessDeniedHandler(accessDeniedHandler).authenticationEntryPoint(authenticationEntryPoint);
// @formatter:on
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) OAuth2AuthenticationManager(org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationManager) AbstractPreAuthenticatedProcessingFilter(org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter) OAuth2AuthenticationProcessingFilter(org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter)

Aggregations

AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)2 OAuth2AuthenticationProcessingFilter (org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter)2 Test (org.junit.Test)1 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)1 OAuth2AuthenticationManager (org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationManager)1 AbstractPreAuthenticatedProcessingFilter (org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter)1