use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class ProfileEntityManagerImplTest method testGetApplications.
@Test
public void testGetApplications() {
Date expiration = new Date(System.currentTimeMillis() + 10000);
OrcidOauth2TokenDetail token1 = createToken(CLIENT_ID_1, "token-1", USER_ORCID, expiration, "/read-limited", false);
OrcidOauth2TokenDetail token2 = createToken(CLIENT_ID_1, "token-2", USER_ORCID, expiration, "/orcid-profile/read-limited", false);
OrcidOauth2TokenDetail token3 = createToken(CLIENT_ID_1, "token-3", USER_ORCID, expiration, "/activities/update", false);
OrcidOauth2TokenDetail token4 = createToken(CLIENT_ID_1, "token-4", USER_ORCID, expiration, "/activities/read-limited", false);
OrcidOauth2TokenDetail token5 = createToken(CLIENT_ID_1, "token-5", USER_ORCID, expiration, "/orcid-works/read-limited", false);
List<ApplicationSummary> applications = profileEntityManager.getApplications(USER_ORCID);
assertNotNull(applications);
assertEquals(5, applications.size());
boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;
for (ApplicationSummary summary : applications) {
assertNotNull(summary.getTokenId());
if (summary.getTokenId().equals(String.valueOf(token1.getId()))) {
found1 = true;
} else if (summary.getTokenId().equals(String.valueOf(token2.getId()))) {
found2 = true;
} else if (summary.getTokenId().equals(String.valueOf(token3.getId()))) {
found3 = true;
} else if (summary.getTokenId().equals(String.valueOf(token4.getId()))) {
found4 = true;
} else if (summary.getTokenId().equals(String.valueOf(token5.getId()))) {
found5 = true;
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);
//Assert we can delete them
profileEntityManager.disableApplication(token1.getId(), USER_ORCID);
profileEntityManager.disableApplication(token5.getId(), USER_ORCID);
found1 = found2 = found3 = found4 = found5 = false;
applications = profileEntityManager.getApplications(USER_ORCID);
assertEquals(3, applications.size());
for (ApplicationSummary summary : applications) {
assertNotNull(summary.getTokenId());
if (summary.getTokenId().equals(String.valueOf(token1.getId()))) {
found1 = true;
} else if (summary.getTokenId().equals(String.valueOf(token2.getId()))) {
found2 = true;
} else if (summary.getTokenId().equals(String.valueOf(token3.getId()))) {
found3 = true;
} else if (summary.getTokenId().equals(String.valueOf(token4.getId()))) {
found4 = true;
} else if (summary.getTokenId().equals(String.valueOf(token5.getId()))) {
found5 = true;
}
}
assertFalse(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertFalse(found5);
//Revoke the others
profileEntityManager.disableApplication(token2.getId(), USER_ORCID);
profileEntityManager.disableApplication(token3.getId(), USER_ORCID);
profileEntityManager.disableApplication(token4.getId(), USER_ORCID);
applications = profileEntityManager.getApplications(USER_ORCID);
assertNotNull(applications);
assertTrue(applications.isEmpty());
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class ProfileEntityManagerImplTest method testDontGetDuplicatedApplications.
@SuppressWarnings("unused")
@Test
public void testDontGetDuplicatedApplications() {
Date expiration = new Date(System.currentTimeMillis() + 10000);
// Displayed
OrcidOauth2TokenDetail token1 = createToken(CLIENT_ID_1, "token-1", USER_ORCID, expiration, "/read-limited", false);
// Displayed
OrcidOauth2TokenDetail token2 = createToken(CLIENT_ID_1, "token-2", USER_ORCID, expiration, "/orcid-profile/read-limited", false);
// Displayed
OrcidOauth2TokenDetail token3 = createToken(CLIENT_ID_1, "token-3", USER_ORCID, expiration, "/activities/update", false);
OrcidOauth2TokenDetail token4 = createToken(CLIENT_ID_1, "token-4", USER_ORCID, expiration, "/read-limited", false);
OrcidOauth2TokenDetail token5 = createToken(CLIENT_ID_1, "token-5", USER_ORCID, expiration, "/orcid-profile/read-limited", false);
OrcidOauth2TokenDetail token6 = createToken(CLIENT_ID_1, "token-6", USER_ORCID, expiration, "/activities/update", false);
OrcidOauth2TokenDetail token7 = createToken(CLIENT_ID_1, "token-7", USER_ORCID, expiration, "/read-limited", false);
OrcidOauth2TokenDetail token8 = createToken(CLIENT_ID_1, "token-8", USER_ORCID, expiration, "/orcid-profile/read-limited", false);
OrcidOauth2TokenDetail token9 = createToken(CLIENT_ID_1, "token-9", USER_ORCID, expiration, "/activities/update", false);
// Displayed
OrcidOauth2TokenDetail token10 = createToken(CLIENT_ID_1, "token-10", USER_ORCID, expiration, "/person/read-limited", false);
OrcidOauth2TokenDetail token11 = createToken(CLIENT_ID_1, "token-11", USER_ORCID, expiration, "/person/read-limited", false);
List<ApplicationSummary> applications = profileEntityManager.getApplications(USER_ORCID);
assertNotNull(applications);
assertEquals(4, applications.size());
boolean found1 = false, found2 = false, found3 = false, found10 = false;
for (ApplicationSummary summary : applications) {
assertNotNull(summary.getTokenId());
if (summary.getTokenId().equals(String.valueOf(token1.getId()))) {
found1 = true;
} else if (summary.getTokenId().equals(String.valueOf(token2.getId()))) {
found2 = true;
} else if (summary.getTokenId().equals(String.valueOf(token3.getId()))) {
found3 = true;
} else if (summary.getTokenId().equals(String.valueOf(token10.getId()))) {
found10 = true;
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found10);
//Revoke them to check revoking one revokes all the ones with the same scopes
profileEntityManager.disableApplication(token1.getId(), USER_ORCID);
profileEntityManager.disableApplication(token2.getId(), USER_ORCID);
applications = profileEntityManager.getApplications(USER_ORCID);
assertNotNull(applications);
assertEquals(2, applications.size());
found1 = found2 = found3 = found10 = false;
for (ApplicationSummary summary : applications) {
assertNotNull(summary.getTokenId());
if (summary.getTokenId().equals(String.valueOf(token1.getId()))) {
found1 = true;
} else if (summary.getTokenId().equals(String.valueOf(token2.getId()))) {
found2 = true;
} else if (summary.getTokenId().equals(String.valueOf(token3.getId()))) {
found3 = true;
} else if (summary.getTokenId().equals(String.valueOf(token10.getId()))) {
found10 = true;
}
}
assertFalse(found1);
assertFalse(found2);
assertTrue(found3);
assertTrue(found10);
//Revoke them all
profileEntityManager.disableApplication(token3.getId(), USER_ORCID);
profileEntityManager.disableApplication(token10.getId(), USER_ORCID);
applications = profileEntityManager.getApplications(USER_ORCID);
assertNotNull(applications);
assertTrue(applications.isEmpty());
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class SetUpClientsAndUsers method clearRegistry.
private boolean clearRegistry(OrcidProfile existingProfile, Map<String, String> params) {
if (existingProfile != null) {
String orcid = params.get(ORCID);
String email = params.get(EMAIL);
// exception
if (existingProfile.getOrcidBio() == null || existingProfile.getOrcidBio().getContactDetails() == null || existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail() == null || !email.equals(existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue())) {
throw new ApplicationException("User with email " + params.get(EMAIL) + " must have orcid id '" + orcid + "' but it is '" + existingProfile.getOrcidId() + "'");
}
// Check if the profile have the same password, if not, update the
// password
String encryptedPassword = encryptionManager.hashForInternalUse(params.get(PASSWORD));
if (!encryptedPassword.equals(existingProfile.getPassword())) {
existingProfile.setPassword(params.get(PASSWORD));
orcidProfileManager.updatePasswordInformation(existingProfile);
}
// Set default names
Name name = new Name();
name.setCreditName(new CreditName(params.get(CREDIT_NAME)));
name.setGivenNames(new GivenNames(params.get(GIVEN_NAMES)));
name.setFamilyName(new FamilyName(params.get(FAMILY_NAMES)));
name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value()));
if (recordNameManager.exists(orcid)) {
recordNameManager.updateRecordName(orcid, name);
} else {
recordNameManager.createRecordName(orcid, name);
}
profileDao.updatePreferences(orcid, true, true, true, true, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, true, 1f);
// Set default bio
org.orcid.jaxb.model.record_v2.Biography bio = biographyManager.getBiography(orcid, 0L);
if (bio == null || bio.getContent() == null) {
bio = new org.orcid.jaxb.model.record_v2.Biography(params.get(BIO));
bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
biographyManager.createBiography(orcid, bio);
} else {
bio.setContent(params.get(BIO));
bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
biographyManager.updateBiography(orcid, bio);
}
// Remove other names
List<OtherNameEntity> otherNames = otherNameDao.getOtherNames(orcid, 0L);
if (otherNames != null && !otherNames.isEmpty()) {
for (OtherNameEntity otherName : otherNames) {
otherNameDao.deleteOtherName(otherName);
}
}
// Remove keywords
List<ProfileKeywordEntity> keywords = profileKeywordDao.getProfileKeywors(orcid, 0L);
if (keywords != null && !keywords.isEmpty()) {
for (ProfileKeywordEntity keyword : keywords) {
profileKeywordDao.deleteProfileKeyword(keyword);
}
}
//Remove researcher urls
List<ResearcherUrlEntity> rUrls = researcherUrlDao.getResearcherUrls(orcid, 0L);
if (rUrls != null && !rUrls.isEmpty()) {
for (ResearcherUrlEntity rUrl : rUrls) {
researcherUrlDao.deleteResearcherUrl(orcid, rUrl.getId());
}
}
// Remove external ids
List<ExternalIdentifierEntity> extIds = externalIdentifierDao.getExternalIdentifiers(orcid, System.currentTimeMillis());
if (extIds != null && !extIds.isEmpty()) {
for (ExternalIdentifierEntity extId : extIds) {
externalIdentifierDao.removeExternalIdentifier(orcid, extId.getId());
}
}
// Remove addresses
List<AddressEntity> addresses = addressDao.getAddresses(orcid, 0L);
if (addresses != null && !addresses.isEmpty()) {
for (AddressEntity address : addresses) {
addressDao.deleteAddress(orcid, address.getId());
}
}
// Remove emails
List<EmailEntity> emails = emailDao.findByOrcid(orcid);
if (emails != null && !emails.isEmpty()) {
for (EmailEntity rc2Email : emails) {
if (!params.get(EMAIL).equals(rc2Email.getId())) {
emailDao.removeEmail(orcid, rc2Email.getId());
}
}
}
// Remove notifications
List<NotificationEntity> notifications = notificationDao.findByOrcid(orcid, true, 0, 10000);
if (notifications != null && !notifications.isEmpty()) {
for (NotificationEntity notification : notifications) {
notificationDao.deleteNotificationItemByNotificationId(notification.getId());
notificationDao.deleteNotificationWorkByNotificationId(notification.getId());
notificationDao.deleteNotificationById(notification.getId());
}
}
// Remove works
List<MinimizedWorkEntity> works = workDao.findWorks(orcid, 0L);
if (works != null && !works.isEmpty()) {
for (MinimizedWorkEntity work : works) {
workDao.removeWork(orcid, work.getId());
}
}
// Remove affiliations
List<OrgAffiliationRelationEntity> affiliations = orgAffiliationRelationDao.getByUser(orcid);
if (affiliations != null && !affiliations.isEmpty()) {
for (OrgAffiliationRelationEntity affiliation : affiliations) {
orgAffiliationRelationDao.remove(affiliation.getId());
}
}
// Remove fundings
List<ProfileFundingEntity> fundings = profileFundingDao.getByUser(orcid);
if (fundings != null && !fundings.isEmpty()) {
for (ProfileFundingEntity funding : fundings) {
profileFundingDao.removeProfileFunding(orcid, funding.getId());
}
}
// Remove peer reviews
List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
if (peerReviews != null && !peerReviews.isEmpty()) {
for (PeerReviewEntity peerReview : peerReviews) {
peerReviewDao.removePeerReview(orcid, peerReview.getId());
}
}
// Remove 3d party links
List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenDetailDao.findByUserName(orcid);
if (tokenDetails != null && !tokenDetails.isEmpty()) {
for (OrcidOauth2TokenDetail token : tokenDetails) {
orcidOauth2TokenDetailDao.remove(token.getId());
}
}
//Unlock just in case it is locked
profileDao.unlockProfile(orcid);
return true;
}
return false;
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidOauth2AuthorizationDetailsDaoTest method testFindByAuthenticationKey.
@Test
@Transactional
@Rollback
public void testFindByAuthenticationKey() throws Exception {
List<OrcidOauth2TokenDetail> all = orcidOauth2TokenDetailDao.getAll();
assertEquals(5, all.size());
for (OrcidOauth2TokenDetail detail : all) {
OrcidOauth2TokenDetail another = orcidOauth2TokenDetailDao.findByTokenValue(detail.getTokenValue());
assertNotNull(another);
assertEquals(detail.getId(), another.getId());
assertTrue(detail.getTokenExpiration().after(new Date()));
assertTrue(detail.getRefreshTokenExpiration().after(new Date()));
}
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidOauth2AuthorizationDetailsDaoTest method testFindById.
@Test
@Transactional
@Rollback
public void testFindById() throws Exception {
List<OrcidOauth2TokenDetail> all = orcidOauth2TokenDetailDao.getAll();
assertEquals(5, all.size());
for (OrcidOauth2TokenDetail detail : all) {
OrcidOauth2TokenDetail another = orcidOauth2TokenDetailDao.find(detail.getId());
assertNotNull(another);
assertEquals(detail.getId(), another.getId());
assertTrue(detail.getTokenExpiration().after(new Date()));
String refreshTokenValue = detail.getRefreshTokenValue();
assertNotNull(refreshTokenValue);
}
}
Aggregations