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");
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations