Search in sources :

Example 46 with ClientDetails

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

the class SparklrUserApprovalHandler method checkForPreApproval.

/**
	 * Allows automatic approval for a white list of clients in the implicit grant case.
	 * 
	 * @param authorizationRequest The authorization request.
	 * @param userAuthentication the current user authentication
	 * 
	 * @return An updated request if it has already been approved by the current user.
	 */
@Override
public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
    boolean approved = false;
    // If we are allowed to check existing approvals this will short circuit the decision
    if (useApprovalStore) {
        authorizationRequest = super.checkForPreApproval(authorizationRequest, userAuthentication);
        approved = authorizationRequest.isApproved();
    } else {
        if (clientDetailsService != null) {
            Collection<String> requestedScopes = authorizationRequest.getScope();
            try {
                ClientDetails client = clientDetailsService.loadClientByClientId(authorizationRequest.getClientId());
                for (String scope : requestedScopes) {
                    if (client.isAutoApprove(scope)) {
                        approved = true;
                        break;
                    }
                }
            } catch (ClientRegistrationException e) {
            }
        }
    }
    authorizationRequest.setApproved(approved);
    return authorizationRequest;
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) ClientRegistrationException(org.springframework.security.oauth2.provider.ClientRegistrationException)

Example 47 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails 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 48 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails 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 49 with ClientDetails

use of org.springframework.security.oauth2.provider.ClientDetails 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)

Example 50 with ClientDetails

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

the class ResourceServerSecurityConfigurer method tokenServices.

private ResourceServerTokenServices tokenServices(HttpSecurity http) {
    if (resourceTokenServices != null) {
        return resourceTokenServices;
    }
    DefaultTokenServices tokenServices = new DefaultTokenServices();
    tokenServices.setTokenStore(tokenStore());
    tokenServices.setSupportRefreshToken(true);
    tokenServices.setClientDetailsService(clientDetails());
    this.resourceTokenServices = tokenServices;
    return tokenServices;
}
Also used : DefaultTokenServices(org.springframework.security.oauth2.provider.token.DefaultTokenServices)

Aggregations

ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)40 Test (org.junit.Test)34 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)28 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)23 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)19 Authentication (org.springframework.security.core.Authentication)18 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)16 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)14 Date (java.util.Date)13 HashMap (java.util.HashMap)11 ClientDetailsService (org.springframework.security.oauth2.provider.ClientDetailsService)7 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)6 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)6 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)6 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)6 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)6 OrcidOauth2ClientAuthentication (org.orcid.core.oauth.OrcidOauth2ClientAuthentication)5 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)5 InvalidClientException (org.springframework.security.oauth2.common.exceptions.InvalidClientException)5