Search in sources :

Example 1 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.

the class ClientDetailsManagerTest method testGetClient.

@Test
public void testGetClient() {
    Client client = clientDetailsManager.getClient("APP-6666666666666666");
    assertNotNull(client);
    assertEquals("Source Client 2", client.getName());
    assertEquals("A test source client", client.getDescription());
}
Also used : Client(org.orcid.jaxb.model.client_v2.Client) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method toEntity_withExistingEntityTest.

@Test
public void toEntity_withExistingEntityTest() {
    Client client = getClient();
    ClientDetailsEntity existingEntity = getClientDetailsEntity();
    existingEntity = adapter.toEntity(client, existingEntity);
    assertEquals(getClientDetailsEntity(), existingEntity);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test)

Example 3 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method toClientTest.

@Test
public void toClientTest() {
    ClientDetailsEntity entity = getClientDetailsEntity();
    Client client = adapter.toClient(entity);
    assertEquals(getClient(), client);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test)

Example 4 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method toEntityTest.

@Test
public void toEntityTest() {
    Client client = getClient();
    ClientDetailsEntity entity = adapter.toEntity(client);
    ClientDetailsEntity toCompare = getClientDetailsEntity();
    // Configuration values should be the default
    assertFalse(entity.isPersistentTokensEnabled());
    assertNull(entity.getAuthenticationProviderId());
    assertEquals(toCompare.getClientDescription(), entity.getClientDescription());
    assertEquals(toCompare.getClientId(), entity.getClientId());
    assertEquals(toCompare.getClientName(), entity.getClientName());
    assertEquals(toCompare.getClientRegisteredRedirectUris(), entity.getClientRegisteredRedirectUris());
    assertEquals(toCompare.getClientWebsite(), entity.getClientWebsite());
    assertEquals(toCompare.isAllowAutoDeprecate(), entity.isAllowAutoDeprecate());
    assertNull(entity.getClientType());
    assertNull(entity.getEmailAccessReason());
    assertNull(entity.getGroupProfileId());
    assertNull(entity.getClientSecrets());
    assertEquals(Collections.EMPTY_SET, entity.getClientAuthorizedGrantTypes());
    assertEquals(Collections.EMPTY_SET, entity.getClientResourceIds());
    assertEquals(Collections.EMPTY_SET, entity.getClientScopes());
    assertEquals(Collections.EMPTY_SET, entity.getCustomEmails());
    assertEquals(Collections.EMPTY_LIST, entity.getClientGrantedAuthorities());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test)

Example 5 with Client

use of com.predic8.membrane.core.interceptor.oauth2.Client 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)

Aggregations

Test (org.junit.Test)27 Client (org.orcid.jaxb.model.client_v2.Client)18 Exchange (com.predic8.membrane.core.exchange.Exchange)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 IOException (java.io.IOException)8 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)6 Outcome (com.predic8.membrane.core.interceptor.Outcome)6 HashSet (java.util.HashSet)6 BaseTest (org.orcid.core.BaseTest)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 URISyntaxException (java.net.URISyntaxException)5 HttpClient (org.apache.commons.httpclient.HttpClient)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 Request (com.predic8.membrane.core.http.Request)4 Response (com.predic8.membrane.core.http.Response)4 Process2 (com.predic8.membrane.examples.Process2)4 Http11Test (com.predic8.membrane.integration.Http11Test)4 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)3 Client (com.predic8.membrane.core.interceptor.oauth2.Client)3 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)3