Search in sources :

Example 1 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class RegistrationController method validateGrcaptcha.

public void validateGrcaptcha(HttpServletRequest request, @RequestBody Registration reg) {
    // block google.
    if (reg.getGrecaptchaWidgetId().getValue() != null) {
        if (reg.getGrecaptcha() == null) {
            reg.setGrecaptcha(new Text());
            reg.getGrecaptcha().setErrors(new ArrayList<String>());
            setError(reg.getGrecaptcha(), "registrationForm.recaptcha.error");
            setError(reg, "registrationForm.recaptcha.error");
        } else {
            reg.getGrecaptcha().setErrors(new ArrayList<String>());
        }
        if (request.getSession().getAttribute(GRECAPTCHA_SESSION_ATTRIBUTE_NAME) != null) {
            if (!reg.getGrecaptcha().getValue().equals(request.getSession().getAttribute(GRECAPTCHA_SESSION_ATTRIBUTE_NAME))) {
                setError(reg.getGrecaptcha(), "registrationForm.recaptcha.error");
                setError(reg, "registrationForm.recaptcha.error");
            }
        } else if (!recaptchaVerifier.verify(reg.getGrecaptcha().getValue())) {
            reg.getGrecaptcha().setErrors(new ArrayList<String>());
            setError(reg.getGrecaptcha(), "registrationForm.recaptcha.error");
            setError(reg, "registrationForm.recaptcha.error");
        } else {
            request.getSession().setAttribute(GRECAPTCHA_SESSION_ATTRIBUTE_NAME, reg.getGrecaptcha().getValue());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text)

Example 2 with Text

use of org.orcid.pojo.ajaxForm.Text 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 3 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class DeveloperToolsControllerTest method testUpdateSSOCredentials.

@Test
@Transactional("transactionManager")
public void testUpdateSSOCredentials() throws Exception {
    SSOCredentials ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a test"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    Set<RedirectUri> redirectUris = new HashSet<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    SSOCredentials result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 0);
    Text clientSecret = result.getClientSecret();
    //Update values
    ssoCredentials.setClientName(Text.valueOf("Updated client name"));
    ssoCredentials.setClientDescription(Text.valueOf("Updated client description"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://updated.com"));
    RedirectUri rUri2 = new RedirectUri();
    rUri2.setType(Text.valueOf("default"));
    rUri2.setValue(Text.valueOf("http://test2.com"));
    redirectUris.add(rUri2);
    ssoCredentials.setRedirectUris(redirectUris);
    SSOCredentials updatedResult = developerToolsController.updateUserCredentials(ssoCredentials);
    assertNotNull(updatedResult);
    assertNotNull(updatedResult.getErrors());
    assertEquals(updatedResult.getErrors().size(), 0);
    Text updatedClientSecret = updatedResult.getClientSecret();
    assertEquals(updatedClientSecret.toString(), clientSecret.toString());
    assertEquals(updatedResult.getClientName().getValue(), "Updated client name");
    assertEquals(updatedResult.getClientDescription().getValue(), "Updated client description");
    assertEquals(updatedResult.getClientWebsite().getValue(), "http://updated.com");
    assertNotNull(updatedResult.getRedirectUris());
    assertEquals(updatedResult.getRedirectUris().size(), 2);
}
Also used : SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) HashSet(java.util.HashSet) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class GroupAdministratorControllerTest method invalidClientTest.

@Test
@Transactional("transactionManager")
@Rollback(true)
public void invalidClientTest() {
    //Test invalid fields
    Client client = controller.getClient();
    String _151chars = new String();
    for (int i = 0; i < 151; i++) _151chars += "a";
    client.setDisplayName(Text.valueOf(_151chars));
    client.setShortDescription(Text.valueOf("description"));
    client.setWebsite(Text.valueOf("http://site.com"));
    client = controller.createClient(client);
    List<String> errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.display_name.150")));
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
    //Test invalid redirect uris
    client = controller.getClient();
    client.setDisplayName(Text.valueOf("Name"));
    client.setShortDescription(Text.valueOf("Description"));
    client.setWebsite(Text.valueOf("http://mysite.com"));
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri one = new RedirectUri();
    one.setType(Text.valueOf("default"));
    one.setValue(new Text());
    redirectUris.add(one);
    client.setRedirectUris(redirectUris);
    client = controller.createClient(client);
    errors = client.getErrors();
    assertEquals(1, errors.size());
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
    RedirectUri two = new RedirectUri();
    two.setType(Text.valueOf("grant-read-wizard"));
    two.setValue(new Text());
    redirectUris = new ArrayList<RedirectUri>();
    redirectUris.add(two);
    client.setRedirectUris(redirectUris);
    client = controller.createClient(client);
    errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.empty_scopes")));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class RegistrationControllerTest method testStripHtmlFromNames.

@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
    HttpSession session = mock(HttpSession.class);
    when(servletRequest.getSession()).thenReturn(session);
    Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
    when(registrationManager.createMinimalRegistration(Matchers.any(Registration.class), eq(false), Matchers.any(java.util.Locale.class), Matchers.anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return "0000-0000-0000-0000";
        }
    });
    Registration reg = new Registration();
    org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
    fv.setVisibility(Visibility.PUBLIC);
    reg.setActivitiesVisibilityDefault(fv);
    reg.setEmail(email);
    reg.setEmailConfirm(email);
    reg.setFamilyNames(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
    reg.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
    reg.setPassword(Text.valueOf("1234abcd"));
    reg.setPasswordConfirm(Text.valueOf("1234abcd"));
    reg.setValNumClient(2L);
    reg.setValNumServer(4L);
    Checkbox c = new Checkbox();
    c.setValue(true);
    reg.setTermsOfUse(c);
    reg.setCreationType(Text.valueOf(CreationMethod.API.value()));
    registrationController.setRegisterConfirm(servletRequest, servletResponse, reg);
    ArgumentCaptor<Registration> argument1 = ArgumentCaptor.forClass(Registration.class);
    ArgumentCaptor<Boolean> argument2 = ArgumentCaptor.forClass(Boolean.class);
    ArgumentCaptor<Locale> argument3 = ArgumentCaptor.forClass(Locale.class);
    ArgumentCaptor<String> argument4 = ArgumentCaptor.forClass(String.class);
    verify(registrationManager).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture());
    assertNotNull(argument1.getValue());
    Registration form = argument1.getValue();
    assertEquals("Given Names", form.getGivenNames().getValue());
    assertEquals("Family Name", form.getFamilyNames().getValue());
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) Text(org.orcid.pojo.ajaxForm.Text) Registration(org.orcid.pojo.ajaxForm.Registration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) Visibility(org.orcid.jaxb.model.common_v2.Visibility) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Text (org.orcid.pojo.ajaxForm.Text)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)15 ArrayList (java.util.ArrayList)8 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)8 Test (org.junit.Test)6 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 Contributor (org.orcid.pojo.ajaxForm.Contributor)4 WorkForm (org.orcid.pojo.ajaxForm.WorkForm)4 HashSet (java.util.HashSet)3 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)3 SSOCredentials (org.orcid.pojo.ajaxForm.SSOCredentials)3 Locale (java.util.Locale)2 HttpSession (javax.servlet.http.HttpSession)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Visibility (org.orcid.jaxb.model.common_v2.Visibility)2 Work (org.orcid.jaxb.model.record_v2.Work)2 Checkbox (org.orcid.pojo.ajaxForm.Checkbox)2 Client (org.orcid.pojo.ajaxForm.Client)2 Date (org.orcid.pojo.ajaxForm.Date)2