Search in sources :

Example 1 with AuthorizationEndpoint

use of org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint in project spring-security-oauth by spring-projects.

the class AuthorizationServerEndpointsConfiguration method authorizationEndpoint.

@Bean
public AuthorizationEndpoint authorizationEndpoint() throws Exception {
    AuthorizationEndpoint authorizationEndpoint = new AuthorizationEndpoint();
    FrameworkEndpointHandlerMapping mapping = getEndpointsConfigurer().getFrameworkEndpointHandlerMapping();
    authorizationEndpoint.setUserApprovalPage(extractPath(mapping, "/oauth/confirm_access"));
    authorizationEndpoint.setProviderExceptionHandler(exceptionTranslator());
    authorizationEndpoint.setErrorPage(extractPath(mapping, "/oauth/error"));
    authorizationEndpoint.setTokenGranter(tokenGranter());
    authorizationEndpoint.setClientDetailsService(clientDetailsService);
    authorizationEndpoint.setAuthorizationCodeServices(authorizationCodeServices());
    authorizationEndpoint.setOAuth2RequestFactory(oauth2RequestFactory());
    authorizationEndpoint.setOAuth2RequestValidator(oauth2RequestValidator());
    authorizationEndpoint.setUserApprovalHandler(userApprovalHandler());
    return authorizationEndpoint;
}
Also used : FrameworkEndpointHandlerMapping(org.springframework.security.oauth2.provider.endpoint.FrameworkEndpointHandlerMapping) AuthorizationEndpoint(org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint) AbstractFactoryBean(org.springframework.beans.factory.config.AbstractFactoryBean) FactoryBean(org.springframework.beans.factory.FactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with AuthorizationEndpoint

use of org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint in project spring-boot by spring-projects.

the class OAuth2AutoConfigurationTests method testDefaultConfiguration.

@Test
public void testDefaultConfiguration() {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    this.context.register(AuthorizationAndResourceServerConfiguration.class, MinimalSecureWebApplication.class);
    this.context.refresh();
    this.context.getBean(AUTHORIZATION_SERVER_CONFIG);
    this.context.getBean(RESOURCE_SERVER_CONFIG);
    this.context.getBean(OAuth2MethodSecurityConfiguration.class);
    ClientDetails config = this.context.getBean(BaseClientDetails.class);
    AuthorizationEndpoint endpoint = this.context.getBean(AuthorizationEndpoint.class);
    UserApprovalHandler handler = (UserApprovalHandler) ReflectionTestUtils.getField(endpoint, "userApprovalHandler");
    ClientDetailsService clientDetailsService = this.context.getBean(ClientDetailsService.class);
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId(config.getClientId());
    assertThat(AopUtils.isJdkDynamicProxy(clientDetailsService)).isTrue();
    assertThat(AopUtils.getTargetClass(clientDetailsService).getName()).isEqualTo(InMemoryClientDetailsService.class.getName());
    assertThat(handler).isInstanceOf(ApprovalStoreUserApprovalHandler.class);
    assertThat(clientDetails).isEqualTo(config);
    verifyAuthentication(config);
    assertThat(this.context.getBeanNamesForType(OAuth2RestOperations.class)).isEmpty();
}
Also used : InMemoryClientDetailsService(org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ApprovalStoreUserApprovalHandler(org.springframework.security.oauth2.provider.approval.ApprovalStoreUserApprovalHandler) UserApprovalHandler(org.springframework.security.oauth2.provider.approval.UserApprovalHandler) AuthorizationEndpoint(org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) InMemoryClientDetailsService(org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService) Test(org.junit.Test)

Aggregations

AuthorizationEndpoint (org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint)2 Test (org.junit.Test)1 FactoryBean (org.springframework.beans.factory.FactoryBean)1 AbstractFactoryBean (org.springframework.beans.factory.config.AbstractFactoryBean)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)1 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)1 ApprovalStoreUserApprovalHandler (org.springframework.security.oauth2.provider.approval.ApprovalStoreUserApprovalHandler)1 UserApprovalHandler (org.springframework.security.oauth2.provider.approval.UserApprovalHandler)1 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)1 InMemoryClientDetailsService (org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService)1 FrameworkEndpointHandlerMapping (org.springframework.security.oauth2.provider.endpoint.FrameworkEndpointHandlerMapping)1