use of org.orcid.core.oauth.OrcidOauth2AuthInfo in project ORCID-Source by ORCID.
the class OrcidRandomValueTokenServicesImpl method createAccessToken.
@Override
public OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) throws AuthenticationException {
OrcidOauth2AuthInfo authInfo = new OrcidOauth2AuthInfo(authentication);
String userOrcid = authInfo.getUserOrcid();
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 (this.isSupportRefreshToken(authentication.getOAuth2Request())) {
OAuth2RefreshToken refreshToken = new DefaultOAuth2RefreshToken(UUID.randomUUID().toString());
accessToken.setRefreshToken(refreshToken);
}
orcidTokenStore.storeAccessToken(accessToken, authentication);
LOGGER.info("Creating new access token: clientId={}, scopes={}, userOrcid={}", new Object[] { authInfo.getClientId(), authInfo.getScopes(), userOrcid });
return accessToken;
}
use of org.orcid.core.oauth.OrcidOauth2AuthInfo in project ORCID-Source by ORCID.
the class OrcidAuthorizationCodeServiceImpl method store.
@Override
protected void store(String code, OAuth2Authentication authentication) {
OrcidOauth2AuthoriziationCodeDetail detail = getDetailFromAuthorization(code, authentication);
if (detail == null) {
throw new IllegalArgumentException("Cannot persist the authorisation code as the user and/or client " + "cannot be found");
}
orcidOauth2AuthoriziationCodeDetailDao.persist(detail);
OrcidOauth2AuthInfo authInfo = new OrcidOauth2AuthInfo(authentication);
LOGGER.info("Storing authorization code: code={}, clientId={}, scopes={}, userOrcid={}", new Object[] { code, authInfo.getClientId(), authInfo.getScopes(), authInfo.getUserOrcid() });
}
use of org.orcid.core.oauth.OrcidOauth2AuthInfo in project ORCID-Source by ORCID.
the class OrcidAuthorizationCodeServiceImpl method remove.
@Override
protected OAuth2Authentication remove(String code) {
OrcidOauth2AuthoriziationCodeDetail detail = orcidOauth2AuthoriziationCodeDetailDao.removeAndReturn(code);
if (detail == null) {
LOGGER.info("No such authorization code to remove: code={}", new Object[] { code });
return null;
}
OrcidOauth2AuthInfo authInfo = new OrcidOauth2AuthInfo(detail.getClientDetailsEntity().getId(), detail.getScopes(), detail.getProfileEntity().getId());
LOGGER.info("Removed authorization code: code={}, clientId={}, scopes={}, userOrcid={}", new Object[] { code, authInfo.getClientId(), authInfo.getScopes(), authInfo.getUserOrcid() });
OAuth2Request oAuth2Request = new OAuth2Request(Collections.<String, String>emptyMap(), authInfo.getClientId(), Collections.<GrantedAuthority>emptyList(), true, authInfo.getScopes(), detail.getResourceIds(), detail.getRedirectUri(), new HashSet<String>(Arrays.asList(detail.getResponseType())), Collections.<String, Serializable>emptyMap());
Authentication userAuth = getUserAuthentication(detail);
OAuth2Authentication result = new OAuth2Authentication(oAuth2Request, userAuth);
return result;
}
Aggregations