Search in sources :

Example 1 with RedirectUri

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

the class GroupAdministratorController method getEmptyRedirectUri.

@RequestMapping(value = "/get-empty-redirect-uri.json", method = RequestMethod.GET)
@ResponseBody
public RedirectUri getEmptyRedirectUri(HttpServletRequest request) {
    RedirectUri result = new RedirectUri();
    result.setValue(new Text());
    result.setType(Text.valueOf(RedirectUriType.DEFAULT.value()));
    result.setActType(Text.valueOf(""));
    result.setGeoArea(Text.valueOf(""));
    return result;
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RedirectUri

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

the class DeveloperToolsController method getEmptyRedirectUri.

@RequestMapping(value = "/get-empty-redirect-uri.json", method = RequestMethod.GET)
@ResponseBody
public RedirectUri getEmptyRedirectUri(HttpServletRequest request) {
    RedirectUri result = new RedirectUri();
    result.setValue(new Text());
    result.setActType(Text.valueOf(""));
    result.setGeoArea(Text.valueOf(""));
    result.setType(Text.valueOf(RedirectUriType.DEFAULT.name()));
    return result;
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with RedirectUri

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

the class GroupAdministratorController method editClient.

@RequestMapping(value = "/edit-client.json", method = RequestMethod.POST)
@Produces(value = { MediaType.APPLICATION_JSON })
@ResponseBody
public Client editClient(@RequestBody Client client) {
    // Clean the error list
    client.setErrors(new ArrayList<String>());
    // Validate fields
    validateDisplayName(client);
    validateWebsite(client);
    validateShortDescription(client);
    validateRedirectUris(client);
    copyErrors(client.getDisplayName(), client);
    copyErrors(client.getWebsite(), client);
    copyErrors(client.getShortDescription(), client);
    for (RedirectUri redirectUri : client.getRedirectUris()) {
        copyErrors(redirectUri, client);
    }
    if (client.getErrors().size() == 0) {
        OrcidProfile profile = getEffectiveProfile();
        String groupOrcid = profile.getOrcidIdentifier().getPath();
        if (profile.getType() == null || !profile.getType().equals(OrcidType.GROUP)) {
            LOGGER.warn("Trying to edit client with non group user {}", profile.getOrcidIdentifier().getPath());
            throw new OrcidClientGroupManagementException(getMessage("web.orcid.privilege.exception"));
        }
        OrcidClient result = null;
        try {
            result = orcidClientGroupManager.updateClient(groupOrcid, client.toOrcidClient());
            clearCache();
        } catch (OrcidClientGroupManagementException e) {
            LOGGER.error(e.getMessage());
            result = new OrcidClient();
            result.setErrors(new ErrorDesc(getMessage("manage.developer_tools.group.unable_to_update")));
        }
        client = Client.valueOf(result);
    }
    return client;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ErrorDesc(org.orcid.jaxb.model.message.ErrorDesc) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RedirectUri

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

the class DeveloperToolsControllerTest method testSSOCredentialsValidation.

@Test
@Transactional("transactionManager")
public void testSSOCredentialsValidation() throws Exception {
    //Test empty title
    SSOCredentials ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientDescription(Text.valueOf("This is a description"));
    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.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.name_not_empty"));
    //Test empty description
    ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    redirectUris = new HashSet<RedirectUri>();
    rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.description_not_empty"));
    //Test empty website
    ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a description"));
    redirectUris = new HashSet<RedirectUri>();
    rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.website_not_empty"));
    //Test empty redirect uris
    ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a description"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 1);
    assertEquals(result.getErrors().get(0), developerToolsController.getMessage("manage.developer_tools.at_least_one"));
}
Also used : SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) HashSet(java.util.HashSet) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with RedirectUri

use of org.orcid.pojo.ajaxForm.RedirectUri 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)

Aggregations

RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)38 Test (org.junit.Test)22 Client (org.orcid.pojo.ajaxForm.Client)21 ArrayList (java.util.ArrayList)15 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)15 Text (org.orcid.pojo.ajaxForm.Text)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 HashSet (java.util.HashSet)7 SSOCredentials (org.orcid.pojo.ajaxForm.SSOCredentials)5 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)4 Transactional (org.springframework.transaction.annotation.Transactional)4 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 Produces (javax.ws.rs.Produces)2 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)2 ErrorDesc (org.orcid.jaxb.model.message.ErrorDesc)2 DBUnitTest (org.orcid.test.DBUnitTest)2 UrlValidator (org.apache.commons.validator.routines.UrlValidator)1 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)1