org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO Java Examples
The following examples show how to use
org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccessTokenIssuer.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Add user attributes to cache. * * @param tokenReqDTO * @param tokenRespDTO */ private void addUserAttributesToCache(OAuth2AccessTokenReqDTO tokenReqDTO, OAuth2AccessTokenRespDTO tokenRespDTO) { AuthorizationGrantCacheKey oldCacheKey = new AuthorizationGrantCacheKey(tokenReqDTO.getAuthorizationCode()); //checking getUserAttributesId value of cacheKey before retrieve entry from cache as it causes to NPE if (oldCacheKey.getUserAttributesId() != null) { AuthorizationGrantCacheEntry authorizationGrantCacheEntry = AuthorizationGrantCache.getInstance().getValueFromCacheByCode(oldCacheKey); AuthorizationGrantCacheKey newCacheKey = new AuthorizationGrantCacheKey(tokenRespDTO.getAccessToken()); authorizationGrantCacheEntry.setTokenId(tokenRespDTO.getTokenId()); if (AuthorizationGrantCache.getInstance().getValueFromCacheByToken(newCacheKey) == null) { if(log.isDebugEnabled()){ log.debug("No AuthorizationGrantCache entry found for the access token:"+ newCacheKey.getUserAttributesId()+ ", hence adding to cache"); } AuthorizationGrantCache.getInstance().addToCacheByToken(newCacheKey, authorizationGrantCacheEntry); AuthorizationGrantCache.getInstance().clearCacheEntryByCode(oldCacheKey); } else{ //if the user attributes are already saved for access token, no need to add again. } } }
Example #2
Source File: OAuth2TokenEndpoint.java From carbon-identity with Apache License 2.0 | 5 votes |
private OAuth2AccessTokenRespDTO getAccessToken(CarbonOAuthTokenRequest oauthRequest) { OAuth2AccessTokenReqDTO tokenReqDTO = new OAuth2AccessTokenReqDTO(); String grantType = oauthRequest.getGrantType(); tokenReqDTO.setGrantType(grantType); tokenReqDTO.setClientId(oauthRequest.getClientId()); tokenReqDTO.setClientSecret(oauthRequest.getClientSecret()); tokenReqDTO.setCallbackURI(oauthRequest.getRedirectURI()); tokenReqDTO.setScope(oauthRequest.getScopes().toArray(new String[oauthRequest.getScopes().size()])); tokenReqDTO.setTenantDomain(oauthRequest.getTenantDomain()); // Check the grant type and set the corresponding parameters if (GrantType.AUTHORIZATION_CODE.toString().equals(grantType)) { tokenReqDTO.setAuthorizationCode(oauthRequest.getCode()); } else if (GrantType.PASSWORD.toString().equals(grantType)) { tokenReqDTO.setResourceOwnerUsername(oauthRequest.getUsername()); tokenReqDTO.setResourceOwnerPassword(oauthRequest.getPassword()); } else if (GrantType.REFRESH_TOKEN.toString().equals(grantType)) { tokenReqDTO.setRefreshToken(oauthRequest.getRefreshToken()); } else if (org.wso2.carbon.identity.oauth.common.GrantType.SAML20_BEARER.toString().equals(grantType)) { tokenReqDTO.setAssertion(oauthRequest.getAssertion()); } else if (org.wso2.carbon.identity.oauth.common.GrantType.IWA_NTLM.toString().equals(grantType)) { tokenReqDTO.setWindowsToken(oauthRequest.getWindowsToken()); } else { // Set all request parameters to the OAuth2AccessTokenReqDTO tokenReqDTO.setRequestParameters(oauthRequest.getRequestParameters()); } return EndpointUtil.getOAuth2Service().issueAccessToken(tokenReqDTO); }
Example #3
Source File: AccessTokenIssuer.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Set headers in OAuth2AccessTokenRespDTO * @param tokReqMsgCtx * @param tokenRespDTO */ private void setResponseHeaders(OAuthTokenReqMessageContext tokReqMsgCtx, OAuth2AccessTokenRespDTO tokenRespDTO) { if (tokReqMsgCtx.getProperty("RESPONSE_HEADERS") != null) { tokenRespDTO.setResponseHeaders((ResponseHeader[]) tokReqMsgCtx.getProperty("RESPONSE_HEADERS")); } }
Example #4
Source File: AuthorizationCodeGrantHandler.java From carbon-identity with Apache License 2.0 | 5 votes |
@Override public OAuth2AccessTokenRespDTO issue(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception { OAuth2AccessTokenRespDTO tokenRespDTO = super.issue(tokReqMsgCtx); // get the token from the OAuthTokenReqMessageContext which is stored while validating // the authorization code. String authzCode = (String) tokReqMsgCtx.getProperty(AUTHZ_CODE); // if it's not there (which is unlikely), recalculate it. if (authzCode == null) { authzCode = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getAuthorizationCode(); } // Clear the cache entry if (cacheEnabled) { String clientId = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId(); OAuthCacheKey cacheKey = new OAuthCacheKey(OAuth2Util.buildCacheKeyStringForAuthzCode( clientId, authzCode)); oauthCache.clearCacheEntry(cacheKey); if (log.isDebugEnabled()) { log.debug("Cache was cleared for authorization code info for client id : " + clientId); } } return tokenRespDTO; }
Example #5
Source File: ExtendedAuthorizationCodeGrantHandler.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Override public OAuth2AccessTokenRespDTO issue(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception { return super.issue(tokReqMsgCtx); }
Example #6
Source File: ClientCredentialsGrantHandler.java From attic-stratos with Apache License 2.0 | 4 votes |
private OAuth2AccessTokenRespDTO getTokenDTO(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception { return super.issue(tokReqMsgCtx); }
Example #7
Source File: IDTokenBuilder.java From carbon-identity with Apache License 2.0 | 2 votes |
/** * Returns the IDToken string * * @param tokReqMsgCtx * @param tokenRespDTO * @return * @throws IdentityOAuth2Exception */ public String buildIDToken(OAuthTokenReqMessageContext tokReqMsgCtx, OAuth2AccessTokenRespDTO tokenRespDTO) throws IdentityOAuth2Exception;
Example #8
Source File: AuthorizationGrantHandler.java From carbon-identity with Apache License 2.0 | 2 votes |
/** * Issue the Access token * * @return <Code>OAuth2AccessTokenRespDTO</Code> representing the Access Token * @throws IdentityException Error when generating or persisting the access token */ public OAuth2AccessTokenRespDTO issue(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception;