Search in sources :

Example 1 with OrcidOauth2AuthInfo

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;
}
Also used : OAuth2RefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken) DefaultOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken) DefaultOAuth2RefreshToken(org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken) OrcidOauth2AuthInfo(org.orcid.core.oauth.OrcidOauth2AuthInfo) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Date(java.util.Date)

Example 2 with OrcidOauth2AuthInfo

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() });
}
Also used : OrcidOauth2AuthoriziationCodeDetail(org.orcid.persistence.jpa.entities.OrcidOauth2AuthoriziationCodeDetail) OrcidOauth2AuthInfo(org.orcid.core.oauth.OrcidOauth2AuthInfo)

Example 3 with OrcidOauth2AuthInfo

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;
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OrcidOauth2AuthoriziationCodeDetail(org.orcid.persistence.jpa.entities.OrcidOauth2AuthoriziationCodeDetail) OrcidOauth2UserAuthentication(org.orcid.core.oauth.OrcidOauth2UserAuthentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidOauth2AuthInfo(org.orcid.core.oauth.OrcidOauth2AuthInfo)

Aggregations

OrcidOauth2AuthInfo (org.orcid.core.oauth.OrcidOauth2AuthInfo)3 OrcidOauth2AuthoriziationCodeDetail (org.orcid.persistence.jpa.entities.OrcidOauth2AuthoriziationCodeDetail)2 Date (java.util.Date)1 OrcidOauth2UserAuthentication (org.orcid.core.oauth.OrcidOauth2UserAuthentication)1 Authentication (org.springframework.security.core.Authentication)1 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)1 DefaultOAuth2RefreshToken (org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken)1 OAuth2RefreshToken (org.springframework.security.oauth2.common.OAuth2RefreshToken)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)1