use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersKeyManagerIdPut.
public Response keyManagersKeyManagerIdPut(String keyManagerId, KeyManagerDTO body, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
try {
KeyManagerConfigurationDTO keyManagerConfigurationDTO = KeyManagerMappingUtil.toKeyManagerConfigurationDTO(organization, body);
keyManagerConfigurationDTO.setUuid(keyManagerId);
KeyManagerConfigurationDTO oldKeyManagerConfigurationDTO = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId);
if (oldKeyManagerConfigurationDTO == null) {
throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);
} else {
if (!oldKeyManagerConfigurationDTO.getName().equals(keyManagerConfigurationDTO.getName())) {
RestApiUtil.handleBadRequest("Key Manager name couldn't able to change", log);
}
KeyManagerConfigurationDTO retrievedKeyManagerConfigurationDTO = apiAdmin.updateKeyManagerConfiguration(keyManagerConfigurationDTO);
APIUtil.logAuditMessage(APIConstants.AuditLogConstants.KEY_MANAGER, new Gson().toJson(keyManagerConfigurationDTO), APIConstants.AuditLogConstants.UPDATED, RestApiCommonUtil.getLoggedInUsername());
return Response.ok(KeyManagerMappingUtil.toKeyManagerDTO(retrievedKeyManagerConfigurationDTO)).build();
}
} catch (APIManagementException e) {
String error = "Error while Retrieving Key Manager configuration for " + keyManagerId + " in organization " + organization;
throw new APIManagementException(error, e, ExceptionCodes.INTERNAL_ERROR);
}
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeyManagersApiServiceImpl method keyManagersKeyManagerIdGet.
public Response keyManagersKeyManagerIdGet(String keyManagerId, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getOrganization(messageContext);
APIAdmin apiAdmin = new APIAdminImpl();
KeyManagerConfigurationDTO keyManagerConfigurationDTO = apiAdmin.getKeyManagerConfigurationById(organization, keyManagerId);
if (keyManagerConfigurationDTO != null) {
KeyManagerDTO keyManagerDTO = KeyManagerMappingUtil.toKeyManagerDTO(keyManagerConfigurationDTO);
return Response.ok(keyManagerDTO).build();
}
throw new APIManagementException("Requested KeyManager not found", ExceptionCodes.KEY_MANAGER_NOT_FOUND);
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeyManagerMappingUtil method fromOpenIdConnectConfigurationToKeyManagerConfiguration.
public static KeyManagerWellKnownResponseDTO fromOpenIdConnectConfigurationToKeyManagerConfiguration(OpenIdConnectConfiguration openIdConnectConfiguration) {
KeyManagerWellKnownResponseDTO keyManagerWellKnownResponseDTO = new KeyManagerWellKnownResponseDTO();
if (openIdConnectConfiguration != null) {
keyManagerWellKnownResponseDTO.setValid(true);
KeyManagerDTO keyManagerDto = new KeyManagerDTO();
keyManagerDto.setIssuer(openIdConnectConfiguration.getIssuer());
keyManagerDto.setIntrospectionEndpoint(openIdConnectConfiguration.getIntrospectionEndpoint());
keyManagerDto.setClientRegistrationEndpoint(openIdConnectConfiguration.getRegistrationEndpoint());
keyManagerDto.setAuthorizeEndpoint(openIdConnectConfiguration.getAuthorizeEndpoint());
keyManagerDto.setTokenEndpoint(openIdConnectConfiguration.getTokenEndpoint());
keyManagerDto.setRevokeEndpoint(openIdConnectConfiguration.getRevokeEndpoint());
keyManagerDto.setEnabled(true);
keyManagerDto.setEnableTokenGeneration(true);
keyManagerDto.setEnableMapOAuthConsumerApps(true);
keyManagerDto.setEnableOAuthAppCreation(true);
keyManagerDto.setEnableSelfValidationJWT(true);
keyManagerDto.setAvailableGrantTypes(openIdConnectConfiguration.getGrantTypesSupported());
if (StringUtils.isNotEmpty(openIdConnectConfiguration.getJwksEndpoint())) {
KeyManagerCertificatesDTO keyManagerCertificatesDTO = new KeyManagerCertificatesDTO();
keyManagerCertificatesDTO.setType(KeyManagerCertificatesDTO.TypeEnum.JWKS);
keyManagerCertificatesDTO.setValue(openIdConnectConfiguration.getJwksEndpoint());
keyManagerDto.setCertificates(keyManagerCertificatesDTO);
}
keyManagerWellKnownResponseDTO.setValue(keyManagerDto);
}
return keyManagerWellKnownResponseDTO;
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeyManagerMappingUtil method toKeyManagerDTO.
public static KeyManagerDTO toKeyManagerDTO(KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
KeyManagerDTO keyManagerDTO = new KeyManagerDTO();
keyManagerDTO.setId(keyManagerConfigurationDTO.getUuid());
keyManagerDTO.setName(keyManagerConfigurationDTO.getName());
keyManagerDTO.setDisplayName(keyManagerConfigurationDTO.getDisplayName());
keyManagerDTO.setDescription(keyManagerConfigurationDTO.getDescription());
keyManagerDTO.setType(keyManagerConfigurationDTO.getType());
keyManagerDTO.setEnabled(keyManagerConfigurationDTO.isEnabled());
keyManagerDTO.setTokenType(KeyManagerDTO.TokenTypeEnum.valueOf(keyManagerConfigurationDTO.getTokenType()));
keyManagerDTO.setAlias(keyManagerConfigurationDTO.getAlias());
keyManagerDTO.setTokenType(KeyManagerDTO.TokenTypeEnum.fromValue(keyManagerConfigurationDTO.getTokenType()));
JsonObject jsonObject = fromConfigurationMapToJson(keyManagerConfigurationDTO.getAdditionalProperties());
JsonElement clientRegistrationElement = jsonObject.get(APIConstants.KeyManager.CLIENT_REGISTRATION_ENDPOINT);
if (clientRegistrationElement != null) {
keyManagerDTO.setClientRegistrationEndpoint(clientRegistrationElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.CLIENT_REGISTRATION_ENDPOINT);
}
JsonElement introspectionElement = jsonObject.get(APIConstants.KeyManager.INTROSPECTION_ENDPOINT);
if (introspectionElement != null) {
keyManagerDTO.setIntrospectionEndpoint(introspectionElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.INTROSPECTION_ENDPOINT);
}
JsonElement tokenEndpointElement = jsonObject.get(APIConstants.KeyManager.TOKEN_ENDPOINT);
if (tokenEndpointElement != null) {
keyManagerDTO.setTokenEndpoint(tokenEndpointElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.TOKEN_ENDPOINT);
}
JsonElement displayTokenEndpointElement = jsonObject.get(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT);
if (displayTokenEndpointElement != null && !displayTokenEndpointElement.getAsString().trim().isEmpty()) {
keyManagerDTO.setDisplayTokenEndpoint(displayTokenEndpointElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT);
}
JsonElement revokeEndpointElement = jsonObject.get(APIConstants.KeyManager.REVOKE_ENDPOINT);
if (revokeEndpointElement != null) {
keyManagerDTO.setRevokeEndpoint(revokeEndpointElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.REVOKE_ENDPOINT);
}
JsonElement displayRevokeEndpointElement = jsonObject.get(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT);
if (displayRevokeEndpointElement != null && !displayRevokeEndpointElement.getAsString().trim().isEmpty()) {
keyManagerDTO.setDisplayRevokeEndpoint(displayRevokeEndpointElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT);
}
JsonElement scopeEndpointElement = jsonObject.get(APIConstants.KeyManager.SCOPE_MANAGEMENT_ENDPOINT);
if (scopeEndpointElement != null) {
keyManagerDTO.setScopeManagementEndpoint(scopeEndpointElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.SCOPE_MANAGEMENT_ENDPOINT);
}
JsonElement grantTypesElement = jsonObject.get(APIConstants.KeyManager.AVAILABLE_GRANT_TYPE);
if (grantTypesElement instanceof JsonArray) {
keyManagerDTO.setAvailableGrantTypes(new Gson().fromJson(grantTypesElement, List.class));
jsonObject.remove(APIConstants.KeyManager.AVAILABLE_GRANT_TYPE);
}
JsonElement issuerElement = jsonObject.get(APIConstants.KeyManager.ISSUER);
if (issuerElement != null) {
keyManagerDTO.setIssuer(issuerElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.ISSUER);
}
JsonElement wellKnownEndpointElement = jsonObject.get(APIConstants.KeyManager.WELL_KNOWN_ENDPOINT);
if (wellKnownEndpointElement != null) {
keyManagerDTO.setWellKnownEndpoint(wellKnownEndpointElement.getAsString());
jsonObject.remove(APIConstants.KeyManager.WELL_KNOWN_ENDPOINT);
}
JsonElement certificateValueElement = jsonObject.get(APIConstants.KeyManager.CERTIFICATE_VALUE);
JsonElement certificateTypeElement = jsonObject.get(APIConstants.KeyManager.CERTIFICATE_TYPE);
if (certificateTypeElement != null && certificateValueElement != null) {
KeyManagerCertificatesDTO keyManagerCertificatesDTO = new KeyManagerCertificatesDTO();
keyManagerCertificatesDTO.setValue(certificateValueElement.getAsString());
if (APIConstants.KeyManager.CERTIFICATE_TYPE_JWKS_ENDPOINT.equals(certificateTypeElement.getAsString())) {
keyManagerCertificatesDTO.setType(KeyManagerCertificatesDTO.TypeEnum.JWKS);
} else if (APIConstants.KeyManager.CERTIFICATE_TYPE_PEM_FILE.equals(certificateTypeElement.getAsString())) {
keyManagerCertificatesDTO.setType(KeyManagerCertificatesDTO.TypeEnum.PEM);
}
keyManagerDTO.setCertificates(keyManagerCertificatesDTO);
jsonObject.remove(APIConstants.KeyManager.CERTIFICATE_VALUE);
jsonObject.remove(APIConstants.KeyManager.CERTIFICATE_TYPE);
}
JsonElement userInfoEndpoint = jsonObject.get(APIConstants.KeyManager.USERINFO_ENDPOINT);
if (userInfoEndpoint != null) {
keyManagerDTO.setUserInfoEndpoint(userInfoEndpoint.getAsString());
jsonObject.remove(APIConstants.KeyManager.USERINFO_ENDPOINT);
}
JsonElement authorizeEndpoint = jsonObject.get(APIConstants.KeyManager.AUTHORIZE_ENDPOINT);
if (authorizeEndpoint != null) {
keyManagerDTO.setAuthorizeEndpoint(authorizeEndpoint.getAsString());
jsonObject.remove(APIConstants.KeyManager.AUTHORIZE_ENDPOINT);
}
JsonElement enableOauthAppCreation = jsonObject.get(APIConstants.KeyManager.ENABLE_OAUTH_APP_CREATION);
if (enableOauthAppCreation != null) {
keyManagerDTO.setEnableOAuthAppCreation(enableOauthAppCreation.getAsBoolean());
jsonObject.remove(APIConstants.KeyManager.ENABLE_OAUTH_APP_CREATION);
}
JsonElement enableMapOauthConsumerApps = jsonObject.get(APIConstants.KeyManager.ENABLE_MAP_OAUTH_CONSUMER_APPS);
if (enableMapOauthConsumerApps != null) {
keyManagerDTO.setEnableMapOAuthConsumerApps(enableMapOauthConsumerApps.getAsBoolean());
jsonObject.remove(APIConstants.KeyManager.ENABLE_MAP_OAUTH_CONSUMER_APPS);
}
JsonElement enableTokenEncryption = jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_ENCRYPTION);
if (enableTokenEncryption != null) {
keyManagerDTO.setEnableTokenEncryption(enableTokenEncryption.getAsBoolean());
jsonObject.remove(APIConstants.KeyManager.ENABLE_TOKEN_ENCRYPTION);
}
JsonElement enableTokenHHashing = jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_HASH);
if (enableTokenEncryption != null) {
keyManagerDTO.setEnableTokenHashing(enableTokenHHashing.getAsBoolean());
jsonObject.remove(APIConstants.KeyManager.ENABLE_TOKEN_HASH);
}
JsonElement enableTokenGeneration = jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_GENERATION);
if (enableTokenGeneration != null) {
keyManagerDTO.setEnableTokenGeneration(enableTokenGeneration.getAsBoolean());
jsonObject.remove(APIConstants.KeyManager.ENABLE_TOKEN_GENERATION);
}
JsonElement selfValidateJWTElement = jsonObject.get(APIConstants.KeyManager.SELF_VALIDATE_JWT);
JsonElement validationValueElement = jsonObject.get(APIConstants.KeyManager.TOKEN_FORMAT_STRING);
if (validationValueElement instanceof JsonPrimitive) {
keyManagerDTO.setTokenValidation(Arrays.asList(new Gson().fromJson(validationValueElement.getAsString(), TokenValidationDTO[].class)));
jsonObject.remove(APIConstants.KeyManager.TOKEN_FORMAT_STRING);
}
if (selfValidateJWTElement != null) {
keyManagerDTO.setEnableSelfValidationJWT(selfValidateJWTElement.getAsBoolean());
}
JsonElement claimMappingElement = jsonObject.get(APIConstants.KeyManager.CLAIM_MAPPING);
if (claimMappingElement != null) {
keyManagerDTO.setClaimMapping(Arrays.asList(new Gson().fromJson(claimMappingElement, ClaimMappingEntryDTO[].class)));
jsonObject.remove(APIConstants.KeyManager.CLAIM_MAPPING);
}
JsonElement scopeClaimKey = jsonObject.get(APIConstants.KeyManager.SCOPES_CLAIM);
if (scopeClaimKey != null) {
keyManagerDTO.setScopesClaim(scopeClaimKey.getAsString());
jsonObject.remove(APIConstants.KeyManager.SCOPES_CLAIM);
}
JsonElement consumerKeyClaim = jsonObject.get(APIConstants.KeyManager.CONSUMER_KEY_CLAIM);
if (scopeClaimKey != null) {
keyManagerDTO.setConsumerKeyClaim(consumerKeyClaim.getAsString());
jsonObject.remove(APIConstants.KeyManager.CONSUMER_KEY_CLAIM);
}
keyManagerDTO.setAdditionalProperties(new Gson().fromJson(jsonObject, Map.class));
return keyManagerDTO;
}
use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto in project carbon-apimgt by wso2.
the class KeymanagersApiServiceImpl method keymanagersGet.
public Response keymanagersGet(String xWSO2Tenant, MessageContext messageContext) {
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
try {
APIAdmin apiAdmin = new APIAdminImpl();
List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiAdmin.getKeyManagerConfigurationsByOrganization(xWSO2Tenant);
List<KeyManagerDTO> keyManagerDTOList = new ArrayList<>();
for (KeyManagerConfigurationDTO keyManagerConfiguration : keyManagerConfigurations) {
keyManagerDTOList.add(toKeyManagerDTO(xWSO2Tenant, keyManagerConfiguration));
}
return Response.ok(keyManagerDTOList).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving key manager configurations", e, log);
}
return null;
}
Aggregations