Search in sources :

Example 1 with DiscoveryBasedDynamicClientRegistrationProviderClient

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

the class ClientRegistrationServiceImpl method renewClientSecret.

@Override
public ClientRegistrationResponse renewClientSecret(String previousRegistrationResponse) {
    try {
        ClientRegistrationResponse registrationResponse = mapper.readValue(previousRegistrationResponse, ClientRegistrationResponse.class);
        if (registrationResponse.getRegistrationAccessToken() == null || registrationResponse.getRegistrationAccessToken().isEmpty() || registrationResponse.getRegistrationClientUri() == null || registrationResponse.getRegistrationClientUri().isEmpty()) {
            throw new RegisteredClientNotUpdatableException();
        }
        Set<ClientRegistrationProviderEntity> providers = findAll();
        if (providers == null || providers.isEmpty()) {
            throw new MissingDynamicClientRegistrationProviderException();
        }
        // For now, take the first provider
        ClientRegistrationProviderEntity provider = providers.iterator().next();
        // Get provider client
        DynamicClientRegistrationProviderClient registrationProviderClient = getDCRClient(false, provider);
        String renewClientSecretEndpoint = provider.getRenewClientSecretEndpoint();
        TemplateEngine templateEngine = TemplateEngine.templateEngine();
        templateEngine.getTemplateContext().setVariable("client_id", registrationResponse.getClientId());
        if (registrationProviderClient instanceof DiscoveryBasedDynamicClientRegistrationProviderClient) {
            ((DiscoveryBasedDynamicClientRegistrationProviderClient) registrationProviderClient).getMetadata().forEach((s, o) -> templateEngine.getTemplateContext().setVariable(s, o));
        }
        return registrationProviderClient.renewClientSecret(provider.getRenewClientSecretMethod(), templateEngine.getValue(renewClientSecretEndpoint, String.class), registrationResponse.getRegistrationAccessToken());
    } catch (IOException ioe) {
        LOGGER.error("Unexpected error while updating a client", ioe);
        return null;
    }
}
Also used : TemplateEngine(io.gravitee.el.TemplateEngine) DiscoveryBasedDynamicClientRegistrationProviderClient(io.gravitee.rest.api.service.impl.configuration.application.registration.client.DiscoveryBasedDynamicClientRegistrationProviderClient) 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) UuidString(io.gravitee.rest.api.service.common.UuidString) IOException(java.io.IOException) DynamicClientRegistrationProviderClient(io.gravitee.rest.api.service.impl.configuration.application.registration.client.DynamicClientRegistrationProviderClient) DiscoveryBasedDynamicClientRegistrationProviderClient(io.gravitee.rest.api.service.impl.configuration.application.registration.client.DiscoveryBasedDynamicClientRegistrationProviderClient)

Aggregations

TemplateEngine (io.gravitee.el.TemplateEngine)1 ClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.ClientRegistrationProviderEntity)1 NewClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.NewClientRegistrationProviderEntity)1 UpdateClientRegistrationProviderEntity (io.gravitee.rest.api.model.configuration.application.registration.UpdateClientRegistrationProviderEntity)1 UuidString (io.gravitee.rest.api.service.common.UuidString)1 DiscoveryBasedDynamicClientRegistrationProviderClient (io.gravitee.rest.api.service.impl.configuration.application.registration.client.DiscoveryBasedDynamicClientRegistrationProviderClient)1 DynamicClientRegistrationProviderClient (io.gravitee.rest.api.service.impl.configuration.application.registration.client.DynamicClientRegistrationProviderClient)1 ClientRegistrationResponse (io.gravitee.rest.api.service.impl.configuration.application.registration.client.register.ClientRegistrationResponse)1 IOException (java.io.IOException)1