List of usage examples for org.springframework.security.oauth2.common DefaultOAuth2AccessToken setRefreshToken
public void setRefreshToken(OAuth2RefreshToken refreshToken)
From source file:org.apigw.authserver.svc.impl.TokenServicesImpl.java
/** * Returns a new access token, shallow-copied from the access token contained in the authorization grant. * @param grant The authorization grant holding the access token. * @param includeAuthorizationGrantId True if the additional information needs to include authorization_grant_id * @return An OAuth2AccessToken populated with information from the given authorization grant. */// w w w . ja v a2 s . c om protected OAuth2AccessToken buildAccessTokenFromAuthorizationGrant(AuthorizationGrant grant, boolean includeAuthorizationGrantId) { log.debug("buildAccessTokenFromAuthorizationGrant"); DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(grant.getAccessToken()); // access token and grant have the same expiry date accessToken.setExpiration(grant.getAccessTokenExpires()); if (supportRefreshToken) { accessToken.setRefreshToken( new DefaultExpiringOAuth2RefreshToken(grant.getRefreshToken(), grant.getGrantExpires())); } accessToken.setScope(buildScopeFromAuthorizationGrant(grant)); accessToken.setTokenType(OAuth2AccessToken.BEARER_TYPE); Map<String, Object> additionalInformation = new HashMap<String, Object>(); additionalInformation.put("issue_date", grant.getIssueDate()); if (includeAuthorizationGrantId) { additionalInformation.put("authorization_grant_id", grant.getId()); } accessToken.setAdditionalInformation(additionalInformation); log.debug("Returning from buildAccessTokenFromAuthorizationGrant"); return accessToken; }
From source file:org.orcid.core.oauth.service.OrcidTokenStoreServiceImpl.java
private OAuth2AccessToken getOauth2AccessTokenFromDetails(OrcidOauth2TokenDetail detail) { DefaultOAuth2AccessToken token = null; if (detail != null && StringUtils.isNotBlank(detail.getTokenValue())) { token = new DefaultOAuth2AccessToken(detail.getTokenValue()); token.setExpiration(detail.getTokenExpiration()); token.setScope(OAuth2Utils.parseParameterList(detail.getScope())); token.setTokenType(detail.getTokenType()); String refreshToken = detail.getRefreshTokenValue(); OAuth2RefreshToken rt;/*from ww w .j a va 2s. c om*/ if (StringUtils.isNotBlank(refreshToken)) { if (detail.getRefreshTokenExpiration() != null) { rt = new DefaultExpiringOAuth2RefreshToken(detail.getRefreshTokenValue(), detail.getRefreshTokenExpiration()); } else { rt = new DefaultOAuth2RefreshToken(detail.getRefreshTokenValue()); } token.setRefreshToken(rt); } ProfileEntity profile = detail.getProfile(); if (profile != null) { Map<String, Object> additionalInfo = new HashMap<String, Object>(); additionalInfo.put(OrcidOauth2Constants.ORCID, profile.getId()); additionalInfo.put(OrcidOauth2Constants.PERSISTENT, detail.isPersistent()); additionalInfo.put(OrcidOauth2Constants.DATE_CREATED, detail.getDateCreated()); additionalInfo.put(OrcidOauth2Constants.TOKEN_VERSION, detail.getVersion()); token.setAdditionalInformation(additionalInfo); } String clientId = detail.getClientDetailsId(); if (!PojoUtil.isEmpty(clientId)) { Map<String, Object> additionalInfo = new HashMap<String, Object>(); Map<String, Object> additionalInfoInToken = token.getAdditionalInformation(); if (additionalInfoInToken != null && !additionalInfoInToken.isEmpty()) { additionalInfo.putAll(additionalInfoInToken); } // Copy to a new one to avoid unmodifiable additionalInfo.put(OrcidOauth2Constants.CLIENT_ID, clientId); token.setAdditionalInformation(additionalInfo); } } return token; }
From source file:org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter.java
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken); Map<String, Object> info = new LinkedHashMap<String, Object>(accessToken.getAdditionalInformation()); String tokenId = result.getValue(); if (!info.containsKey(TOKEN_ID)) { info.put(TOKEN_ID, tokenId);//from w w w.ja va 2s.c om } result.setAdditionalInformation(info); result.setValue(encode(result, authentication)); OAuth2RefreshToken refreshToken = result.getRefreshToken(); if (refreshToken != null) { DefaultOAuth2AccessToken encodedRefreshToken = new DefaultOAuth2AccessToken(accessToken); DefaultOAuth2RefreshToken token = new DefaultOAuth2RefreshToken( encode(encodedRefreshToken, authentication)); if (refreshToken instanceof ExpiringOAuth2RefreshToken) { Date expiration = ((ExpiringOAuth2RefreshToken) refreshToken).getExpiration(); encodedRefreshToken.setExpiration(expiration); token = new DefaultExpiringOAuth2RefreshToken(encode(encodedRefreshToken, authentication), expiration); } result.setRefreshToken(token); } return result; }