Search in sources :

Example 51 with ClientDetails

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

the class ClientDetailsUserDetailsService method loadUserByUsername.

public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    ClientDetails clientDetails;
    try {
        clientDetails = clientDetailsService.loadClientByClientId(username);
    } catch (NoSuchClientException e) {
        throw new UsernameNotFoundException(e.getMessage(), e);
    }
    String clientSecret = clientDetails.getClientSecret();
    if (clientSecret == null || clientSecret.trim().length() == 0) {
        clientSecret = emptyPassword;
    }
    return new User(username, clientSecret, clientDetails.getAuthorities());
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) User(org.springframework.security.core.userdetails.User) NoSuchClientException(org.springframework.security.oauth2.provider.NoSuchClientException)

Example 52 with ClientDetails

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

the class DefaultTokenServices method getAccessTokenValiditySeconds.

/**
	 * The access token validity period in seconds
	 * 
	 * @param clientAuth the current authorization request
	 * @return the access token validity period in seconds
	 */
protected int getAccessTokenValiditySeconds(OAuth2Request clientAuth) {
    if (clientDetailsService != null) {
        ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
        Integer validity = client.getAccessTokenValiditySeconds();
        if (validity != null) {
            return validity;
        }
    }
    return accessTokenValiditySeconds;
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails)

Example 53 with ClientDetails

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

the class DefaultTokenServices method getRefreshTokenValiditySeconds.

/**
	 * The refresh token validity period in seconds
	 * 
	 * @param clientAuth the current authorization request
	 * @return the refresh token validity period in seconds
	 */
protected int getRefreshTokenValiditySeconds(OAuth2Request clientAuth) {
    if (clientDetailsService != null) {
        ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
        Integer validity = client.getRefreshTokenValiditySeconds();
        if (validity != null) {
            return validity;
        }
    }
    return refreshTokenValiditySeconds;
}
Also used : ClientDetails(org.springframework.security.oauth2.provider.ClientDetails)

Example 54 with ClientDetails

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

the class DefaultOAuth2RequestFactory method createTokenRequest.

public TokenRequest createTokenRequest(Map<String, String> requestParameters, ClientDetails authenticatedClient) {
    String clientId = requestParameters.get(OAuth2Utils.CLIENT_ID);
    if (clientId == null) {
        // if the clientId wasn't passed in in the map, we add pull it from the authenticated client object
        clientId = authenticatedClient.getClientId();
    } else {
        // otherwise, make sure that they match
        if (!clientId.equals(authenticatedClient.getClientId())) {
            throw new InvalidClientException("Given client ID does not match authenticated client");
        }
    }
    String grantType = requestParameters.get(OAuth2Utils.GRANT_TYPE);
    Set<String> scopes = extractScopes(requestParameters, clientId);
    TokenRequest tokenRequest = new TokenRequest(requestParameters, clientId, scopes, grantType);
    return tokenRequest;
}
Also used : InvalidClientException(org.springframework.security.oauth2.common.exceptions.InvalidClientException) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest)

Example 55 with ClientDetails

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

the class DefaultOAuth2RequestFactory method createAuthorizationRequest.

public AuthorizationRequest createAuthorizationRequest(Map<String, String> authorizationParameters) {
    String clientId = authorizationParameters.get(OAuth2Utils.CLIENT_ID);
    String state = authorizationParameters.get(OAuth2Utils.STATE);
    String redirectUri = authorizationParameters.get(OAuth2Utils.REDIRECT_URI);
    Set<String> responseTypes = OAuth2Utils.parseParameterList(authorizationParameters.get(OAuth2Utils.RESPONSE_TYPE));
    Set<String> scopes = extractScopes(authorizationParameters, clientId);
    AuthorizationRequest request = new AuthorizationRequest(authorizationParameters, Collections.<String, String>emptyMap(), clientId, scopes, null, null, false, state, redirectUri, responseTypes);
    ClientDetails clientDetails = clientDetailsService.loadClientByClientId(clientId);
    request.setResourceIdsAndAuthoritiesFromClientDetails(clientDetails);
    return request;
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails)

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