if (includeGrantType && authentication.getOAuth2Request().getGrantType()!=null) { response.put(GRANT_TYPE, authentication.getOAuth2Request().getGrantType());
if(client.getAuthorizedGrantTypes().contains(GRANT_TYPE_REFRESH_TOKEN)){ RefreshTokenRequestData refreshTokenRequestData = new RefreshTokenRequestData( oAuth2Request.getGrantType(), oAuth2Request.getScope(), authenticationMethods,
/** * The access token validity period in seconds * * @param authorizationRequest * the current authorization request * @return the access token validity period in seconds */ @Override protected int getAccessTokenValiditySeconds(OAuth2Request authorizationRequest) { Set<ScopePathType> requestedScopes = ScopePathType.getScopesFromStrings(authorizationRequest.getScope()); if (isClientCredentialsGrantType(authorizationRequest)) { boolean allAreClientCredentialsScopes = true; for (ScopePathType scope : requestedScopes) { if (!scope.isClientCreditalScope()) { allAreClientCredentialsScopes = false; break; } } if (allAreClientCredentialsScopes) { return readValiditySeconds; } } else if(OrcidOauth2Constants.IMPLICIT_GRANT_TYPE.equals(authorizationRequest.getGrantType())){ return implicitValiditySeconds; } else if(OrcidOauth2Constants.IETF_EXCHANGE_GRANT_TYPE.equals(authorizationRequest.getGrantType())) { return ietfTokenExchangeValiditySeconds; } else if (isPersistentTokenEnabled(authorizationRequest)) { return readValiditySeconds; } return writeValiditySeconds; }
@Override public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) { String principal = authentication.getPrincipal().toString(); String clientId = authentication.getOAuth2Request().getClientId(); String grantType = authentication.getOAuth2Request().getGrantType(); return this.getAccessToken(principal, clientId, grantType); }
if (!OrcidOauth2Constants.IMPLICIT_GRANT_TYPE.equals(authentication.getOAuth2Request().getGrantType())){
@Test public void readAuthenticationForRefreshToken() throws Exception { when(this.stat.executeQuery()).thenReturn(res); Mockito.when(res.next()).thenReturn(true).thenReturn(false); Mockito.when(res.getString("localuser")).thenReturn("username"); Mockito.when(res.getString("clientid")).thenReturn("client_id"); Mockito.when(res.getString("granttype")).thenReturn("password"); OAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken("value_X1"); OAuth2Authentication auth = this.tokenDAO.readAuthenticationForRefreshToken(refreshToken); Assert.assertNotNull(auth); Assert.assertEquals("username", auth.getPrincipal()); Assert.assertEquals("password", auth.getOAuth2Request().getGrantType()); Mockito.verify(stat, Mockito.times(1)).setString(Mockito.anyInt(), Mockito.anyString()); Mockito.verify(res, Mockito.times(3)).getString(Mockito.anyString()); Mockito.verify(res, Mockito.times(0)).getTimestamp(Mockito.anyString()); Mockito.verify(stat, Mockito.times(1)).close(); Mockito.verify(res, Mockito.times(1)).close(); Mockito.verify(conn, Mockito.times(1)).close(); }
if (includeGrantType && authentication.getOAuth2Request().getGrantType()!=null) { response.put(GRANT_TYPE, authentication.getOAuth2Request().getGrantType());
private DefaultOAuth2AccessToken generateAccessToken(OAuth2Authentication authentication) { DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(UUID.randomUUID().toString()); int validitySeconds = getAccessTokenValiditySeconds(authentication.getOAuth2Request()); if (validitySeconds > 0) { accessToken.setExpiration(new Date(System.currentTimeMillis() + (validitySeconds * 1000L))); } accessToken.setScope(authentication.getOAuth2Request().getScope()); if(customTokenEnhancer != null) { accessToken = new DefaultOAuth2AccessToken(customTokenEnhancer.enhance(accessToken, authentication)); } if(!OrcidOauth2Constants.IETF_EXCHANGE_GRANT_TYPE.equals(authentication.getOAuth2Request().getGrantType()) && this.isSupportRefreshToken(authentication.getOAuth2Request())) { OAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken(UUID.randomUUID().toString()); accessToken.setRefreshToken(refreshToken); } return accessToken; }
} else { if (null != authentication.getOAuth2Request()) { stat.setString(5, authentication.getOAuth2Request().getGrantType()); } else { stat.setNull(5, Types.VARCHAR);
scopes.add("scope2"); when(oauth2Request.getGrantType()).thenReturn(grantType); when(authentication.getDetails()).thenReturn(authDetails); when(authDetails.getTokenValue()).thenReturn("tokenValue");
if (OrcidOauth2Constants.IMPLICIT_GRANT_TYPE.equals(authentication.getOAuth2Request().getGrantType())) {
if(OrcidOauth2Constants.IETF_EXCHANGE_GRANT_TYPE.equals(authentication.getOAuth2Request().getGrantType()) && authentication.getOAuth2Request().getRequestParameters().containsKey(OrcidOauth2Constants.IETF_EXCHANGE_SUBJECT_TOKEN) && OrcidOauth2Constants.IETF_EXCHANGE_ID_TOKEN.equals(authentication.getOAuth2Request().getRequestParameters().get(OrcidOauth2Constants.IETF_EXCHANGE_SUBJECT_TOKEN_TYPE))) {