use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.
the class OrcidProfileManagerContributorVisibilityTest method onlyNameProvided.
@Test
@Transactional
public void onlyNameProvided() {
// Unmarshall message containing contributor name only
OrcidMessage orcidMessage = unmarshallOrcidMessage("new_work_with_contributor_name.xml");
// Add the work
orcidProfileManager.addOrcidWorks(orcidMessage.getOrcidProfile());
// Get it back from the API
OrcidWork retrievedWork = retrieveAddedWorkFromApi();
Contributor workContributor = retrievedWork.getWorkContributors().getContributor().get(0);
// Check that the contributor name is included in the resulting work
assertEquals("Test Contributor Name", workContributor.getCreditName().getContent());
// Check that the email is not included in the resulting work, because
// never want to show email
assertNull(workContributor.getContributorEmail());
}
use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.
the class DefaultPermissionCheckerTest method testCheckUserPermissionsAuthenticationScopesOrcidAndOrcidMessageWhenWrongUser.
@Test(expected = AccessControlException.class)
@Transactional
@Rollback
public void testCheckUserPermissionsAuthenticationScopesOrcidAndOrcidMessageWhenWrongUser() throws Exception {
Set<String> resourceIds = new HashSet<String>(Arrays.asList("orcid"));
HashSet<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>(Arrays.asList(new SimpleGrantedAuthority("ROLE_CLIENT")));
AuthorizationRequest request = new AuthorizationRequest("4444-4444-4444-4441", Arrays.asList("/orcid-bio/external-identifiers/create"));
request.setAuthorities(grantedAuthorities);
request.setResourceIds(resourceIds);
ProfileEntity entity = profileEntityManager.findByOrcid("4444-4444-4444-4445");
OrcidOauth2UserAuthentication oauth2UserAuthentication = new OrcidOauth2UserAuthentication(entity, true);
OAuth2Authentication oAuth2Authentication = new OrcidOAuth2Authentication(request, oauth2UserAuthentication, "made-up-token");
ScopePathType requiredScope = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE;
OrcidMessage orcidMessage = getOrcidMessage();
String messageOrcid = orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath();
defaultPermissionChecker.checkPermissions(oAuth2Authentication, requiredScope, messageOrcid, orcidMessage);
}
use of org.orcid.jaxb.model.message.OrcidMessage in project ORCID-Source by ORCID.
the class DefaultPermissionCheckerTest method testCheckPermissionsAuthenticationScopesAndOrcidMessage.
@Test
public void testCheckPermissionsAuthenticationScopesAndOrcidMessage() throws Exception {
Set<String> resourceIds = new HashSet<String>(Arrays.asList("orcid"));
HashSet<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>(Arrays.asList(new SimpleGrantedAuthority("ROLE_CLIENT")));
AuthorizationRequest request = new AuthorizationRequest("4444-4444-4444-4441", Arrays.asList(ScopePathType.ORCID_WORKS_CREATE.value()));
request.setAuthorities(grantedAuthorities);
request.setResourceIds(resourceIds);
OAuth2Authentication oAuth2Authentication = new OrcidOAuth2Authentication(request, null, "made-up-token");
ScopePathType requiredScope = ScopePathType.ORCID_WORKS_CREATE;
OrcidMessage orcidMessage = getOrcidMessage();
defaultPermissionChecker.checkPermissions(oAuth2Authentication, requiredScope, orcidMessage);
}
use of org.orcid.jaxb.model.message.OrcidMessage 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.OrcidMessage in project ORCID-Source by ORCID.
the class MemberV1Test method testCreateNewProfile.
@Test
public void testCreateNewProfile() throws Exception {
String accessToken = getClientCredentialsAccessToken(ScopePathType.ORCID_PROFILE_CREATE, this.getClient1ClientId(), this.getClient1ClientSecret(), APIRequestType.MEMBER);
OrcidMessage orcidMessage = (OrcidMessage) unmarshallFromPath("/samples/small_orcid_profile.xml");
assertNotNull(orcidMessage);
assertNotNull(orcidMessage.getOrcidProfile());
//Update email
orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getEmail().get(0).setValue(System.currentTimeMillis() + "@api.com");
ClientResponse response = t2OAuthClient_1_2.createProfileXML(orcidMessage, accessToken);
assertNotNull(response);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
String locationPath = response.getLocation().getPath();
String orcid = locationPath.substring(0, locationPath.lastIndexOf('/'));
orcid = orcid.substring(orcid.lastIndexOf('/') + 1);
assertNotNull(orcid);
response = t2OAuthClient_1_2.viewFullDetailsXml(orcid, accessToken);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
OrcidMessage newMessage = response.getEntity(OrcidMessage.class);
assertNotNull(newMessage);
assertNotNull(newMessage.getOrcidProfile());
OrcidProfile newProfile = newMessage.getOrcidProfile();
assertEquals(OrcidVisibilityDefaults.CREATED_BY_MEMBER_DEFAULT.getVisibility().value(), newProfile.getOrcidBio().getBiography().getVisibility().value());
assertEquals(OrcidVisibilityDefaults.CREATED_BY_MEMBER_DEFAULT.getVisibility().value(), newProfile.getOrcidBio().getExternalIdentifiers().getVisibility().value());
assertEquals(OrcidVisibilityDefaults.CREATED_BY_MEMBER_DEFAULT.getVisibility().value(), newProfile.getOrcidBio().getKeywords().getVisibility().value());
assertEquals(OrcidVisibilityDefaults.CREATED_BY_MEMBER_DEFAULT.getVisibility().value(), newProfile.getOrcidBio().getResearcherUrls().getVisibility().value());
assertEquals(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value(), newProfile.getOrcidBio().getPersonalDetails().getCreditName().getVisibility().value());
assertEquals(OrcidVisibilityDefaults.CREATED_BY_MEMBER_DEFAULT.getVisibility().value(), newProfile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility().value());
assertEquals(OrcidVisibilityDefaults.CREATED_BY_MEMBER_DEFAULT.getVisibility().value(), newProfile.getOrcidBio().getContactDetails().getAddress().getCountry().getVisibility().value());
}
Aggregations