Search in sources :

Example 16 with RedirectUri

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

the class DeveloperToolsController method generateSSOCredentialsJson.

@RequestMapping(value = "/generate-sso-credentials.json", method = RequestMethod.POST)
@ResponseBody
public SSOCredentials generateSSOCredentialsJson(@RequestBody SSOCredentials ssoCredentials) {
    boolean hasErrors = validateSSOCredentials(ssoCredentials);
    if (!hasErrors) {
        OrcidProfile profile = getEffectiveProfile();
        String orcid = profile.getOrcidIdentifier().getPath();
        Set<String> redirectUriStrings = new HashSet<String>();
        for (RedirectUri redirectUri : ssoCredentials.getRedirectUris()) {
            redirectUriStrings.add(redirectUri.getValue().getValue());
        }
        String clientName = ssoCredentials.getClientName().getValue();
        String clientDescription = ssoCredentials.getClientDescription().getValue();
        String clientWebsite = ssoCredentials.getClientWebsite().getValue();
        ClientDetailsEntity clientDetails = orcidSSOManager.grantSSOAccess(orcid, clientName, clientDescription, clientWebsite, redirectUriStrings);
        ssoCredentials = SSOCredentials.toSSOCredentials(clientDetails);
    } else {
        List<String> errors = ssoCredentials.getErrors();
        if (errors == null)
            errors = new ArrayList<String>();
        if (ssoCredentials.getClientName().getErrors() != null && !ssoCredentials.getClientName().getErrors().isEmpty())
            errors.addAll(ssoCredentials.getClientName().getErrors());
        if (ssoCredentials.getClientDescription().getErrors() != null && !ssoCredentials.getClientDescription().getErrors().isEmpty())
            errors.addAll(ssoCredentials.getClientDescription().getErrors());
        if (ssoCredentials.getClientWebsite().getErrors() != null && !ssoCredentials.getClientWebsite().getErrors().isEmpty())
            errors.addAll(ssoCredentials.getClientWebsite().getErrors());
        if (ssoCredentials.getRedirectUris() != null) {
            for (RedirectUri redirectUri : ssoCredentials.getRedirectUris()) {
                if (redirectUri.getErrors() != null && !redirectUri.getErrors().isEmpty())
                    errors.addAll(redirectUri.getErrors());
            }
        }
        ssoCredentials.setErrors(errors);
    }
    return ssoCredentials;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with RedirectUri

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

the class DeveloperToolsController method getEmptySSOCredentials.

@RequestMapping(value = "/get-empty-sso-credential.json", method = RequestMethod.GET)
@ResponseBody
public SSOCredentials getEmptySSOCredentials(HttpServletRequest request) {
    SSOCredentials emptyObject = new SSOCredentials();
    emptyObject.setClientSecret(Text.valueOf(StringUtils.EMPTY));
    RedirectUri redirectUri = new RedirectUri();
    redirectUri.setValue(new Text());
    redirectUri.setType(Text.valueOf(RedirectUriType.DEFAULT.name()));
    Set<RedirectUri> set = new HashSet<RedirectUri>();
    set.add(redirectUri);
    emptyObject.setRedirectUris(set);
    return emptyObject;
}
Also used : SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with RedirectUri

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

the class GroupAdministratorControllerTest method testInvalidWebsite.

@Test
public void testInvalidWebsite() {
    Client client = controller.getClient();
    client.setRedirectUris(new ArrayList<RedirectUri>());
    client.setDisplayName(Text.valueOf("This is a valid name"));
    client.setShortDescription(Text.valueOf("This is a valid description"));
    client.setWebsite(Text.valueOf("http:://orcid.org"));
    client = controller.createClient(client);
    assertNotNull(client);
    assertEquals(1, client.getErrors().size());
    assertEquals(controller.getMessage("common.invalid_url"), client.getErrors().get(0));
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 19 with RedirectUri

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

the class ManageMembersControllerTest method findClientTest.

@Test
public void findClientTest() throws Exception {
    //Client with all redirect uris default
    Client client_0002 = manageMembers.findClient("APP-0000000000000002");
    assertNotNull(client_0002);
    assertNotNull(client_0002.getDisplayName());
    assertEquals("Client # 2", client_0002.getDisplayName().getValue());
    assertNotNull(client_0002.getRedirectUris());
    assertEquals(1, client_0002.getRedirectUris().size());
    assertEquals("http://www.google.com/APP-0000000000000002/redirect/oauth", client_0002.getRedirectUris().get(0).getValue().getValue());
    //Client with redirect uri not default
    Client client_0003 = manageMembers.findClient("APP-0000000000000003");
    assertNotNull(client_0003);
    assertNotNull(client_0003.getDisplayName());
    assertEquals("Client # 3", client_0003.getDisplayName().getValue());
    assertNotNull(client_0003.getRedirectUris());
    assertEquals(2, client_0003.getRedirectUris().size());
    RedirectUri rUri1 = client_0003.getRedirectUris().get(0);
    if ("http://www.google.com/APP-0000000000000003/redirect/oauth".equals(rUri1.getValue().getValue())) {
        assertNotNull(rUri1.getType());
        assertEquals("default", rUri1.getType().getValue());
        assertNotNull(rUri1.getScopes());
        assertEquals(0, rUri1.getScopes().size());
    } else if ("http://www.google.com/APP-0000000000000003/redirect/oauth/grant_read_wizard".equals(rUri1.getValue().getValue())) {
        assertNotNull(rUri1.getType());
        assertEquals("grant-read-wizard", rUri1.getType().getValue());
        assertNotNull(rUri1.getScopes());
        assertEquals(1, rUri1.getScopes().size());
        assertEquals("/funding/read-limited", rUri1.getScopes().get(0));
    } else {
        fail("Invalid redirect uri: " + rUri1.getValue().getValue());
    }
    RedirectUri rUri2 = client_0003.getRedirectUris().get(1);
    if ("http://www.google.com/APP-0000000000000003/redirect/oauth".equals(rUri2.getValue().getValue())) {
        assertNotNull(rUri2.getType());
        assertEquals("default", rUri2.getType().getValue());
        assertNotNull(rUri2.getScopes());
        assertEquals(1, rUri2.getScopes().size());
        assertEquals("", rUri2.getScopes().get(0));
    } else if ("http://www.google.com/APP-0000000000000003/redirect/oauth/grant_read_wizard".equals(rUri2.getValue().getValue())) {
        assertNotNull(rUri2.getType());
        assertEquals("grant-read-wizard", rUri2.getType().getValue());
        assertNotNull(rUri2.getScopes());
        assertEquals(1, rUri2.getScopes().size());
        assertEquals("/funding/read-limited", rUri2.getScopes().get(0));
    } else {
        fail("Invalid redirect uri: " + rUri2.getValue().getValue());
    }
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Client(org.orcid.pojo.ajaxForm.Client) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 20 with RedirectUri

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

the class GroupAdministratorController method getClient.

@RequestMapping(value = "/client.json", method = RequestMethod.GET)
@ResponseBody
public Client getClient() {
    Client emptyClient = new Client();
    emptyClient.setDisplayName(new Text());
    emptyClient.setWebsite(new Text());
    emptyClient.setShortDescription(new Text());
    emptyClient.setClientId(new Text());
    emptyClient.setClientSecret(new Text());
    emptyClient.setType(new Text());
    emptyClient.setAllowAutoDeprecate(Checkbox.valueOf(false));
    ArrayList<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri emptyRedirectUri = new RedirectUri();
    emptyRedirectUri.setValue(new Text());
    emptyRedirectUri.setType(Text.valueOf(RedirectUriType.DEFAULT.value()));
    emptyRedirectUri.setActType(Text.valueOf(""));
    emptyRedirectUri.setGeoArea(Text.valueOf(""));
    redirectUris.add(emptyRedirectUri);
    emptyClient.setRedirectUris(redirectUris);
    return emptyClient;
}
Also used : ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) Client(org.orcid.pojo.ajaxForm.Client) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)24 Test (org.junit.Test)12 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)10 HashSet (java.util.HashSet)9 Text (org.orcid.pojo.ajaxForm.Text)8 Client (org.orcid.pojo.ajaxForm.Client)7 SSOCredentials (org.orcid.pojo.ajaxForm.SSOCredentials)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)5 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)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