Search in sources :

Example 1 with ClientRegistrationRequest

use of io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest in project gravitee-management-rest-api by gravitee-io.

the class ClientRegistrationServiceImpl method convert.

private ClientRegistrationRequest convert(NewApplicationEntity application) {
    ClientRegistrationRequest request = new ClientRegistrationRequest();
    request.setClientName(application.getName());
    request.setApplicationType(application.getSettings().getoAuthClient().getApplicationType());
    request.setClientUri(application.getSettings().getoAuthClient().getClientUri());
    request.setGrantTypes(application.getSettings().getoAuthClient().getGrantTypes());
    request.setLogoUri(application.getSettings().getoAuthClient().getLogoUri());
    request.setRedirectUris(application.getSettings().getoAuthClient().getRedirectUris());
    request.setResponseTypes(application.getSettings().getoAuthClient().getResponseTypes());
    return request;
}
Also used : ClientRegistrationRequest(io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest)

Example 2 with ClientRegistrationRequest

use of io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest 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 3 with ClientRegistrationRequest

use of io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest 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

ClientRegistrationRequest (io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationRequest)3 ClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity)2 NewClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity)2 UpdateClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.UpdateClientRegistrationProviderEntity)2 DiscoveryBasedDynamicClientRegistrationProviderClient (io.gravitee.rest.api.service.impl.configuration.application.registration.client.DiscoveryBasedDynamicClientRegistrationProviderClient)2 DynamicClientRegistrationProviderClient (io.gravitee.rest.api.service.impl.configuration.application.registration.client.DynamicClientRegistrationProviderClient)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 ClientRegistrationResponse (io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse)1 IOException (java.io.IOException)1