use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class BaseController method validateEmailAddress.
protected void validateEmailAddress(String email, boolean ignoreCurrentUser, boolean isRegisterRequest, HttpServletRequest request, BindingResult bindingResult) {
if (StringUtils.isNotBlank(email)) {
if (!validateEmailAddress(email)) {
String[] codes = { "Email.personalInfoForm.email" };
String[] args = { email };
bindingResult.addError(new FieldError("email", "email", email, false, codes, args, "Not vaild"));
}
if (!(ignoreCurrentUser && emailMatchesCurrentUser(email)) && emailManager.emailExists(email)) {
OrcidProfile orcidProfile = orcidProfileManager.retrieveOrcidProfileByEmail(email, LoadOptions.BIO_ONLY);
if (orcidProfile.getOrcidHistory().isClaimed()) {
String[] codes = null;
String[] args = { email };
if (isRegisterRequest) {
if (orcidProfile.getOrcidHistory().getDeactivationDate() != null) {
codes = new String[] { "orcid.frontend.verify.deactivated_email" };
} else {
codes = new String[] { "orcid.frontend.verify.duplicate_email" };
}
bindingResult.addError(new FieldError("email", "email", email, false, codes, args, "Email already exists"));
} else {
bindingResult.addError(new FieldError("email", "email", getVerifyClaimedMessage(email)));
}
} else {
String resendUrl = createResendClaimUrl(email, request);
String message = getVerifyUnclaimedMessage(email, resendUrl);
bindingResult.addError(new FieldError("email", "email", message));
}
}
}
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class VisibilityFilterImpl method filter.
/**
* Remove the elements that are not present in the list of set of
* {@link org.orcid.jaxb.model.message .Visibility}s present in the array
* passed in.
*
* @param messageToBeFiltered
* the {@link org.orcid.jaxb.model.message.OrcidMessage} that
* will be traversed looking for
* {@link org .orcid.jaxb.model.message.VisibilityType} elements.
* @param source
* The orcid source that is executing the request
* @param removeAttribute
* should all {@link org.orcid.jaxb.model.message.Visibility}
* elements be removed from the object graph. This has the effect
* that they will not be present in the resulting JAXB
* serialisation.
* @param visibilities
* What {@link org.orcid.jaxb.model.message.Visibility} elements
* should be allowed.
* @return the cleansed {@link org.orcid.jaxb.model.message.OrcidMessage}
*/
@Override
public OrcidMessage filter(OrcidMessage messageToBeFiltered, final String sourceId, final boolean allowPrivateWorks, final boolean allowPrivateFunding, final boolean allowPrivateAffiliations, Visibility... visibilities) {
if (messageToBeFiltered == null || visibilities == null || visibilities.length == 0) {
return null;
}
String messageIdForLog = getMessageIdForLog(messageToBeFiltered);
LOGGER.debug("About to filter message: " + messageIdForLog);
final Set<Visibility> visibilitySet = new HashSet<Visibility>(Arrays.asList(visibilities));
if (visibilitySet.contains(Visibility.SYSTEM)) {
return messageToBeFiltered;
} else {
TreeCleaner treeCleaner = new TreeCleaner();
treeCleaner.clean(messageToBeFiltered, new TreeCleaningStrategy() {
public TreeCleaningDecision needsStripping(Object obj) {
TreeCleaningDecision decision = TreeCleaningDecision.DEFAULT;
if (obj != null) {
Class<?> clazz = obj.getClass();
if (!PojoUtil.isEmpty(sourceId)) {
if (allowPrivateAffiliations && Affiliation.class.isAssignableFrom(clazz)) {
Affiliation affiliation = (Affiliation) obj;
Source source = affiliation.getSource();
if (source != null) {
String sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
if (sourceId.equals(sourcePath)) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
} else if (allowPrivateFunding && Funding.class.isAssignableFrom(clazz)) {
Funding funding = (Funding) obj;
Source source = funding.getSource();
if (source != null) {
String sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
if (sourceId.equals(sourcePath)) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
} else if (allowPrivateWorks && OrcidWork.class.isAssignableFrom(clazz)) {
OrcidWork work = (OrcidWork) obj;
Source source = work.getSource();
if (source != null) {
if (sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
}
// fields are inside the country element
if (Address.class.isAssignableFrom(clazz)) {
Address address = (Address) obj;
// Remove empty addresses
if (address.getCountry() == null) {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
} else {
Country country = address.getCountry();
// Allow public addresses
if (Visibility.PUBLIC.equals(country.getVisibility())) {
decision = TreeCleaningDecision.IGNORE;
} else if (visibilitySet.contains(Visibility.LIMITED)) {
// Allow limited visibility when possible
if (Visibility.LIMITED.equals(country.getVisibility())) {
decision = TreeCleaningDecision.IGNORE;
} else {
// As last resource, check the source
Source source = country.getSource();
if (source != null && sourceId != null && sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
} else {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
}
}
}
}
}
if (Email.class.isAssignableFrom(clazz)) {
// include all emails if present
try {
Authentication authentication = getAuthentication();
if (authentication != null && messageToBeFiltered.getOrcidProfile() != null) {
permissionChecker.checkPermissions(getAuthentication(), ScopePathType.EMAIL_READ_PRIVATE, messageToBeFiltered.getOrcidProfile().retrieveOrcidPath());
decision = TreeCleaningDecision.IGNORE;
}
} catch (AccessControlException e) {
// private email can't be read, do nothing here
}
}
// that implements PrivateVisibleToSource
if (sourceId != null)
if (PrivateVisibleToSource.class.isAssignableFrom(clazz) && visibilitySet.contains(Visibility.LIMITED)) {
Source source = ((PrivateVisibleToSource) obj).getSource();
if (source != null) {
if (sourceId.equals(source.retrieveSourcePath())) {
decision = TreeCleaningDecision.IGNORE;
}
}
}
if (TreeCleaningDecision.DEFAULT.equals(decision)) {
if (WorkContributors.class.isAssignableFrom(clazz)) {
decision = TreeCleaningDecision.IGNORE;
} else if (VisibilityType.class.isAssignableFrom(clazz)) {
VisibilityType visibilityType = (VisibilityType) obj;
if ((visibilityType.getVisibility() == null || !visibilitySet.contains(visibilityType.getVisibility()))) {
decision = TreeCleaningDecision.CLEANING_REQUIRED;
}
}
}
}
return decision;
}
});
OrcidProfile orcidProfile = messageToBeFiltered.getOrcidProfile();
if (orcidProfile != null) {
orcidProfile.setOrcidInternal(null);
}
LOGGER.debug("Finished filtering message: " + messageIdForLog);
return messageToBeFiltered;
}
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class AccessTokenSecurityChecksTest method testTokenIssuedForOneUserFailForOtherUsers_12API.
@Test
public void testTokenIssuedForOneUserFailForOtherUsers_12API() throws JSONException, InterruptedException, URISyntaxException {
String accessToken = getNonCachedAccessTokens(getUser2OrcidId(), getUser2Password(), getScopes(), getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
String orcid = getUser1OrcidId();
OrcidMessage message = new OrcidMessage();
message.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setOrcidIdentifier(orcid);
message.setOrcidProfile(orcidProfile);
// Add operations
evaluateResponseOn12API(t2OAuthClient_1_2.addAffiliationsJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.addAffiliationsXml(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.addExternalIdentifiersJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.addExternalIdentifiersXml(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.addFundingJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.addFundingXml(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.addWorksJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.addWorksXml(orcid, message, accessToken));
// Update operations
evaluateResponseOn12API(t2OAuthClient_1_2.updateAffiliationsJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.updateAffiliationsXml(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.updateBioDetailsJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.updateBioDetailsXml(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.updateFundingJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.updateFundingXml(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.updateWorksJson(orcid, message, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.updateWorksXml(orcid, message, accessToken));
// View operations
evaluateResponseOn12API(t2OAuthClient_1_2.viewAffiliationDetailsJson(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewAffiliationDetailsXml(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewBioDetailsJson(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewBioDetailsXml(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewFundingDetailsJson(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewFundingDetailsXml(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewWorksDetailsJson(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewWorksDetailsXml(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewFullDetailsJson(orcid, accessToken));
evaluateResponseOn12API(t2OAuthClient_1_2.viewFullDetailsXml(orcid, accessToken));
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class Api12MembersTest method personUpdateTest.
@Test
public void personUpdateTest() throws InterruptedException, JSONException {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String giveName = getUser1GivenName();
String familyName = getUser1FamilyNames();
String creditName = getUser1CreditName();
String accessToken = getAccessToken(userId, password, Arrays.asList("/person/update", "/orcid-bio/read-limited"), clientId, clientSecret, clientRedirectUri, true);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
OrcidBio orcidBio = new OrcidBio();
PersonalDetails personalDetails = new PersonalDetails();
personalDetails.setGivenNames(new GivenNames("My given name"));
personalDetails.setFamilyName(new FamilyName("My family name"));
CreditName creditNameElement = new CreditName("My credit name");
creditNameElement.setVisibility(Visibility.LIMITED);
personalDetails.setCreditName(creditNameElement);
orcidBio.setPersonalDetails(personalDetails);
orcidProfile.setOrcidBio(orcidBio);
ClientResponse clientResponse = t2OAuthClient_1_2.updateBioDetailsXml(userId, orcidMessage, accessToken);
assertEquals(200, clientResponse.getStatus());
ClientResponse response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
OrcidMessage orcidMessageWithBio = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithBio);
assertNotNull(orcidMessageWithBio.getOrcidProfile());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames());
assertEquals("My given name", orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName());
assertEquals("My family name", orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName());
assertEquals("My credit name", orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getContent());
assertEquals(Visibility.LIMITED, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getVisibility());
// Rollback changes
orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidBio = new OrcidBio();
personalDetails = new PersonalDetails();
personalDetails.setGivenNames(new GivenNames(giveName));
personalDetails.setFamilyName(new FamilyName(familyName));
creditNameElement = new CreditName(creditName);
creditNameElement.setVisibility(Visibility.PUBLIC);
personalDetails.setCreditName(creditNameElement);
orcidBio.setPersonalDetails(personalDetails);
orcidProfile.setOrcidBio(orcidBio);
clientResponse = t2OAuthClient_1_2.updateBioDetailsXml(userId, orcidMessage, accessToken);
assertEquals(200, clientResponse.getStatus());
response = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
orcidMessageWithBio = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithBio);
assertNotNull(orcidMessageWithBio.getOrcidProfile());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames());
assertEquals(giveName, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName());
assertEquals(familyName, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getFamilyName().getContent());
assertNotNull(orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName());
assertEquals(creditName, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getContent());
assertEquals(Visibility.PUBLIC, orcidMessageWithBio.getOrcidProfile().getOrcidBio().getPersonalDetails().getCreditName().getVisibility());
}
use of org.orcid.jaxb.model.message.OrcidProfile in project ORCID-Source by ORCID.
the class EmailsTest method cantUpdateEmailsTest.
/**
* Test update email for a specific user
*/
@Test
public void cantUpdateEmailsTest() throws JSONException, InterruptedException {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String originalEmail = getUser1UserName();
String password = getUser1Password();
String accessToken = getAccessToken(userId, password, Arrays.asList("/orcid-bio/update"), clientId, clientSecret, clientRedirectUri, true);
long time = System.currentTimeMillis();
String updatedEmail = time + "@update.com";
ContactDetails contactDetails = new ContactDetails();
contactDetails.getEmail().add(new Email(updatedEmail));
OrcidBio orcidBio = new OrcidBio();
orcidBio.setContactDetails(contactDetails);
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setType(OrcidType.USER);
orcidProfile.setOrcidBio(orcidBio);
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2");
orcidMessage.setOrcidProfile(orcidProfile);
ClientResponse clientResponse = t2OAuthClient_1_2.updateBioDetailsXml(userId, orcidMessage, accessToken);
assertEquals(200, clientResponse.getStatus());
clientResponse = t2OAuthClient_1_2.viewBioDetailsXml(userId, accessToken);
assertEquals(200, clientResponse.getStatus());
OrcidMessage result = clientResponse.getEntity(OrcidMessage.class);
// Check returning message
assertNotNull(result);
assertNotNull(result.getOrcidProfile());
assertNotNull(result.getOrcidProfile().getOrcidBio());
assertNotNull(result.getOrcidProfile().getOrcidBio().getContactDetails());
assertNotNull(result.getOrcidProfile().getOrcidBio().getContactDetails().getEmail());
boolean haveOriginalEmail = false;
for (Email email : result.getOrcidProfile().getOrcidBio().getContactDetails().getEmail()) {
assertFalse(email.getValue().equals(updatedEmail));
if (email.getValue().equals(originalEmail)) {
haveOriginalEmail = true;
}
}
assertTrue(haveOriginalEmail);
}
Aggregations