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));
}
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;
}
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);
}
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;
}
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;
}
}
Aggregations