use of org.orcid.pojo.ajaxForm.SSOCredentials in project ORCID-Source by ORCID.
the class DeveloperToolsController method getSSOCredentialsJson.
@RequestMapping(value = "/get-sso-credentials.json", method = RequestMethod.GET)
@ResponseBody
public SSOCredentials getSSOCredentialsJson() {
SSOCredentials credentials = new SSOCredentials();
String userOrcid = getEffectiveUserOrcid();
ClientDetailsEntity existingClientDetails = orcidSSOManager.getUserCredentials(userOrcid);
if (existingClientDetails != null)
credentials = SSOCredentials.toSSOCredentials(existingClientDetails);
return credentials;
}
use of org.orcid.pojo.ajaxForm.SSOCredentials 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"));
}
use of org.orcid.pojo.ajaxForm.SSOCredentials 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);
}
use of org.orcid.pojo.ajaxForm.SSOCredentials in project ORCID-Source by ORCID.
the class DeveloperToolsControllerTest method testResetClientSecret.
@Test
public void testResetClientSecret() 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();
assertTrue(developerToolsController.resetClientSecret(result.getClientOrcid().getValue()));
ClientDetailsEntity clientDetails = clientDetailsDao.findByClientId(result.getClientOrcid().getValue(), System.currentTimeMillis());
assertEquals(result.getClientName().getValue(), clientDetails.getClientName());
assertEquals(result.getClientDescription().getValue(), clientDetails.getClientDescription());
assertEquals(result.getClientOrcid().getValue(), clientDetails.getClientId());
assertEquals(result.getClientWebsite().getValue(), clientDetails.getClientWebsite());
Set<ClientSecretEntity> clientSecrets = clientDetails.getClientSecrets();
assertNotNull(clientSecrets);
assertEquals(2, clientSecrets.size());
for (ClientSecretEntity clientSecretEntity : clientSecrets) {
String secret = encryptionManager.decryptForInternalUse(clientSecretEntity.getClientSecret());
if (!clientSecretEntity.isPrimary())
assertEquals(clientSecret.getValue(), secret);
else
assertFalse(clientSecret.getValue().equals(secret));
}
}
use of org.orcid.pojo.ajaxForm.SSOCredentials in project ORCID-Source by ORCID.
the class DeveloperToolsControllerTest method testGenerateSSOCredentials.
@Test
@Transactional("transactionManager")
public void testGenerateSSOCredentials() 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);
assertNotNull(result.getClientSecret());
assertFalse(PojoUtil.isEmpty(result.getClientSecret()));
assertFalse(PojoUtil.isEmpty(result.getClientOrcid()));
}
Aggregations