Search in sources :

Example 1 with SSOCredentials

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;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with SSOCredentials

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"));
}
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 3 with SSOCredentials

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

Example 4 with SSOCredentials

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));
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) 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)

Example 5 with SSOCredentials

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()));
}
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)

Aggregations

SSOCredentials (org.orcid.pojo.ajaxForm.SSOCredentials)6 HashSet (java.util.HashSet)5 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)5 Test (org.junit.Test)4 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)4 Text (org.orcid.pojo.ajaxForm.Text)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)1