Search in sources :

Example 21 with ClientDetailsService

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

the class AuthorizationServerEndpointsConfigurer method getDefaultTokenGranters.

private List<TokenGranter> getDefaultTokenGranters() {
    ClientDetailsService clientDetails = clientDetailsService();
    AuthorizationServerTokenServices tokenServices = tokenServices();
    AuthorizationCodeServices authorizationCodeServices = authorizationCodeServices();
    OAuth2RequestFactory requestFactory = requestFactory();
    List<TokenGranter> tokenGranters = new ArrayList<TokenGranter>();
    tokenGranters.add(new AuthorizationCodeTokenGranter(tokenServices, authorizationCodeServices, clientDetails, requestFactory));
    tokenGranters.add(new RefreshTokenGranter(tokenServices, clientDetails, requestFactory));
    ImplicitTokenGranter implicit = new ImplicitTokenGranter(tokenServices, clientDetails, requestFactory);
    tokenGranters.add(implicit);
    tokenGranters.add(new ClientCredentialsTokenGranter(tokenServices, clientDetails, requestFactory));
    if (authenticationManager != null) {
        tokenGranters.add(new ResourceOwnerPasswordTokenGranter(authenticationManager, tokenServices, clientDetails, requestFactory));
    }
    return tokenGranters;
}
Also used : AuthorizationCodeServices(org.springframework.security.oauth2.provider.code.AuthorizationCodeServices) InMemoryAuthorizationCodeServices(org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices) ImplicitTokenGranter(org.springframework.security.oauth2.provider.implicit.ImplicitTokenGranter) DefaultOAuth2RequestFactory(org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory) OAuth2RequestFactory(org.springframework.security.oauth2.provider.OAuth2RequestFactory) CompositeTokenGranter(org.springframework.security.oauth2.provider.CompositeTokenGranter) ImplicitTokenGranter(org.springframework.security.oauth2.provider.implicit.ImplicitTokenGranter) RefreshTokenGranter(org.springframework.security.oauth2.provider.refresh.RefreshTokenGranter) AuthorizationCodeTokenGranter(org.springframework.security.oauth2.provider.code.AuthorizationCodeTokenGranter) ClientCredentialsTokenGranter(org.springframework.security.oauth2.provider.client.ClientCredentialsTokenGranter) TokenGranter(org.springframework.security.oauth2.provider.TokenGranter) ResourceOwnerPasswordTokenGranter(org.springframework.security.oauth2.provider.password.ResourceOwnerPasswordTokenGranter) AuthorizationServerTokenServices(org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices) AuthorizationCodeTokenGranter(org.springframework.security.oauth2.provider.code.AuthorizationCodeTokenGranter) ResourceOwnerPasswordTokenGranter(org.springframework.security.oauth2.provider.password.ResourceOwnerPasswordTokenGranter) ArrayList(java.util.ArrayList) ClientCredentialsTokenGranter(org.springframework.security.oauth2.provider.client.ClientCredentialsTokenGranter) ClientDetailsService(org.springframework.security.oauth2.provider.ClientDetailsService) InMemoryClientDetailsService(org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService) RefreshTokenGranter(org.springframework.security.oauth2.provider.refresh.RefreshTokenGranter)

Example 22 with ClientDetailsService

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

the class AuthorizationServerEndpointsConfigurer method userApprovalHandler.

private UserApprovalHandler userApprovalHandler() {
    if (userApprovalHandler == null) {
        if (approvalStore() != null) {
            ApprovalStoreUserApprovalHandler handler = new ApprovalStoreUserApprovalHandler();
            handler.setApprovalStore(approvalStore());
            handler.setRequestFactory(requestFactory());
            handler.setClientDetailsService(clientDetailsService);
            this.userApprovalHandler = handler;
        } else if (tokenStore() != null) {
            TokenStoreUserApprovalHandler userApprovalHandler = new TokenStoreUserApprovalHandler();
            userApprovalHandler.setTokenStore(tokenStore());
            userApprovalHandler.setClientDetailsService(clientDetailsService());
            userApprovalHandler.setRequestFactory(requestFactory());
            this.userApprovalHandler = userApprovalHandler;
        } else {
            throw new IllegalStateException("Either a TokenStore or an ApprovalStore must be provided");
        }
    }
    return this.userApprovalHandler;
}
Also used : TokenStoreUserApprovalHandler(org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler) ApprovalStoreUserApprovalHandler(org.springframework.security.oauth2.provider.approval.ApprovalStoreUserApprovalHandler)

Example 23 with ClientDetailsService

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

the class AuthorizationServerSecurityConfigurer method init.

@Override
public void init(HttpSecurity http) throws Exception {
    registerDefaultAuthenticationEntryPoint(http);
    if (passwordEncoder != null) {
        ClientDetailsUserDetailsService clientDetailsUserDetailsService = new ClientDetailsUserDetailsService(clientDetailsService());
        clientDetailsUserDetailsService.setPasswordEncoder(passwordEncoder());
        http.getSharedObject(AuthenticationManagerBuilder.class).userDetailsService(clientDetailsUserDetailsService).passwordEncoder(passwordEncoder());
    } else {
        http.userDetailsService(new ClientDetailsUserDetailsService(clientDetailsService()));
    }
    http.securityContext().securityContextRepository(new NullSecurityContextRepository()).and().csrf().disable().httpBasic().realmName(realm);
}
Also used : NullSecurityContextRepository(org.springframework.security.web.context.NullSecurityContextRepository) ClientDetailsUserDetailsService(org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService)

Example 24 with ClientDetailsService

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

the class InMemoryClientDetailsServiceBuilder method performBuild.

@Override
protected ClientDetailsService performBuild() {
    InMemoryClientDetailsService clientDetailsService = new InMemoryClientDetailsService();
    clientDetailsService.setClientDetailsStore(clientDetails);
    return clientDetailsService;
}
Also used : InMemoryClientDetailsService(org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService)

Example 25 with ClientDetailsService

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

the class JdbcClientDetailsServiceBuilder method performBuild.

@Override
protected ClientDetailsService performBuild() {
    Assert.state(dataSource != null, "You need to provide a DataSource");
    JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
    if (passwordEncoder != null) {
        // This is used to encode secrets as they are added to the database (if it isn't set then the user has top
        // pass in pre-encoded secrets)
        clientDetailsService.setPasswordEncoder(passwordEncoder);
    }
    for (ClientDetails client : clientDetails) {
        clientDetailsService.addClientDetails(client);
    }
    return clientDetailsService;
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) JdbcClientDetailsService(org.springframework.security.oauth2.provider.client.JdbcClientDetailsService)

Aggregations

Test (org.junit.Test)27 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)18 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)16 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)14 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)13 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)11 Authentication (org.springframework.security.core.Authentication)8 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)7 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)7 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)6 ClientRegistrationException (org.springframework.security.oauth2.provider.ClientRegistrationException)6 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)6 HashMap (java.util.HashMap)5 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)5 InMemoryClientDetailsService (org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService)5 Before (org.junit.Before)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 DefaultOAuth2RequestFactory (org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory)4 Date (java.util.Date)3 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)3