Search in sources :

Example 1 with KeyManagerDto

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);
    }
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Gson(com.google.gson.Gson) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 2 with KeyManagerDto

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);
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) KeyManagerDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 3 with KeyManagerDto

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;
}
Also used : KeyManagerCertificatesDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerCertificatesDTO) KeyManagerWellKnownResponseDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO) KeyManagerDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO)

Example 4 with KeyManagerDto

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;
}
Also used : JsonArray(com.google.gson.JsonArray) KeyManagerCertificatesDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerCertificatesDTO) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) TokenValidationDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.TokenValidationDTO) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) KeyManagerDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ClaimMappingEntryDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ClaimMappingEntryDTO)

Example 5 with 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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) ArrayList(java.util.ArrayList) KeyManagerDTO(org.wso2.carbon.apimgt.internal.service.dto.KeyManagerDTO) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Aggregations

KeyManagerDto (org.wso2.carbon.apimgt.impl.dto.KeyManagerDto)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)15 HashMap (java.util.HashMap)13 Map (java.util.Map)13 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)13 TreeMap (java.util.TreeMap)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)5 Gson (com.google.gson.Gson)4 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)4 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)4 JsonObject (com.google.gson.JsonObject)3 ArrayList (java.util.ArrayList)3 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3 Scope (org.wso2.carbon.apimgt.api.model.Scope)3 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)3 KeyManagerDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO)3 JsonArray (com.google.gson.JsonArray)2 HashSet (java.util.HashSet)2 List (java.util.List)2