Search in sources :

Example 56 with TokenRequest

use of org.springframework.security.oauth2.provider.TokenRequest in project ORCID-Source by ORCID.

the class OrcidClientCredentialsCheckerTest method testValidCredentialsScopes.

@Test
public void testValidCredentialsScopes() throws Exception {
    String memberId = "2875-8158-1475-6194";
    String clientId = "APP-1";
    setupMocks(clientId, memberId);
    Set<String> requestedScopes = new HashSet<String>(Arrays.asList(ScopePathType.READ_PUBLIC.value()));
    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put(OrcidOauth2Constants.SCOPE_PARAM, ScopePathType.READ_PUBLIC.value());
    checker.validateCredentials("client_credentials", new TokenRequest(requestParams, clientId, requestedScopes, "client_credentials"));
}
Also used : HashMap(java.util.HashMap) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with TokenRequest

use of org.springframework.security.oauth2.provider.TokenRequest in project ORCID-Source by ORCID.

the class OrcidClientCredentialsCheckerTest method testValidCredentialsScopesForClientOnly.

@Test
public void testValidCredentialsScopesForClientOnly() throws Exception {
    String memberId = "2875-8158-1475-6194";
    String clientId = "APP-1";
    setupMocks(clientId, memberId);
    Set<String> requestedScopes = new HashSet<String>(Arrays.asList(ScopePathType.READ_PUBLIC.value()));
    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put(OrcidOauth2Constants.SCOPE_PARAM, ScopePathType.READ_PUBLIC.value());
    checker.validateCredentials("client_credentials", new TokenRequest(requestParams, clientId, requestedScopes, "client_credentials"));
}
Also used : HashMap(java.util.HashMap) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 58 with TokenRequest

use of org.springframework.security.oauth2.provider.TokenRequest in project ORCID-Source by ORCID.

the class OrcidRefreshTokenTokenGranterTest method generateRefreshToken.

private OAuth2AccessToken generateRefreshToken(OrcidOauth2TokenDetail tokenDetails, String customClientId, Boolean revokeOld, Long expiresIn, String... scopesParam) {
    Set<String> scopes = null;
    if (scopesParam != null) {
        scopes = new HashSet<String>(Arrays.asList(scopesParam));
    }
    Map<String, String> authorizationParameters = new HashMap<String, String>();
    String scopesString = scopes == null ? null : StringUtils.join(scopes, ' ');
    String clientId = PojoUtil.isEmpty(customClientId) ? tokenDetails.getClientDetailsId() : customClientId;
    String refreshTokenValue = tokenDetails.getRefreshTokenValue();
    authorizationParameters.put(OAuth2Utils.CLIENT_ID, clientId);
    authorizationParameters.put(OrcidOauth2Constants.IS_PERSISTENT, "true");
    authorizationParameters.put(OrcidOauth2Constants.AUTHORIZATION, tokenDetails.getTokenValue());
    authorizationParameters.put(OrcidOauth2Constants.REFRESH_TOKEN, refreshTokenValue);
    authorizationParameters.put(OAuth2Utils.REDIRECT_URI, tokenDetails.getRedirectUri());
    if (!PojoUtil.isEmpty(scopesString)) {
        authorizationParameters.put(OAuth2Utils.SCOPE, scopesString);
    }
    if (revokeOld != null) {
        authorizationParameters.put(OrcidOauth2Constants.REVOKE_OLD, String.valueOf(revokeOld));
    }
    if (expiresIn != null) {
        authorizationParameters.put(OrcidOauth2Constants.EXPIRES_IN, String.valueOf(expiresIn));
    }
    TokenRequest tokenRequest = new TokenRequest(authorizationParameters, clientId, scopes, OrcidOauth2Constants.REFRESH_TOKEN);
    return refreshTokenTokenGranter.grant(OrcidOauth2Constants.REFRESH_TOKEN, tokenRequest);
}
Also used : HashMap(java.util.HashMap) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest)

Aggregations

TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)40 Test (org.junit.Test)38 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)34 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)33 Authentication (org.springframework.security.core.Authentication)25 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)21 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)13 HashMap (java.util.HashMap)11 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)11 ModelAndView (org.springframework.web.servlet.ModelAndView)10 ExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken)9 TokenGranter (org.springframework.security.oauth2.provider.TokenGranter)9 RedirectView (org.springframework.web.servlet.view.RedirectView)9 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)8 DefaultExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken)7 DefaultUserApprovalHandler (org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler)7 InvalidGrantException (org.springframework.security.oauth2.common.exceptions.InvalidGrantException)6 Date (java.util.Date)5 HashSet (java.util.HashSet)5 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)5