Search in sources :

Example 51 with Name

use of org.orcid.jaxb.model.record_rc4.Name in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV2Test method checkIsPublicNameTest.

@Test
public void checkIsPublicNameTest() {
    Name n = new Name();
    n.setVisibility(Visibility.PUBLIC);
    publicAPISecurityManagerV2.checkIsPublic(n);
    try {
        n.setVisibility(Visibility.LIMITED);
        publicAPISecurityManagerV2.checkIsPublic(n);
        fail();
    } catch (OrcidNonPublicElementException e) {
    }
    try {
        n.setVisibility(Visibility.PRIVATE);
        publicAPISecurityManagerV2.checkIsPublic(n);
        fail();
    } catch (OrcidNonPublicElementException e) {
    }
}
Also used : OrcidNonPublicElementException(org.orcid.core.exception.OrcidNonPublicElementException) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Name(org.orcid.jaxb.model.record_v2.Name) Test(org.junit.Test)

Example 52 with Name

use of org.orcid.jaxb.model.record_rc4.Name in project ORCID-Source by ORCID.

the class ManageProfileController method setNameFormJson.

@RequestMapping(value = "/nameForm.json", method = RequestMethod.POST)
@ResponseBody
public NamesForm setNameFormJson(@RequestBody NamesForm nf) throws NoSuchRequestHandlingMethodException {
    nf.setErrors(new ArrayList<String>());
    // Strip any html code from names before validating them
    if (!PojoUtil.isEmpty(nf.getFamilyName())) {
        nf.getFamilyName().setValue(OrcidStringUtils.stripHtml(nf.getFamilyName().getValue()));
    }
    if (!PojoUtil.isEmpty(nf.getGivenNames())) {
        nf.getGivenNames().setValue(OrcidStringUtils.stripHtml(nf.getGivenNames().getValue()));
    }
    if (!PojoUtil.isEmpty(nf.getCreditName())) {
        nf.getCreditName().setValue(OrcidStringUtils.stripHtml(nf.getCreditName().getValue()));
    }
    if (nf.getGivenNames() == null)
        nf.setGivenNames(new Text());
    givenNameValidate(nf.getGivenNames());
    copyErrors(nf.getGivenNames(), nf);
    if (nf.getErrors().size() > 0)
        return nf;
    Name name = nf.toName();
    String orcid = getCurrentUserOrcid();
    if (recordNameManager.exists(orcid)) {
        recordNameManager.updateRecordName(orcid, name);
    } else {
        recordNameManager.createRecordName(orcid, name);
    }
    return nf;
}
Also used : Text(org.orcid.pojo.ajaxForm.Text) Name(org.orcid.jaxb.model.record_v2.Name) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 53 with Name

use of org.orcid.jaxb.model.record_rc4.Name in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method initMocks.

@Before
public void initMocks() throws Exception {
    controller = new ManageProfileController();
    MockitoAnnotations.initMocks(this);
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    TargetProxyHelper.injectIntoProxy(controller, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(controller, "encryptionManager", mockEncryptionManager);
    TargetProxyHelper.injectIntoProxy(controller, "emailManager", mockEmailManager);
    TargetProxyHelper.injectIntoProxy(controller, "localeManager", mockLocaleManager);
    TargetProxyHelper.injectIntoProxy(controller, "profileEntityManager", mockProfileEntityManager);
    TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManager", mockGivenPermissionToManager);
    TargetProxyHelper.injectIntoProxy(controller, "orcidSecurityManager", mockOrcidSecurityManager);
    when(mockOrcidSecurityManager.isPasswordConfirmationRequired()).thenReturn(true);
    when(mockEncryptionManager.hashMatches(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    when(mockEncryptionManager.hashMatches(Mockito.eq("invalid password"), Mockito.anyString())).thenReturn(false);
    when(mockProfileEntityManager.deprecateProfile(Mockito.anyString(), Mockito.anyString())).thenReturn(false);
    when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID))).thenReturn(true);
    when(mockLocaleManager.resolveMessage(Mockito.anyString(), Mockito.any())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArgument(0);
        }
    });
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).then(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            ProfileEntity entity = new ProfileEntity();
            entity.setId(invocation.getArgument(0));
            Set<GivenPermissionToEntity> givenPermissionTo = new HashSet<GivenPermissionToEntity>();
            IntStream.range(0, 2).forEachOrdered(i -> {
                GivenPermissionToEntity e1 = new GivenPermissionToEntity();
                e1.setId(Long.valueOf(i));
                Date now = new Date();
                e1.setApprovalDate(now);
                e1.setDateCreated(now);
                e1.setGiver(invocation.getArgument(0));
                ProfileSummaryEntity ps = new ProfileSummaryEntity();
                RecordNameEntity recordName = new RecordNameEntity();
                recordName.setVisibility(Visibility.PUBLIC);
                if (i == 0) {
                    ps.setId("0000-0000-0000-0004");
                    recordName.setCreditName("Credit Name");
                } else {
                    ps.setId("0000-0000-0000-0005");
                    recordName.setFamilyName("Family Name");
                    recordName.setGivenNames("Given Names");
                }
                ps.setRecordNameEntity(recordName);
                e1.setReceiver(ps);
                givenPermissionTo.add(e1);
            });
            entity.setGivenPermissionTo(givenPermissionTo);
            EmailEntity email1 = new EmailEntity();
            email1.setId(invocation.getArgument(0) + "_1@test.orcid.org");
            email1.setVerified(true);
            email1.setCurrent(true);
            email1.setDateCreated(new Date());
            email1.setLastModified(new Date());
            email1.setPrimary(true);
            email1.setVisibility(Visibility.PUBLIC);
            EmailEntity email2 = new EmailEntity();
            email2.setId(invocation.getArgument(0) + "_2@test.orcid.org");
            email2.setVerified(true);
            email2.setCurrent(false);
            email2.setDateCreated(new Date());
            email2.setLastModified(new Date());
            email2.setPrimary(false);
            email2.setVisibility(Visibility.PUBLIC);
            Set<EmailEntity> emails = new HashSet<EmailEntity>();
            emails.add(email1);
            emails.add(email2);
            entity.setEmails(emails);
            entity.setRecordNameEntity(getRecordName(invocation.getArgument(0)));
            entity.setEncryptedPassword("password");
            return entity;
        }
    });
    when(mockEmailManager.getEmails(Mockito.anyString(), Mockito.anyLong())).thenAnswer(new Answer<Emails>() {

        @Override
        public Emails answer(InvocationOnMock invocation) throws Throwable {
            Emails emails = new Emails();
            Email email1 = new Email();
            email1.setEmail(invocation.getArgument(0) + "_1@test.orcid.org");
            email1.setVisibility(Visibility.PUBLIC);
            emails.getEmails().add(email1);
            Email email2 = new Email();
            email2.setEmail(invocation.getArgument(0) + "_2@test.orcid.org");
            email2.setVisibility(Visibility.PUBLIC);
            emails.getEmails().add(email2);
            return emails;
        }
    });
    when(mockEmailManager.findCaseInsensitive(Mockito.anyString())).thenAnswer(new Answer<EmailEntity>() {

        @Override
        public EmailEntity answer(InvocationOnMock invocation) throws Throwable {
            String emailString = invocation.getArgument(0);
            String orcidString = emailString.substring(0, (emailString.indexOf("_")));
            EmailEntity email = new EmailEntity();
            email.setId(emailString);
            email.setVisibility(Visibility.PUBLIC);
            ProfileEntity entity = new ProfileEntity(orcidString);
            entity.setEncryptedPassword("password");
            entity.setRecordNameEntity(getRecordName(orcidString));
            email.setProfile(entity);
            return email;
        }
    });
}
Also used : Arrays(java.util.Arrays) TargetProxyHelper(org.orcid.test.TargetProxyHelper) ProfileSummaryEntity(org.orcid.persistence.jpa.entities.ProfileSummaryEntity) Date(java.util.Date) DelegateForm(org.orcid.pojo.DelegateForm) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) StringUtils(org.apache.commons.lang3.StringUtils) NamesForm(org.orcid.pojo.ajaxForm.NamesForm) MockitoAnnotations(org.mockito.MockitoAnnotations) ManageDelegate(org.orcid.pojo.ManageDelegate) OrcidType(org.orcid.jaxb.model.message.OrcidType) ProfileEntityCacheManager(org.orcid.core.manager.ProfileEntityCacheManager) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) BiographyForm(org.orcid.pojo.ajaxForm.BiographyForm) EncryptionManager(org.orcid.core.manager.EncryptionManager) Set(java.util.Set) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) LocaleManager(org.orcid.core.locale.LocaleManager) Text(org.orcid.pojo.ajaxForm.Text) List(java.util.List) OrcidWebRole(org.orcid.core.security.OrcidWebRole) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) Biography(org.orcid.jaxb.model.record_v2.Biography) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) IntStream(java.util.stream.IntStream) NoSuchRequestHandlingMethodException(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) Mock(org.mockito.Mock) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) EmailManager(org.orcid.core.manager.EmailManager) CreditName(org.orcid.jaxb.model.common_v2.CreditName) HashSet(java.util.HashSet) GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrcidSecurityManager(org.orcid.core.manager.OrcidSecurityManager) SecurityQuestion(org.orcid.pojo.SecurityQuestion) Before(org.junit.Before) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) DeprecateProfile(org.orcid.pojo.DeprecateProfile) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BiographyManager(org.orcid.core.manager.BiographyManager) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Assert.assertNull(org.junit.Assert.assertNull) RecordNameManager(org.orcid.core.manager.RecordNameManager) Email(org.orcid.jaxb.model.record_v2.Email) Emails(org.orcid.jaxb.model.record_v2.Emails) GivenPermissionToManager(org.orcid.core.manager.GivenPermissionToManager) Name(org.orcid.jaxb.model.record_v2.Name) Assert.assertEquals(org.junit.Assert.assertEquals) ProfileEntityManager(org.orcid.core.manager.ProfileEntityManager) ProfileSummaryEntity(org.orcid.persistence.jpa.entities.ProfileSummaryEntity) Set(java.util.Set) HashSet(java.util.HashSet) Email(org.orcid.jaxb.model.record_v2.Email) GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Emails(org.orcid.jaxb.model.record_v2.Emails) Before(org.junit.Before)

Example 54 with Name

use of org.orcid.jaxb.model.record_rc4.Name in project robovm by robovm.

the class X509CertSelectorTest method test_getPathToNames.

/**
     * java.security.cert.X509CertSelector#getPathToNames()
     */
public void test_getPathToNames() throws Exception {
    GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5", new byte[] { 1, 2, 0, 1 }));
    GeneralName san1 = new GeneralName(1, "rfc@822.Name");
    GeneralName san2 = new GeneralName(2, "dNSName");
    GeneralName san3 = new GeneralName(new ORAddress());
    GeneralName san4 = new GeneralName(new Name("O=Organization"));
    GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
    GeneralName san7 = new GeneralName(7, "1.1.1.1");
    GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");
    GeneralNames sans1 = new GeneralNames();
    sans1.addName(san0);
    sans1.addName(san1);
    sans1.addName(san2);
    sans1.addName(san3);
    sans1.addName(san4);
    sans1.addName(san6);
    sans1.addName(san7);
    sans1.addName(san8);
    GeneralNames sans2 = new GeneralNames();
    sans2.addName(san0);
    TestCert cert1 = new TestCert(sans1);
    TestCert cert2 = new TestCert(sans2);
    X509CertSelector selector = new X509CertSelector();
    selector.setMatchAllSubjectAltNames(true);
    selector.setPathToNames(null);
    assertTrue("Any certificate should match in the case of null " + "subjectAlternativeNames criteria.", selector.match(cert1) && selector.match(cert2));
    Collection<List<?>> sans = sans1.getPairsList();
    selector.setPathToNames(sans);
    selector.getPathToNames();
}
Also used : GeneralNames(org.apache.harmony.security.x509.GeneralNames) OtherName(org.apache.harmony.security.x509.OtherName) X509CertSelector(java.security.cert.X509CertSelector) List(java.util.List) ArrayList(java.util.ArrayList) GeneralName(org.apache.harmony.security.x509.GeneralName) ORAddress(org.apache.harmony.security.x509.ORAddress) GeneralName(org.apache.harmony.security.x509.GeneralName) OtherName(org.apache.harmony.security.x509.OtherName) Name(org.apache.harmony.security.x501.Name)

Example 55 with Name

use of org.orcid.jaxb.model.record_rc4.Name in project robovm by robovm.

the class X509CertSelectorTest method test_addSubjectAlternativeNameLintLbyte_array2.

/**
     * java.security.cert.X509CertSelector#addSubjectAlternativeName(int, byte[])
     */
public void test_addSubjectAlternativeNameLintLbyte_array2() throws Exception {
    GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5", new byte[] { 1, 2, 0, 1 }));
    GeneralName san1 = new GeneralName(1, "rfc@822.Name");
    GeneralName san2 = new GeneralName(2, "dNSName");
    GeneralNames sans1 = new GeneralNames();
    sans1.addName(san0);
    sans1.addName(san1);
    sans1.addName(san2);
    X509CertSelector selector = new X509CertSelector();
    selector.addSubjectAlternativeName(0, san0.getEncodedName());
    selector.addSubjectAlternativeName(1, san1.getEncodedName());
    selector.addSubjectAlternativeName(2, san2.getEncodedName());
    GeneralNames sans2 = new GeneralNames();
    sans2.addName(san0);
    TestCert cert1 = new TestCert(sans1);
    TestCert cert2 = new TestCert(sans2);
    assertTrue(selector.match(cert1));
    assertFalse(selector.match(cert2));
    selector.setSubjectAlternativeNames(null);
    GeneralName name = new GeneralName(new Name("O=Android"));
    try {
        selector.addSubjectAlternativeName(0, name.getEncodedName());
    } catch (IOException e) {
    // ok
    }
}
Also used : GeneralNames(org.apache.harmony.security.x509.GeneralNames) OtherName(org.apache.harmony.security.x509.OtherName) X509CertSelector(java.security.cert.X509CertSelector) GeneralName(org.apache.harmony.security.x509.GeneralName) IOException(java.io.IOException) GeneralName(org.apache.harmony.security.x509.GeneralName) OtherName(org.apache.harmony.security.x509.OtherName) Name(org.apache.harmony.security.x501.Name)

Aggregations

Test (org.junit.Test)92 Name (org.orcid.jaxb.model.record_v2.Name)75 OtherName (org.orcid.jaxb.model.record_v2.OtherName)61 Biography (org.orcid.jaxb.model.record_v2.Biography)45 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)40 Address (org.orcid.jaxb.model.record_v2.Address)30 Email (org.orcid.jaxb.model.record_v2.Email)30 Emails (org.orcid.jaxb.model.record_v2.Emails)29 Keyword (org.orcid.jaxb.model.record_v2.Keyword)29 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)29 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)29 Addresses (org.orcid.jaxb.model.record_v2.Addresses)28 Keywords (org.orcid.jaxb.model.record_v2.Keywords)28 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)28 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)28 Person (org.orcid.jaxb.model.record_v2.Person)26 ClientResponse (com.sun.jersey.api.client.ClientResponse)17 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)17 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)17 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)17