Search in sources :

Example 1 with ClientRegistrationProviderEntity

use of io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class ClientRegistrationProvidersResourceTest method shouldCreateSubscription.

@Test
public void shouldCreateSubscription() {
    reset(clientRegistrationService);
    NewClientRegistrationProviderEntity newClientRegistrationProviderEntity = new NewClientRegistrationProviderEntity();
    newClientRegistrationProviderEntity.setName("my-client-registration-provider-name");
    newClientRegistrationProviderEntity.setDiscoveryEndpoint("my-client-registration-provider-discovery-endpoint");
    newClientRegistrationProviderEntity.setInitialAccessTokenType(InitialAccessTokenType.INITIAL_ACCESS_TOKEN);
    newClientRegistrationProviderEntity.setInitialAccessToken("my-client-registration-provider-initial-access-token");
    ClientRegistrationProviderEntity createdClientRegistrationProvider = new ClientRegistrationProviderEntity();
    createdClientRegistrationProvider.setId("my-client-registration-provider-id");
    when(clientRegistrationService.create(any())).thenReturn(createdClientRegistrationProvider);
    final Response response = envTarget().request().post(Entity.json(newClientRegistrationProviderEntity));
    assertEquals(CREATED_201, response.getStatus());
    assertEquals(envTarget().path("my-client-registration-provider-id").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
}
Also used : Response(javax.ws.rs.core.Response) NewClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity) NewClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity) ClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity) Test(org.junit.Test)

Example 2 with ClientRegistrationProviderEntity

use of io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class ClientRegistrationServiceImpl method convert.

private ClientRegistrationProviderEntity convert(ClientRegistrationProvider clientRegistrationProvider) {
    ClientRegistrationProviderEntity entity = new ClientRegistrationProviderEntity();
    entity.setId(clientRegistrationProvider.getId());
    entity.setName(clientRegistrationProvider.getName());
    entity.setDescription(clientRegistrationProvider.getDescription());
    entity.setDiscoveryEndpoint(clientRegistrationProvider.getDiscoveryEndpoint());
    entity.setRenewClientSecretSupport(clientRegistrationProvider.isRenewClientSecretSupport());
    entity.setRenewClientSecretMethod(clientRegistrationProvider.getRenewClientSecretMethod());
    entity.setRenewClientSecretEndpoint(clientRegistrationProvider.getRenewClientSecretEndpoint());
    entity.setSoftwareId(clientRegistrationProvider.getSoftwareId());
    if (clientRegistrationProvider.getInitialAccessTokenType() == null || clientRegistrationProvider.getInitialAccessTokenType() == ClientRegistrationProvider.InitialAccessTokenType.CLIENT_CREDENTIALS) {
        entity.setInitialAccessTokenType(InitialAccessTokenType.CLIENT_CREDENTIALS);
        entity.setClientId(clientRegistrationProvider.getClientId());
        entity.setClientSecret(clientRegistrationProvider.getClientSecret());
        entity.setScopes(clientRegistrationProvider.getScopes());
    } else {
        entity.setInitialAccessTokenType(InitialAccessTokenType.INITIAL_ACCESS_TOKEN);
        entity.setInitialAccessToken(clientRegistrationProvider.getInitialAccessToken());
    }
    entity.setCreatedAt(clientRegistrationProvider.getCreatedAt());
    entity.setUpdatedAt(clientRegistrationProvider.getUpdatedAt());
    return entity;
}
Also used : NewClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity) UpdateClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.UpdateClientRegistrationProviderEntity) ClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity)

Example 3 with ClientRegistrationProviderEntity

use of io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class ClientRegistrationServiceImpl method register.

@Override
public ClientRegistrationResponse register(NewApplicationEntity application) {
    // Create an OAuth client
    Set<ClientRegistrationProviderEntity> providers = findAll();
    if (providers == null || providers.isEmpty()) {
        throw new MissingDynamicClientRegistrationProviderException();
    }
    // For now, took the first provider
    ClientRegistrationProviderEntity provider = providers.iterator().next();
    // Get provider client
    DynamicClientRegistrationProviderClient registrationProviderClient = getDCRClient(false, provider);
    ClientRegistrationRequest clientRegistrationRequest = convert(application);
    if (provider.getSoftwareId() != null && !provider.getSoftwareId().isEmpty()) {
        clientRegistrationRequest.setSoftwareId(provider.getSoftwareId());
    }
    return registrationProviderClient.register(clientRegistrationRequest);
}
Also used : NewClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity) UpdateClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.UpdateClientRegistrationProviderEntity) ClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity) ClientRegistrationRequest(io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest) DynamicClientRegistrationProviderClient(io.gravitee.rest.api.service.impl.configuration.application.registration.client.DynamicClientRegistrationProviderClient) DiscoveryBasedDynamicClientRegistrationProviderClient(io.gravitee.rest.api.service.impl.configuration.application.registration.client.DiscoveryBasedDynamicClientRegistrationProviderClient)

Example 4 with ClientRegistrationProviderEntity

use of io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationServiceImpl method getSettings.

private ApplicationSettings getSettings(Application application) {
    final ApplicationSettings settings = new ApplicationSettings();
    if (application.getType() == ApplicationType.SIMPLE) {
        SimpleApplicationSettings simpleSettings = new SimpleApplicationSettings();
        if (application.getMetadata() != null) {
            if (application.getMetadata().get("client_id") != null) {
                simpleSettings.setClientId(application.getMetadata().get("client_id"));
            }
            if (application.getMetadata().get("type") != null) {
                simpleSettings.setType(application.getMetadata().get("type"));
            }
        }
        settings.setApp(simpleSettings);
    } else {
        OAuthClientSettings clientSettings = new OAuthClientSettings();
        if (application.getMetadata() != null) {
            try {
                final String registrationPayload = application.getMetadata().get("registration_payload");
                if (registrationPayload != null) {
                    final ClientRegistrationResponse registrationResponse = mapper.readValue(registrationPayload, ClientRegistrationResponse.class);
                    clientSettings.setClientId(registrationResponse.getClientId());
                    clientSettings.setClientSecret(registrationResponse.getClientSecret());
                    clientSettings.setClientUri(registrationResponse.getClientUri());
                    clientSettings.setApplicationType(registrationResponse.getApplicationType());
                    clientSettings.setLogoUri(registrationResponse.getLogoUri());
                    clientSettings.setResponseTypes(registrationResponse.getResponseTypes());
                    clientSettings.setRedirectUris(registrationResponse.getRedirectUris());
                    clientSettings.setGrantTypes(registrationResponse.getGrantTypes());
                }
                Iterator<ClientRegistrationProviderEntity> clientRegistrationProviderIte = clientRegistrationService.findAll().iterator();
                if (clientRegistrationProviderIte.hasNext()) {
                    clientSettings.setRenewClientSecretSupported(clientRegistrationProviderIte.next().isRenewClientSecretSupport());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        settings.setoAuthClient(clientSettings);
    }
    return settings;
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) ClientRegistrationResponse(io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse) ClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity) UuidString(io.gravitee.rest.api.service.common.UuidString) IOException(java.io.IOException)

Example 5 with ClientRegistrationProviderEntity

use of io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity in project gravitee-management-rest-api by gravitee-io.

the class ClientRegistrationServiceImpl method update.

@Override
public ClientRegistrationResponse update(String previousRegistrationResponse, UpdateApplicationEntity application) {
    try {
        ClientRegistrationResponse registrationResponse = mapper.readValue(previousRegistrationResponse, ClientRegistrationResponse.class);
        if (registrationResponse.getRegistrationAccessToken() == null || registrationResponse.getRegistrationAccessToken().isEmpty() || registrationResponse.getRegistrationClientUri() == null || registrationResponse.getRegistrationClientUri().isEmpty()) {
            throw new RegisteredClientNotUpdatableException();
        }
        // Update an OAuth client
        Set<ClientRegistrationProviderEntity> providers = findAll();
        if (providers == null || providers.isEmpty()) {
            throw new MissingDynamicClientRegistrationProviderException();
        }
        // For now, took the first provider
        ClientRegistrationProviderEntity provider = providers.iterator().next();
        // Get provider client
        DynamicClientRegistrationProviderClient registrationProviderClient = getDCRClient(false, provider);
        ClientRegistrationRequest registrationRequest = mapper.readValue(previousRegistrationResponse, ClientRegistrationRequest.class);
        registrationRequest.setSoftwareId(provider.getSoftwareId());
        return registrationProviderClient.update(registrationResponse.getRegistrationAccessToken(), registrationResponse.getRegistrationClientUri(), convert(registrationRequest, application), application.getSettings().getoAuthClient().getClientId());
    } catch (Exception ex) {
        LOGGER.error("Unexpected error while updating a client", ex);
        return null;
    }
}
Also used : ClientRegistrationResponse(io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse) NewClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity) UpdateClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.UpdateClientRegistrationProviderEntity) ClientRegistrationProviderEntity(io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity) ClientRegistrationRequest(io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest) DynamicClientRegistrationProviderClient(io.gravitee.rest.api.service.impl.configuration.application.registration.client.DynamicClientRegistrationProviderClient) DiscoveryBasedDynamicClientRegistrationProviderClient(io.gravitee.rest.api.service.impl.configuration.application.registration.client.DiscoveryBasedDynamicClientRegistrationProviderClient) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) IOException(java.io.IOException)

Aggregations

ClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity)7 NewClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity)6 UpdateClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.UpdateClientRegistrationProviderEntity)5 DiscoveryBasedDynamicClientRegistrationProviderClient (io.gravitee.rest.api.service.impl.configuration.application.registration.client.DiscoveryBasedDynamicClientRegistrationProviderClient)4 DynamicClientRegistrationProviderClient (io.gravitee.rest.api.service.impl.configuration.application.registration.client.DynamicClientRegistrationProviderClient)4 ClientRegistrationResponse (io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse)3 IOException (java.io.IOException)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 UuidString (io.gravitee.rest.api.service.common.UuidString)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 ClientRegistrationRequest (io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest)2 TemplateEngine (io.gravitee.el.TemplateEngine)1 ClientRegistrationProvider (io.gravitee.repository.management.model.ClientRegistrationProvider)1 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)1 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)1 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)1 Date (java.util.Date)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1