Search in sources :

Example 11 with RedirectUri

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

the class ResultContainer method validateIdP.

private void validateIdP(Client client) {
    if (client != null) {
        if (!PojoUtil.isEmpty(client.getAuthenticationProviderId())) {
            client.getAuthenticationProviderId().setErrors(new ArrayList<String>());
            boolean redirectUriFound = false;
            if (client.getRedirectUris() != null) {
                for (RedirectUri rUri : client.getRedirectUris()) {
                    if (RedirectUriType.INSTITUTIONAL_SIGN_IN.value().equals(rUri.getType().getValue())) {
                        redirectUriFound = true;
                    }
                }
            }
            if (!redirectUriFound) {
                setError(client.getAuthenticationProviderId(), "manage.developer_tools.client.idp.error.no_redirect_uri_found");
            }
        }
    }
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri)

Example 12 with RedirectUri

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

the class ResultContainer method updateClient.

@RequestMapping(value = "/update-client.json", method = RequestMethod.POST)
@ResponseBody
public Client updateClient(@RequestBody Client client) {
    // Clean the error list 
    client.setErrors(new ArrayList<String>());
    // Validate fields
    groupAdministratorController.validateDisplayName(client);
    groupAdministratorController.validateWebsite(client);
    groupAdministratorController.validateShortDescription(client);
    groupAdministratorController.validateRedirectUris(client, true);
    copyErrors(client.getDisplayName(), client);
    copyErrors(client.getWebsite(), client);
    copyErrors(client.getShortDescription(), client);
    if (client.getAuthenticationProviderId() != null) {
        validateIdP(client);
        copyErrors(client.getAuthenticationProviderId(), client);
    }
    for (RedirectUri redirectUri : client.getRedirectUris()) {
        copyErrors(redirectUri, client);
    }
    if (client.getErrors().isEmpty()) {
        client = membersManager.updateClient(client);
    }
    return client;
}
Also used : RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with RedirectUri

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

the class DeveloperToolsController method updateUserCredentials.

@RequestMapping(value = "/update-user-credentials.json", method = RequestMethod.POST)
@ResponseBody
public SSOCredentials updateUserCredentials(@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.updateUserCredentials(orcid, clientName, clientDescription, clientWebsite, redirectUriStrings);
        ssoCredentials = SSOCredentials.toSSOCredentials(clientDetails);
        ssoCredentials.setClientWebsite(Text.valueOf(clientWebsite));
    } 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());
        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 14 with RedirectUri

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

the class DeveloperToolsController method validateSSOCredentials.

/**
     * Validates the ssoCredentials object
     * 
     * @param ssoCredentials
     * @return true if any error is found in the ssoCredentials object
     * */
private boolean validateSSOCredentials(SSOCredentials ssoCredentials) {
    boolean hasErrors = false;
    Set<RedirectUri> redirectUris = ssoCredentials.getRedirectUris();
    if (PojoUtil.isEmpty(ssoCredentials.getClientName())) {
        if (ssoCredentials.getClientName() == null) {
            ssoCredentials.setClientName(new Text());
        }
        ssoCredentials.getClientName().setErrors(Arrays.asList(getMessage("manage.developer_tools.name_not_empty")));
        hasErrors = true;
    } else if (ssoCredentials.getClientName().getValue().length() > CLIENT_NAME_LENGTH) {
        ssoCredentials.getClientName().setErrors(Arrays.asList(getMessage("manage.developer_tools.name_too_long")));
        hasErrors = true;
    } else if (OrcidStringUtils.hasHtml(ssoCredentials.getClientName().getValue())) {
        ssoCredentials.getClientName().setErrors(Arrays.asList(getMessage("manage.developer_tools.name.html")));
        hasErrors = true;
    } else {
        ssoCredentials.getClientName().setErrors(new ArrayList<String>());
    }
    if (PojoUtil.isEmpty(ssoCredentials.getClientDescription())) {
        if (ssoCredentials.getClientDescription() == null) {
            ssoCredentials.setClientDescription(new Text());
        }
        ssoCredentials.getClientDescription().setErrors(Arrays.asList(getMessage("manage.developer_tools.description_not_empty")));
        hasErrors = true;
    } else if (OrcidStringUtils.hasHtml(ssoCredentials.getClientDescription().getValue())) {
        ssoCredentials.getClientDescription().setErrors(Arrays.asList(getMessage("manage.developer_tools.description.html")));
        hasErrors = true;
    } else {
        ssoCredentials.getClientDescription().setErrors(new ArrayList<String>());
    }
    if (PojoUtil.isEmpty(ssoCredentials.getClientWebsite())) {
        if (ssoCredentials.getClientWebsite() == null) {
            ssoCredentials.setClientWebsite(new Text());
        }
        ssoCredentials.getClientWebsite().setErrors(Arrays.asList(getMessage("manage.developer_tools.website_not_empty")));
        hasErrors = true;
    } else {
        List<String> errors = new ArrayList<String>();
        String[] schemes = { "http", "https", "ftp" };
        UrlValidator urlValidator = new UrlValidator(schemes);
        String websiteString = ssoCredentials.getClientWebsite().getValue();
        if (!urlValidator.isValid(websiteString))
            websiteString = "http://" + websiteString;
        // test validity again
        if (!urlValidator.isValid(websiteString)) {
            errors.add(getMessage("manage.developer_tools.invalid_website"));
        }
        ssoCredentials.getClientWebsite().setErrors(errors);
    }
    if (redirectUris == null || redirectUris.isEmpty()) {
        List<String> errors = new ArrayList<String>();
        errors.add(getMessage("manage.developer_tools.at_least_one"));
        ssoCredentials.setErrors(errors);
        hasErrors = true;
    } else {
        for (RedirectUri redirectUri : redirectUris) {
            List<String> errors = validateRedirectUri(redirectUri);
            if (errors != null) {
                redirectUri.setErrors(errors);
                hasErrors = true;
            }
        }
    }
    return hasErrors;
}
Also used : ArrayList(java.util.ArrayList) UrlValidator(org.apache.commons.validator.routines.UrlValidator) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text)

Example 15 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)

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