use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceImpl method getOAuth2AuthenticationFromDetails.
private OAuth2Authentication getOAuth2AuthenticationFromDetails(OrcidOauth2TokenDetail details) {
if (details != null) {
ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(details.getClientDetailsId());
Authentication authentication = null;
AuthorizationRequest request = null;
if (clientDetailsEntity != null) {
//Check member is not locked
orcidOAuth2RequestValidator.validateClientIsEnabled(clientDetailsEntity);
Set<String> scopes = OAuth2Utils.parseParameterList(details.getScope());
request = new AuthorizationRequest(clientDetailsEntity.getClientId(), scopes);
request.setAuthorities(clientDetailsEntity.getAuthorities());
Set<String> resourceIds = new HashSet<>();
resourceIds.add(details.getResourceId());
request.setResourceIds(resourceIds);
request.setApproved(details.isApproved());
ProfileEntity profile = details.getProfile();
if (profile != null) {
authentication = new OrcidOauth2UserAuthentication(profile, details.isApproved());
}
}
return new OrcidOAuth2Authentication(request, authentication, details.getTokenValue());
}
throw new InvalidTokenException("Token not found");
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class DefaultPermissionChecker method performUserChecks.
private void performUserChecks(OAuth2Authentication oAuth2Authentication, ScopePathType requiredScope, OrcidMessage orcidMessage, String orcid) {
ProfileEntity principal = (ProfileEntity) oAuth2Authentication.getPrincipal();
String userOrcid = principal.getId();
if (orcidMessage != null && orcidMessage.getOrcidProfile() != null && orcidMessage.getOrcidProfile().getOrcidIdentifier() != null && StringUtils.isNotBlank(orcid)) {
String messageOrcid = orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath();
// the request is invalid
if (!messageOrcid.equals(orcid)) {
throw new IllegalArgumentException("The ORCID in the body and the URI do not match. Body ORCID: " + messageOrcid + " URI ORCID: " + orcid + " do NOT match.");
}
}
// through
if (userOrcid.equals(orcid)) {
return;
} else {
if (profileDao.isProfileDeprecated(orcid)) {
ProfileEntity entity = profileEntityCacheManager.retrieve(orcid);
Map<String, String> params = new HashMap<String, String>();
StringBuffer primary = new StringBuffer(baseUrl).append("/").append(entity.getPrimaryRecord().getId());
params.put(OrcidDeprecatedException.ORCID, primary.toString());
if (entity.getDeprecatedDate() != null) {
XMLGregorianCalendar calendar = DateUtils.convertToXMLGregorianCalendar(entity.getDeprecatedDate());
params.put(OrcidDeprecatedException.DEPRECATED_DATE, calendar.toString());
}
throw new OrcidDeprecatedException(params);
}
}
throw new AccessControlException("You do not have the required permissions.");
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class JpaJaxbEntityAdapterToProfileEntityTest method initDelegationProfiles.
@Before
public void initDelegationProfiles() {
ProfileEntity entityReceivingPermission = new ProfileEntity();
entityReceivingPermission.setId("1111-1111-1111-1115");
profileDao.merge(entityReceivingPermission);
ProfileEntity entityGivingPermission = new ProfileEntity();
entityGivingPermission.setId("2222-2222-2222-2229");
profileDao.merge(entityGivingPermission);
ProfileEntity source1 = new ProfileEntity();
source1.setId("2111-1111-1111-1114");
profileDao.merge(source1);
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class JpaJaxbEntityAdapterToOrcidProfileTest method testToOrcidProfileWithNewWayOfDoingEmails.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testToOrcidProfileWithNewWayOfDoingEmails() throws SAXException, IOException {
ProfileEntity profileEntity = profileDao.find("4444-4444-4444-4445");
long start = System.currentTimeMillis();
OrcidProfile orcidProfile = adapter.toOrcidProfile(profileEntity);
System.out.println("Took: " + Long.toString(System.currentTimeMillis() - start));
ContactDetails contactDetails = orcidProfile.getOrcidBio().getContactDetails();
Email primaryEmail = contactDetails.retrievePrimaryEmail();
assertNotNull(primaryEmail);
assertTrue(primaryEmail.isPrimary());
assertTrue(primaryEmail.isCurrent());
assertFalse(primaryEmail.isVerified());
assertEquals(Visibility.PRIVATE, primaryEmail.getVisibility());
assertEquals("andrew@timothy.com", primaryEmail.getValue());
assertEquals("4444-4444-4444-4441", primaryEmail.getSource());
Email nonPrimaryEmail = contactDetails.getEmailByString("andrew2@timothy.com");
assertNotNull(nonPrimaryEmail);
assertFalse(nonPrimaryEmail.isPrimary());
assertFalse(nonPrimaryEmail.isCurrent());
assertFalse(nonPrimaryEmail.isVerified());
assertEquals(Visibility.PRIVATE, nonPrimaryEmail.getVisibility());
assertEquals("andrew2@timothy.com", nonPrimaryEmail.getValue());
assertEquals("4444-4444-4444-4441", nonPrimaryEmail.getSource());
assertEquals(2, contactDetails.getEmail().size());
validateAgainstSchema(new OrcidMessage(orcidProfile));
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class JpaJaxbEntityAdapterToOrcidProfileTest method testToOrcidProfile.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testToOrcidProfile() throws SAXException, IOException {
ProfileEntity profileEntity = profileDao.find("4444-4444-4444-4443");
long start = System.currentTimeMillis();
OrcidProfile orcidProfile = adapter.toOrcidProfile(profileEntity);
System.out.println("Took: " + Long.toString(System.currentTimeMillis() - start));
System.out.println(orcidProfile);
checkOrcidProfile(orcidProfile);
validateAgainstSchema(new OrcidMessage(orcidProfile));
}
Aggregations