Search in sources :

Example 1 with ClientRedirectUri

use of org.orcid.jaxb.model.client_v2.ClientRedirectUri in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getClientMapperFacade.

public MapperFacade getClientMapperFacade() {
    MapperFactory mapperFactory = getNewMapperFactory();
    ClassMapBuilder<ClientSummary, ClientDetailsEntity> clientSummaryClassMap = mapperFactory.classMap(ClientSummary.class, ClientDetailsEntity.class);
    clientSummaryClassMap.field("name", "clientName");
    clientSummaryClassMap.field("description", "clientDescription");
    clientSummaryClassMap.byDefault();
    clientSummaryClassMap.register();
    ClassMapBuilder<Client, ClientDetailsEntity> clientClassMap = mapperFactory.classMap(Client.class, ClientDetailsEntity.class);
    clientClassMap.field("name", "clientName");
    clientClassMap.field("description", "clientDescription");
    clientClassMap.field("website", "clientWebsite");
    clientClassMap.field("allowAutoDeprecate", "allowAutoDeprecate");
    clientClassMap.fieldBToA("clientId", "id");
    clientClassMap.fieldBToA("clientType", "clientType");
    clientClassMap.fieldBToA("groupProfileId", "groupProfileId");
    clientClassMap.fieldBToA("authenticationProviderId", "authenticationProviderId");
    clientClassMap.fieldBToA("persistentTokensEnabled", "persistentTokensEnabled");
    clientClassMap.customize(new CustomMapper<Client, ClientDetailsEntity>() {

        /**
         * On the way in, from Client to ClientDetailsEntity, we need to
         * care about mapping the redirect uri's, since all config features
         * will not change from UI requests
         */
        @Override
        public void mapAtoB(Client a, ClientDetailsEntity b, MappingContext context) {
            Map<String, ClientRedirectUriEntity> existingRedirectUriEntitiesMap = new HashMap<String, ClientRedirectUriEntity>();
            if (b.getClientRegisteredRedirectUris() != null && !b.getClientRegisteredRedirectUris().isEmpty()) {
                existingRedirectUriEntitiesMap = ClientRedirectUriEntity.mapByUriAndType(b.getClientRegisteredRedirectUris());
            }
            if (b.getClientRegisteredRedirectUris() != null) {
                b.getClientRegisteredRedirectUris().clear();
            } else {
                b.setClientRegisteredRedirectUris(new TreeSet<ClientRedirectUriEntity>());
            }
            if (a.getClientRedirectUris() != null) {
                for (ClientRedirectUri cru : a.getClientRedirectUris()) {
                    String rUriKey = ClientRedirectUriEntity.getUriAndTypeKey(cru);
                    if (existingRedirectUriEntitiesMap.containsKey(rUriKey)) {
                        ClientRedirectUriEntity existingEntity = existingRedirectUriEntitiesMap.get(rUriKey);
                        existingEntity.setLastModified(new Date());
                        existingEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
                        existingEntity.setUriActType(cru.getUriActType());
                        existingEntity.setUriGeoArea(cru.getUriGeoArea());
                        b.getClientRegisteredRedirectUris().add(existingEntity);
                    } else {
                        ClientRedirectUriEntity newEntity = new ClientRedirectUriEntity();
                        newEntity.setClientDetailsEntity(b);
                        newEntity.setDateCreated(new Date());
                        newEntity.setLastModified(new Date());
                        newEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(cru.getPredefinedClientScopes()));
                        newEntity.setRedirectUri(cru.getRedirectUri());
                        newEntity.setRedirectUriType(cru.getRedirectUriType());
                        newEntity.setUriActType(cru.getUriActType());
                        newEntity.setUriGeoArea(cru.getUriGeoArea());
                        b.getClientRegisteredRedirectUris().add(newEntity);
                    }
                }
            }
        }

        /**
         * On the way out, from ClientDetailsEntity to Client, we just need
         * to care about mapping the redirect uri's and the primary client
         * secret since all config features will not be visible on the UI
         */
        @Override
        public void mapBtoA(ClientDetailsEntity b, Client a, MappingContext context) {
            if (b.getClientSecrets() != null) {
                for (ClientSecretEntity entity : b.getClientSecrets()) {
                    if (entity.isPrimary()) {
                        a.setDecryptedSecret(encryptionManager.decryptForInternalUse(entity.getClientSecret()));
                    }
                }
            }
            if (b.getRegisteredRedirectUri() != null) {
                a.setClientRedirectUris(new HashSet<ClientRedirectUri>());
                for (ClientRedirectUriEntity entity : b.getClientRegisteredRedirectUris()) {
                    ClientRedirectUri element = new ClientRedirectUri();
                    element.setRedirectUri(entity.getRedirectUri());
                    element.setRedirectUriType(entity.getRedirectUriType());
                    element.setUriActType(entity.getUriActType());
                    element.setUriGeoArea(entity.getUriGeoArea());
                    element.setPredefinedClientScopes(ScopePathType.getScopesFromSpaceSeparatedString(entity.getPredefinedClientScope()));
                    a.getClientRedirectUris().add(element);
                }
            }
        }
    });
    clientClassMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ClientSummary(org.orcid.jaxb.model.client_v2.ClientSummary) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity) PublicationDate(org.orcid.jaxb.model.common_v2.PublicationDate) Date(java.util.Date) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) MappingContext(ma.glasnost.orika.MappingContext) TreeSet(java.util.TreeSet) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) Client(org.orcid.jaxb.model.client_v2.Client) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with ClientRedirectUri

use of org.orcid.jaxb.model.client_v2.ClientRedirectUri in project ORCID-Source by ORCID.

the class ClientManagerReadOnlyTest method getClient.

private Client getClient(String randomString) {
    Client client = new Client();
    client.setAllowAutoDeprecate(true);
    client.setPersistentTokensEnabled(true);
    client.setClientType(ClientType.CREATOR);
    client.setDescription("description " + randomString);
    client.setGroupProfileId("group-profile-id " + randomString);
    client.setId(randomString);
    client.setName("client-name " + randomString);
    client.setWebsite("client-website " + randomString);
    client.setAuthenticationProviderId("authentication-provider-id " + randomString);
    Set<ClientRedirectUri> clientRedirectUris = new HashSet<ClientRedirectUri>();
    ClientRedirectUri rUri1 = new ClientRedirectUri();
    Set<ScopePathType> scopes1 = new HashSet<ScopePathType>();
    scopes1.add(ScopePathType.ACTIVITIES_READ_LIMITED);
    rUri1.setPredefinedClientScopes(scopes1);
    rUri1.setRedirectUri("redirect-uri-1 " + randomString);
    rUri1.setRedirectUriType("type-1 " + randomString);
    rUri1.setUriActType("uri-act-type-1 " + randomString);
    rUri1.setUriGeoArea("uri-geo-area-1 " + randomString);
    ClientRedirectUri rUri2 = new ClientRedirectUri();
    Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
    scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri2.setPredefinedClientScopes(scopes2);
    rUri2.setRedirectUri("redirect-uri-2 " + randomString);
    rUri2.setRedirectUriType("type-2 " + randomString);
    rUri2.setUriActType("uri-act-type-2 " + randomString);
    rUri2.setUriGeoArea("uri-geo-area-2 " + randomString);
    ClientRedirectUri rUri3 = new ClientRedirectUri();
    Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
    scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
    rUri3.setPredefinedClientScopes(scopes3);
    rUri3.setRedirectUri("redirect-uri-3 " + randomString);
    rUri3.setRedirectUriType("type-3 " + randomString);
    rUri3.setUriActType("uri-act-type-3 " + randomString);
    rUri3.setUriGeoArea("uri-geo-area-3 " + randomString);
    clientRedirectUris.add(rUri1);
    clientRedirectUris.add(rUri2);
    clientRedirectUris.add(rUri3);
    client.setClientRedirectUris(clientRedirectUris);
    return client;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) HashSet(java.util.HashSet)

Example 3 with ClientRedirectUri

use of org.orcid.jaxb.model.client_v2.ClientRedirectUri in project ORCID-Source by ORCID.

the class ClientManagerTest method editWithoutUpdatingConfigValues.

@Test
public void editWithoutUpdatingConfigValues() {
    String seed = RandomStringUtils.randomAlphanumeric(15);
    Client originalClient = getClient(seed, MEMBER_ID);
    assertFalse(originalClient.getId().startsWith("APP-"));
    // Create the client
    Client client = clientManager.create(originalClient);
    String initialClientSecret = client.getDecryptedSecret();
    // Update some fields
    client.setAllowAutoDeprecate(false);
    client.setAuthenticationProviderId("updated-authentication-provider-id");
    client.setDescription("updated-desciption");
    client.setEmailAccessReason("updated-email-access-reason");
    client.setName("updated-client-name");
    client.setPersistentTokensEnabled(false);
    client.setWebsite("updated-website");
    // Change group id, which should not be persisted
    client.setGroupProfileId("0000-0000-0000-0000");
    // Change client type, which should not be persisted
    client.setClientType(ClientType.UPDATER);
    // Add a new redirect uri
    ClientRedirectUri rUri = new ClientRedirectUri();
    Set<ScopePathType> scopes = new HashSet<ScopePathType>();
    scopes.add(ScopePathType.READ_LIMITED);
    scopes.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri.setPredefinedClientScopes(scopes);
    rUri.setRedirectUri("new-redirect-uri");
    rUri.setRedirectUriType(RedirectUriType.IMPORT_WORKS_WIZARD.value());
    rUri.setUriActType("updated-uri-act-type");
    rUri.setUriGeoArea("updated-geo-area");
    client.getClientRedirectUris().add(rUri);
    // Edit the client
    Date editTime = new Date();
    clientManager.edit(client, false);
    // Verify new data is there
    ClientDetailsEntity entityClient = clientDetailsDao.find(client.getId());
    assertEquals(MEMBER_ID, entityClient.getGroupProfileId());
    assertEquals("updated-desciption", entityClient.getClientDescription());
    assertEquals("updated-client-name", entityClient.getClientName());
    assertEquals("updated-website", entityClient.getClientWebsite());
    assertEquals(initialClientSecret, encryptionManager.decryptForInternalUse(entityClient.getClientSecretForJpa()));
    assertFalse(entityClient.isAllowAutoDeprecate());
    // Verify authentication provider id doesn't changed
    assertNotEquals(originalClient.getAuthenticationProviderId(), client.getAuthenticationProviderId());
    assertEquals(originalClient.getAuthenticationProviderId(), entityClient.getAuthenticationProviderId());
    // Verify enable persistent tokens doesn't changed
    assertNotEquals(originalClient.isPersistentTokensEnabled(), client.isPersistentTokensEnabled());
    assertEquals(originalClient.isPersistentTokensEnabled(), entityClient.isPersistentTokensEnabled());
    // Verify config data doesn't changed
    validateClientConfigSettings(entityClient, editTime);
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 4 with ClientRedirectUri

use of org.orcid.jaxb.model.client_v2.ClientRedirectUri in project ORCID-Source by ORCID.

the class ClientManagerTest method editUpdatingConfigValues.

@Test
public void editUpdatingConfigValues() {
    String seed = RandomStringUtils.randomAlphanumeric(15);
    Client originalClient = getClient(seed, MEMBER_ID);
    assertFalse(originalClient.getId().startsWith("APP-"));
    // Create the client
    Client client = clientManager.create(originalClient);
    String initialClientSecret = client.getDecryptedSecret();
    // Update some fields
    client.setAllowAutoDeprecate(false);
    client.setAuthenticationProviderId("updated-authentication-provider-id");
    client.setDescription("updated-desciption");
    client.setEmailAccessReason("updated-email-access-reason");
    client.setName("updated-client-name");
    client.setPersistentTokensEnabled(false);
    client.setWebsite("updated-website");
    // Change group id, which should not be persisted
    client.setGroupProfileId("0000-0000-0000-0000");
    // Change client type, which should not be persisted
    client.setClientType(ClientType.UPDATER);
    // Add a new redirect uri
    ClientRedirectUri rUri = new ClientRedirectUri();
    Set<ScopePathType> scopes = new HashSet<ScopePathType>();
    scopes.add(ScopePathType.READ_LIMITED);
    scopes.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri.setPredefinedClientScopes(scopes);
    rUri.setRedirectUri("new-redirect-uri");
    rUri.setRedirectUriType(RedirectUriType.IMPORT_WORKS_WIZARD.value());
    rUri.setUriActType("updated-uri-act-type");
    rUri.setUriGeoArea("updated-geo-area");
    client.getClientRedirectUris().add(rUri);
    // Edit the client
    Date editTime = new Date();
    clientManager.edit(client, true);
    // Verify new data is there
    ClientDetailsEntity entityClient = clientDetailsDao.find(client.getId());
    assertEquals(MEMBER_ID, entityClient.getGroupProfileId());
    assertEquals("updated-desciption", entityClient.getClientDescription());
    assertEquals("updated-client-name", entityClient.getClientName());
    assertEquals("updated-website", entityClient.getClientWebsite());
    assertEquals(initialClientSecret, encryptionManager.decryptForInternalUse(entityClient.getClientSecretForJpa()));
    assertFalse(entityClient.isAllowAutoDeprecate());
    // Verify authentication provider id changed
    assertNotEquals(originalClient.getAuthenticationProviderId(), client.getAuthenticationProviderId());
    assertEquals(client.getAuthenticationProviderId(), entityClient.getAuthenticationProviderId());
    // Verify enable persistent tokens changed
    assertNotEquals(originalClient.isPersistentTokensEnabled(), client.isPersistentTokensEnabled());
    assertEquals(client.isPersistentTokensEnabled(), entityClient.isPersistentTokensEnabled());
    // Verify config data doesn't changed
    validateClientConfigSettings(entityClient, editTime);
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 5 with ClientRedirectUri

use of org.orcid.jaxb.model.client_v2.ClientRedirectUri in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method getClient.

private Client getClient() {
    Client client = new Client();
    client.setAllowAutoDeprecate(true);
    client.setPersistentTokensEnabled(true);
    client.setClientType(ClientType.CREATOR);
    client.setDescription("description");
    client.setGroupProfileId("group-profile-id");
    client.setId("id");
    client.setName("client-name");
    client.setWebsite("client-website");
    client.setAuthenticationProviderId("authentication-provider-id");
    Set<ClientRedirectUri> clientRedirectUris = new HashSet<ClientRedirectUri>();
    ClientRedirectUri rUri1 = new ClientRedirectUri();
    Set<ScopePathType> scopes1 = new HashSet<ScopePathType>();
    scopes1.add(ScopePathType.ACTIVITIES_READ_LIMITED);
    rUri1.setPredefinedClientScopes(scopes1);
    rUri1.setRedirectUri("redirect-uri-1");
    rUri1.setRedirectUriType("type-1");
    rUri1.setUriActType("uri-act-type-1");
    rUri1.setUriGeoArea("uri-geo-area-1");
    ClientRedirectUri rUri2 = new ClientRedirectUri();
    Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
    scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri2.setPredefinedClientScopes(scopes2);
    rUri2.setRedirectUri("redirect-uri-2");
    rUri2.setRedirectUriType("type-2");
    rUri2.setUriActType("uri-act-type-2");
    rUri2.setUriGeoArea("uri-geo-area-2");
    ClientRedirectUri rUri3 = new ClientRedirectUri();
    Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
    scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
    rUri3.setPredefinedClientScopes(scopes3);
    rUri3.setRedirectUri("redirect-uri-3");
    rUri3.setRedirectUriType("type-3");
    rUri3.setUriActType("uri-act-type-3");
    rUri3.setUriGeoArea("uri-geo-area-3");
    clientRedirectUris.add(rUri1);
    clientRedirectUris.add(rUri2);
    clientRedirectUris.add(rUri3);
    client.setClientRedirectUris(clientRedirectUris);
    return client;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)6 Client (org.orcid.jaxb.model.client_v2.Client)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 Date (java.util.Date)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 Test (org.junit.Test)2 BaseTest (org.orcid.core.BaseTest)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 MappingContext (ma.glasnost.orika.MappingContext)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 ClientSummary (org.orcid.jaxb.model.client_v2.ClientSummary)1 FuzzyDate (org.orcid.jaxb.model.common_v2.FuzzyDate)1 PublicationDate (org.orcid.jaxb.model.common_v2.PublicationDate)1 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)1 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)1