use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method before.
@Before
@Transactional
@Rollback
public void before() throws Exception {
OrcidProfileManagerImpl orcidProfileManagerImpl = getTargetObject(orcidProfileManager, OrcidProfileManagerImpl.class);
orcidProfileManagerImpl.setNotificationManager(notificationManager);
if (profileDao.find(TEST_ORCID) != null) {
profileDao.remove(TEST_ORCID);
}
subjectDao.merge(new SubjectEntity("Computer Science"));
subjectDao.merge(new SubjectEntity("Dance"));
OrcidProfile delegateProfile = new OrcidProfile();
delegateProfile.setOrcidIdentifier(DELEGATE_ORCID);
OrcidBio delegateBio = new OrcidBio();
delegateProfile.setOrcidBio(delegateBio);
PersonalDetails delegatePersonalDetails = new PersonalDetails();
delegateBio.setPersonalDetails(delegatePersonalDetails);
CreditName delegateCreditName = new CreditName("H. Shearer");
delegateCreditName.setVisibility(Visibility.PUBLIC);
delegatePersonalDetails.setCreditName(delegateCreditName);
orcidProfileManager.createOrcidProfile(delegateProfile, false, false);
OrcidProfile applicationProfile = new OrcidProfile();
applicationProfile.setOrcidIdentifier(APPLICATION_ORCID);
OrcidBio applicationBio = new OrcidBio();
applicationProfile.setOrcidBio(applicationBio);
PersonalDetails applicationPersonalDetails = new PersonalDetails();
applicationBio.setPersonalDetails(applicationPersonalDetails);
applicationPersonalDetails.setCreditName(new CreditName("Brown University"));
orcidProfileManager.createOrcidProfile(applicationProfile, false, false);
ClientDetailsEntity clientDetails = new ClientDetailsEntity();
clientDetails.setId(applicationProfile.getOrcidIdentifier().getPath());
ProfileEntity applicationProfileEntity = profileDao.find(applicationProfile.getOrcidIdentifier().getPath());
profileDao.refresh(applicationProfileEntity);
clientDetails.setGroupProfileId(applicationProfileEntity.getId());
clientDetailsManager.merge(clientDetails);
OrcidOauth2TokenDetail token = new OrcidOauth2TokenDetail();
token.setTokenValue("1234");
token.setClientDetailsId(clientDetails.getId());
token.setProfile(profileDao.find(delegateProfile.getOrcidIdentifier().getPath()));
token.setScope(StringUtils.join(new String[] { ScopePathType.ORCID_BIO_READ_LIMITED.value(), ScopePathType.ORCID_BIO_UPDATE.value() }, " "));
SortedSet<OrcidOauth2TokenDetail> tokens = new TreeSet<>();
tokens.add(token);
ProfileEntity delegateProfileEntity = profileDao.find(delegateProfile.getOrcidIdentifier().getPath());
delegateProfileEntity.setTokenDetails(tokens);
profileDao.merge(delegateProfileEntity);
SecurityQuestionEntity existingSecurityQuestionEntity = securityQuestionDao.find(3);
if (existingSecurityQuestionEntity == null) {
SecurityQuestionEntity securityQuestionEntity = new SecurityQuestionEntity();
securityQuestionEntity.setId(3);
securityQuestionEntity.setQuestion("What?");
securityQuestionDao.persist(securityQuestionEntity);
}
orcidProfileManager.setCompareWorksUsingScopusWay(true);
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceImpl method storeAccessToken.
/**
* Store an access token.
*
* @param token
* The token to store.
* @param authentication
* The authentication associated with the token.
*/
@Override
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
OrcidOauth2TokenDetail detail = populatePropertiesFromTokenAndAuthentication(token, authentication, null);
orcidOauthTokenDetailService.removeConflictsAndCreateNew(detail);
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceImpl method populatePropertiesFromTokenAndAuthentication.
private OrcidOauth2TokenDetail populatePropertiesFromTokenAndAuthentication(OAuth2AccessToken token, OAuth2Authentication authentication, OrcidOauth2TokenDetail detail) {
OAuth2Request authorizationRequest = authentication.getOAuth2Request();
if (detail == null) {
detail = new OrcidOauth2TokenDetail();
}
String clientId = authorizationRequest.getClientId();
String authKey = authenticationKeyGenerator.extractKey(authentication);
detail.setAuthenticationKey(authKey);
detail.setClientDetailsId(clientId);
OAuth2RefreshToken refreshToken = token.getRefreshToken();
if (refreshToken != null && StringUtils.isNotBlank(refreshToken.getValue())) {
if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
// Override the refresh token expiration from the client
// details, and make it the same as the token itself
detail.setRefreshTokenExpiration(token.getExpiration());
}
detail.setRefreshTokenValue(refreshToken.getValue());
}
if (!authentication.isClientOnly()) {
Object principal = authentication.getPrincipal();
if (principal instanceof ProfileEntity) {
ProfileEntity profileEntity = (ProfileEntity) authentication.getPrincipal();
profileEntity = profileEntityCacheManager.retrieve(profileEntity.getId());
detail.setProfile(profileEntity);
}
}
detail.setTokenValue(token.getValue());
detail.setTokenType(token.getTokenType());
detail.setTokenExpiration(token.getExpiration());
detail.setApproved(authorizationRequest.isApproved());
detail.setRedirectUri(authorizationRequest.getRedirectUri());
Set<String> resourceIds = authorizationRequest.getResourceIds();
if (resourceIds == null || resourceIds.isEmpty()) {
ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
resourceIds = clientDetails.getResourceIds();
}
detail.setResourceId(OAuth2Utils.formatParameterList(resourceIds));
detail.setResponseType(OAuth2Utils.formatParameterList(authorizationRequest.getResponseTypes()));
detail.setScope(OAuth2Utils.formatParameterList(authorizationRequest.getScope()));
Map<String, Object> additionalInfo = token.getAdditionalInformation();
if (additionalInfo != null) {
if (additionalInfo.containsKey(OrcidOauth2Constants.TOKEN_VERSION)) {
String sVersion = String.valueOf(additionalInfo.get(OrcidOauth2Constants.TOKEN_VERSION));
detail.setVersion(Long.valueOf(sVersion));
} else {
// TODO: As of Jan 2015 all tokens will be new tokens, so, we
// will have to remove the token version code and
// treat all tokens as new tokens
detail.setVersion(Long.valueOf(OrcidOauth2Constants.PERSISTENT_TOKEN));
}
if (additionalInfo.containsKey(OrcidOauth2Constants.PERSISTENT)) {
boolean isPersistentKey = (Boolean) additionalInfo.get(OrcidOauth2Constants.PERSISTENT);
detail.setPersistent(isPersistentKey);
} else {
detail.setPersistent(false);
}
} else {
detail.setPersistent(false);
}
return detail;
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceImpl method findTokensByClientIdAndUserName.
@Override
public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) {
List<OrcidOauth2TokenDetail> details = orcidOauthTokenDetailService.findByClientIdAndUserName(clientId, userName);
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();
if (details != null && !details.isEmpty()) {
for (OrcidOauth2TokenDetail detail : details) {
if (detail.getTokenDisabled() == null || !detail.getTokenDisabled()) {
accessTokens.add(getOauth2AccessTokenFromDetails(detail));
}
}
}
return accessTokens;
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceImpl method findTokensByClientId.
/**
* @param clientId
* the client id
* @return a collection of access tokens
*/
@Override
public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
List<OrcidOauth2TokenDetail> details = orcidOauthTokenDetailService.findByClientId(clientId);
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>();
if (details != null && !details.isEmpty()) {
for (OrcidOauth2TokenDetail detail : details) {
accessTokens.add(getOauth2AccessTokenFromDetails(detail));
}
}
return accessTokens;
}
Aggregations