use of io.gravitee.repository.management.model.ClientRegistrationProvider in project gravitee-management-rest-api by gravitee-io.
the class ClientRegistrationServiceImpl method convert.
private ClientRegistrationProvider convert(NewClientRegistrationProviderEntity newClientRegistrationProvider) {
ClientRegistrationProvider provider = new ClientRegistrationProvider();
provider.setId(UUID.toString(UUID.random()));
provider.setName(newClientRegistrationProvider.getName());
provider.setDescription(newClientRegistrationProvider.getDescription());
provider.setDiscoveryEndpoint(newClientRegistrationProvider.getDiscoveryEndpoint());
provider.setRenewClientSecretSupport(newClientRegistrationProvider.isRenewClientSecretSupport());
provider.setRenewClientSecretMethod(newClientRegistrationProvider.getRenewClientSecretMethod());
provider.setRenewClientSecretEndpoint(newClientRegistrationProvider.getRenewClientSecretEndpoint());
provider.setSoftwareId(newClientRegistrationProvider.getSoftwareId());
if (newClientRegistrationProvider.getInitialAccessTokenType() == InitialAccessTokenType.CLIENT_CREDENTIALS) {
provider.setInitialAccessTokenType(ClientRegistrationProvider.InitialAccessTokenType.CLIENT_CREDENTIALS);
provider.setClientId(newClientRegistrationProvider.getClientId());
provider.setClientSecret(newClientRegistrationProvider.getClientSecret());
provider.setScopes(newClientRegistrationProvider.getScopes());
} else {
provider.setInitialAccessTokenType(ClientRegistrationProvider.InitialAccessTokenType.INITIAL_ACCESS_TOKEN);
provider.setInitialAccessToken(newClientRegistrationProvider.getInitialAccessToken());
}
return provider;
}
use of io.gravitee.repository.management.model.ClientRegistrationProvider in project gravitee-management-rest-api by gravitee-io.
the class ClientRegistrationServiceImpl method delete.
@Override
public void delete(String id) {
try {
LOGGER.debug("Delete client registration provider: {}", id);
Optional<ClientRegistrationProvider> clientRegistrationProvider = clientRegistrationProviderRepository.findById(id);
if (!clientRegistrationProvider.isPresent()) {
throw new ClientRegistrationProviderNotFoundException(id);
}
clientRegistrationProviderRepository.delete(id);
auditService.createEnvironmentAuditLog(Collections.singletonMap(CLIENT_REGISTRATION_PROVIDER, id), ClientRegistrationProvider.AuditEvent.CLIENT_REGISTRATION_PROVIDER_DELETED, new Date(), clientRegistrationProvider.get(), null);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete a client registration provider using its ID {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to delete a client registration provider using its ID " + id, ex);
}
}
use of io.gravitee.repository.management.model.ClientRegistrationProvider in project gravitee-management-rest-api by gravitee-io.
the class ClientRegistrationServiceImpl method convert.
private ClientRegistrationProvider convert(UpdateClientRegistrationProviderEntity updateClientRegistrationProvider) {
ClientRegistrationProvider provider = new ClientRegistrationProvider();
provider.setName(updateClientRegistrationProvider.getName());
provider.setDescription(updateClientRegistrationProvider.getDescription());
provider.setDiscoveryEndpoint(updateClientRegistrationProvider.getDiscoveryEndpoint());
provider.setRenewClientSecretSupport(updateClientRegistrationProvider.isRenewClientSecretSupport());
provider.setRenewClientSecretMethod(updateClientRegistrationProvider.getRenewClientSecretMethod());
provider.setRenewClientSecretEndpoint(updateClientRegistrationProvider.getRenewClientSecretEndpoint());
provider.setSoftwareId(updateClientRegistrationProvider.getSoftwareId());
if (updateClientRegistrationProvider.getInitialAccessTokenType() == InitialAccessTokenType.CLIENT_CREDENTIALS) {
provider.setInitialAccessTokenType(ClientRegistrationProvider.InitialAccessTokenType.CLIENT_CREDENTIALS);
provider.setClientId(updateClientRegistrationProvider.getClientId());
provider.setClientSecret(updateClientRegistrationProvider.getClientSecret());
provider.setScopes(updateClientRegistrationProvider.getScopes());
} else {
provider.setInitialAccessTokenType(ClientRegistrationProvider.InitialAccessTokenType.INITIAL_ACCESS_TOKEN);
provider.setInitialAccessToken(updateClientRegistrationProvider.getInitialAccessToken());
}
return provider;
}
use of io.gravitee.repository.management.model.ClientRegistrationProvider in project gravitee-management-rest-api by gravitee-io.
the class ClientRegistrationServiceImpl method update.
@Override
public ClientRegistrationProviderEntity update(String id, UpdateClientRegistrationProviderEntity updateClientRegistrationProvider) {
try {
LOGGER.debug("Update client registration provider {}", updateClientRegistrationProvider);
Optional<ClientRegistrationProvider> optClientRegistrationProvider = clientRegistrationProviderRepository.findById(id);
if (!optClientRegistrationProvider.isPresent()) {
throw new ClientRegistrationProviderNotFoundException(updateClientRegistrationProvider.getName());
}
if (updateClientRegistrationProvider.getInitialAccessTokenType() == InitialAccessTokenType.INITIAL_ACCESS_TOKEN && (updateClientRegistrationProvider.getInitialAccessToken() == null || updateClientRegistrationProvider.getInitialAccessToken().isEmpty())) {
throw new EmptyInitialAccessTokenException();
}
ClientRegistrationProvider clientRegistrationProvider = convert(updateClientRegistrationProvider);
// Check renew_client_secret configuration
renewClientSecretSupport(clientRegistrationProvider);
clientRegistrationProvider.setId(id);
DynamicClientRegistrationProviderClient registrationProviderClient = getDCRClient(true, convert(clientRegistrationProvider));
// Ensure that the client credentials are valid
registrationProviderClient.getInitialAccessToken();
LOGGER.debug("Found a DCR Client for provider: {}", clientRegistrationProvider.getName(), registrationProviderClient);
final ClientRegistrationProvider clientProviderToUpdate = optClientRegistrationProvider.get();
clientRegistrationProvider.setId(id);
clientRegistrationProvider.setCreatedAt(clientProviderToUpdate.getCreatedAt());
clientRegistrationProvider.setUpdatedAt(new Date());
ClientRegistrationProvider updatedClientRegistrationProvider = clientRegistrationProviderRepository.update(clientRegistrationProvider);
// Audit
auditService.createEnvironmentAuditLog(singletonMap(CLIENT_REGISTRATION_PROVIDER, id), ClientRegistrationProvider.AuditEvent.CLIENT_REGISTRATION_PROVIDER_CREATED, clientRegistrationProvider.getUpdatedAt(), clientProviderToUpdate, updatedClientRegistrationProvider);
return convert(updatedClientRegistrationProvider);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update client registration provider {}", updateClientRegistrationProvider, ex);
throw new TechnicalManagementException("An error occurs while trying to update " + updateClientRegistrationProvider, ex);
}
}
use of io.gravitee.repository.management.model.ClientRegistrationProvider in project gravitee-management-rest-api by gravitee-io.
the class ClientRegistrationServiceImpl method create.
@Override
public ClientRegistrationProviderEntity create(NewClientRegistrationProviderEntity newClientRegistrationProvider) {
try {
LOGGER.debug("Create client registration provider {}", newClientRegistrationProvider);
Set<ClientRegistrationProviderEntity> clientRegistrationProviders = this.findAll();
// For now, we are supporting only a single client registration provider.
if (clientRegistrationProviders.size() == 1) {
throw new IllegalStateException("Until now, supports only a single client registration provider. " + "Please update the existing one: " + clientRegistrationProviders.iterator().next().getName());
}
Optional<ClientRegistrationProvider> optClientRegistrationProvider = clientRegistrationProviderRepository.findById(IdGenerator.generate(newClientRegistrationProvider.getName()));
if (optClientRegistrationProvider.isPresent()) {
throw new ClientRegistrationProviderAlreadyExistsException(newClientRegistrationProvider.getName());
}
if (newClientRegistrationProvider.getInitialAccessTokenType() == InitialAccessTokenType.INITIAL_ACCESS_TOKEN && (newClientRegistrationProvider.getInitialAccessToken() == null || newClientRegistrationProvider.getInitialAccessToken().isEmpty())) {
throw new EmptyInitialAccessTokenException();
}
ClientRegistrationProvider clientRegistrationProvider = convert(newClientRegistrationProvider);
// Check renew_client_secret configuration
renewClientSecretSupport(clientRegistrationProvider);
clientRegistrationProvider.setId(UuidString.generateRandom());
DynamicClientRegistrationProviderClient registrationProviderClient = getDCRClient(true, convert(clientRegistrationProvider));
// Ensure that the client credentials are valid
registrationProviderClient.getInitialAccessToken();
LOGGER.debug("Found a DCR Client for provider: {}", clientRegistrationProvider.getName(), registrationProviderClient);
// Set date fields
clientRegistrationProvider.setCreatedAt(new Date());
clientRegistrationProvider.setUpdatedAt(clientRegistrationProvider.getCreatedAt());
ClientRegistrationProvider createdClientRegistrationProvider = clientRegistrationProviderRepository.create(clientRegistrationProvider);
auditService.createEnvironmentAuditLog(singletonMap(CLIENT_REGISTRATION_PROVIDER, createdClientRegistrationProvider.getId()), ClientRegistrationProvider.AuditEvent.CLIENT_REGISTRATION_PROVIDER_CREATED, createdClientRegistrationProvider.getUpdatedAt(), null, createdClientRegistrationProvider);
return convert(createdClientRegistrationProvider);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create client registration provider {}", newClientRegistrationProvider, ex);
throw new TechnicalManagementException("An error occurs while trying to create " + newClientRegistrationProvider, ex);
}
}
Aggregations