Search in sources :

Example 1 with Client

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

the class MembersManagerImpl method getClient.

@Override
public Client getClient(String clientId) {
    Client result = new Client();
    ClientDetailsEntity clientDetailsEntity = clientDetailsManager.findByClientId(clientId);
    if (clientDetailsEntity != null) {
        result = Client.valueOf(clientDetailsEntity);
        //Set member name
        result.setMemberName(Text.valueOf(clientDetailsManager.getMemberName(clientId)));
        //Set client secret
        if (clientDetailsEntity.getClientSecrets() != null) {
            for (ClientSecretEntity secret : clientDetailsEntity.getClientSecrets()) {
                if (secret.isPrimary()) {
                    result.setClientSecret(Text.valueOf(encryptionManager.decryptForInternalUse(secret.getClientSecret())));
                }
            }
        }
    } else {
        result.getErrors().add(getMessage("admin.edit_client.invalid_orcid"));
    }
    return result;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) Client(org.orcid.pojo.ajaxForm.Client)

Example 2 with Client

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

the class GroupAdministratorController method getClients.

@RequestMapping(value = "/get-clients.json", method = RequestMethod.GET)
@Produces(value = { MediaType.APPLICATION_JSON })
@ResponseBody
public List<Client> getClients() {
    OrcidProfile profile = getEffectiveProfile();
    String groupOrcid = profile.getOrcidIdentifier().getPath();
    if (profile.getType() == null || !profile.getType().equals(OrcidType.GROUP)) {
        LOGGER.warn("Trying to get clients of non group user {}", profile.getOrcidIdentifier().getPath());
        throw new OrcidClientGroupManagementException(getMessage("web.orcid.privilege.exception"));
    }
    OrcidClientGroup group = orcidClientGroupManager.retrieveOrcidClientGroup(groupOrcid);
    List<Client> clients = new ArrayList<Client>();
    for (OrcidClient orcidClient : group.getOrcidClient()) {
        clients.add(Client.valueOf(orcidClient));
    }
    return clients;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ArrayList(java.util.ArrayList) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) Client(org.orcid.pojo.ajaxForm.Client) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with Client

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

the class GroupAdministratorControllerTest method invalidClientTest.

@Test
@Transactional("transactionManager")
@Rollback(true)
public void invalidClientTest() {
    //Test invalid fields
    Client client = controller.getClient();
    String _151chars = new String();
    for (int i = 0; i < 151; i++) _151chars += "a";
    client.setDisplayName(Text.valueOf(_151chars));
    client.setShortDescription(Text.valueOf("description"));
    client.setWebsite(Text.valueOf("http://site.com"));
    client = controller.createClient(client);
    List<String> errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.display_name.150")));
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
    //Test invalid redirect uris
    client = controller.getClient();
    client.setDisplayName(Text.valueOf("Name"));
    client.setShortDescription(Text.valueOf("Description"));
    client.setWebsite(Text.valueOf("http://mysite.com"));
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUri one = new RedirectUri();
    one.setType(Text.valueOf("default"));
    one.setValue(new Text());
    redirectUris.add(one);
    client.setRedirectUris(redirectUris);
    client = controller.createClient(client);
    errors = client.getErrors();
    assertEquals(1, errors.size());
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
    RedirectUri two = new RedirectUri();
    two.setType(Text.valueOf("grant-read-wizard"));
    two.setValue(new Text());
    redirectUris = new ArrayList<RedirectUri>();
    redirectUris.add(two);
    client.setRedirectUris(redirectUris);
    client = controller.createClient(client);
    errors = client.getErrors();
    assertEquals(2, errors.size());
    assertTrue(errors.contains(controller.getMessage("common.invalid_url")));
    assertTrue(errors.contains(controller.getMessage("manage.developer_tools.group.error.empty_scopes")));
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) Client(org.orcid.pojo.ajaxForm.Client) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Client

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

the class ManageMembersControllerTest method editMemberDoesntChangePersistentTokenEnabledValueTest.

@Test
public void editMemberDoesntChangePersistentTokenEnabledValueTest() throws Exception {
    Client clientWithPersistentTokensEnabled = manageMembers.findClient("APP-0000000000000001");
    assertNotNull(clientWithPersistentTokensEnabled);
    assertNotNull(clientWithPersistentTokensEnabled.getDisplayName());
    assertEquals("Client # 1", clientWithPersistentTokensEnabled.getDisplayName().getValue());
    assertNotNull(clientWithPersistentTokensEnabled.getPersistentTokenEnabled());
    assertTrue(clientWithPersistentTokensEnabled.getPersistentTokenEnabled().getValue());
    clientWithPersistentTokensEnabled.getDisplayName().setValue("Updated Name");
    manageMembers.updateClient(clientWithPersistentTokensEnabled);
    Client updatedClient = manageMembers.findClient("APP-0000000000000001");
    assertNotNull(updatedClient);
    assertNotNull(updatedClient.getDisplayName());
    assertEquals("Updated Name", updatedClient.getDisplayName().getValue());
    assertNotNull(updatedClient.getPersistentTokenEnabled());
    assertTrue(updatedClient.getPersistentTokenEnabled().getValue());
}
Also used : Client(org.orcid.pojo.ajaxForm.Client) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with Client

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

the class ResultContainer method findClient.

@RequestMapping(value = "/find-client.json", method = RequestMethod.GET)
@ResponseBody
public Client findClient(@RequestParam("orcid") String clientId) {
    Client result = new Client();
    if (PojoUtil.isEmpty(clientId)) {
        result.getErrors().add(getMessage("manage_member.not_blank"));
    } else {
        org.orcid.jaxb.model.v3.dev1.client.Client modelClient = clientManagerReadOnly.get(clientId);
        result = Client.fromModelObject(modelClient);
    }
    return result;
}
Also used : Client(org.orcid.pojo.ajaxForm.Client) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Client (org.orcid.pojo.ajaxForm.Client)31 Test (org.junit.Test)23 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)21 ArrayList (java.util.ArrayList)14 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)14 Text (org.orcid.pojo.ajaxForm.Text)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)3 DBUnitTest (org.orcid.test.DBUnitTest)3 Rollback (org.springframework.test.annotation.Rollback)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1 Produces (javax.ws.rs.Produces)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)1 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1