Search in sources :

Example 6 with KeyManagerInfoDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerInfoDTO in project carbon-apimgt by wso2.

the class KeyManagerMappingUtil method toKeyManagerListDto.

public static KeyManagerListDTO toKeyManagerListDto(List<KeyManagerConfigurationDTO> keyManagerConfigurations) {
    KeyManagerListDTO keyManagerListDTO = new KeyManagerListDTO();
    List<KeyManagerInfoDTO> keyManagerInfoDTOList = new ArrayList<>();
    for (KeyManagerConfigurationDTO keyManagerConfigurationDTO : keyManagerConfigurations) {
        keyManagerInfoDTOList.add(fromKeyManagerConfigurationDtoToKeyManagerInfoDto(keyManagerConfigurationDTO));
    }
    keyManagerListDTO.setList(keyManagerInfoDTOList);
    keyManagerListDTO.setCount(keyManagerInfoDTOList.size());
    return keyManagerListDTO;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) KeyManagerListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerListDTO) ArrayList(java.util.ArrayList) KeyManagerInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerInfoDTO)

Example 7 with KeyManagerInfoDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerInfoDTO in project carbon-apimgt by wso2.

the class KeyManagerMappingUtil method fromKeyManagerConfigurationDtoToKeyManagerInfoDto.

public static KeyManagerInfoDTO fromKeyManagerConfigurationDtoToKeyManagerInfoDto(KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
    KeyManagerInfoDTO keyManagerInfoDTO = new KeyManagerInfoDTO();
    keyManagerInfoDTO.setId(keyManagerConfigurationDTO.getUuid());
    keyManagerInfoDTO.setName(keyManagerConfigurationDTO.getName());
    keyManagerInfoDTO.setDescription(keyManagerConfigurationDTO.getDescription());
    keyManagerInfoDTO.setDisplayName(keyManagerConfigurationDTO.getDisplayName());
    keyManagerInfoDTO.setEnabled(keyManagerConfigurationDTO.isEnabled());
    keyManagerInfoDTO.setType(keyManagerConfigurationDTO.getType());
    keyManagerInfoDTO.setAlias(keyManagerConfigurationDTO.getAlias());
    keyManagerInfoDTO.setTokenType(KeyManagerInfoDTO.TokenTypeEnum.valueOf(keyManagerConfigurationDTO.getTokenType()));
    JsonObject jsonObject = fromConfigurationMapToJson(keyManagerConfigurationDTO.getAdditionalProperties());
    JsonElement grantTypesElement = jsonObject.get(APIConstants.KeyManager.AVAILABLE_GRANT_TYPE);
    if (grantTypesElement instanceof JsonArray) {
        keyManagerInfoDTO.setAvailableGrantTypes(new Gson().fromJson(grantTypesElement, List.class));
    }
    if (jsonObject.has(APIConstants.KeyManager.ENABLE_OAUTH_APP_CREATION)) {
        keyManagerInfoDTO.setEnableOAuthAppCreation(jsonObject.get(APIConstants.KeyManager.ENABLE_OAUTH_APP_CREATION).getAsBoolean());
    }
    if (jsonObject.has(APIConstants.KeyManager.ENABLE_TOKEN_GENERATION)) {
        keyManagerInfoDTO.setEnableTokenGeneration(jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_GENERATION).getAsBoolean());
    }
    if (jsonObject.has(APIConstants.KeyManager.ENABLE_MAP_OAUTH_CONSUMER_APPS)) {
        keyManagerInfoDTO.setEnableMapOAuthConsumerApps(jsonObject.get(APIConstants.KeyManager.ENABLE_MAP_OAUTH_CONSUMER_APPS).getAsBoolean());
    }
    if (jsonObject.has(APIConstants.KeyManager.ENABLE_TOKEN_ENCRYPTION)) {
        keyManagerInfoDTO.setEnableTokenEncryption(jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_ENCRYPTION).getAsBoolean());
    }
    if (jsonObject.has(APIConstants.KeyManager.ENABLE_TOKEN_HASH)) {
        keyManagerInfoDTO.setEnableTokenHashing(jsonObject.get(APIConstants.KeyManager.ENABLE_TOKEN_HASH).getAsBoolean());
    }
    if (jsonObject.has(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT) && !jsonObject.get(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT).isJsonNull() && !jsonObject.get(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT).getAsString().trim().isEmpty()) {
        keyManagerInfoDTO.setTokenEndpoint(jsonObject.get(APIConstants.KeyManager.DISPLAY_TOKEN_ENDPOINT).getAsString());
    } else {
        if (jsonObject.has(APIConstants.KeyManager.TOKEN_ENDPOINT)) {
            keyManagerInfoDTO.setTokenEndpoint(jsonObject.get(APIConstants.KeyManager.TOKEN_ENDPOINT).getAsString());
        }
    }
    if (jsonObject.has(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT) && !jsonObject.get(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT).isJsonNull() && !jsonObject.get(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT).getAsString().trim().isEmpty()) {
        keyManagerInfoDTO.setRevokeEndpoint(jsonObject.get(APIConstants.KeyManager.DISPLAY_REVOKE_ENDPOINT).getAsString());
    } else {
        if (jsonObject.has(APIConstants.KeyManager.REVOKE_ENDPOINT)) {
            keyManagerInfoDTO.setRevokeEndpoint(jsonObject.get(APIConstants.KeyManager.REVOKE_ENDPOINT).getAsString());
        }
    }
    Map<String, String> additionalProperties = new HashMap<>();
    if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.PRODUCTION_TOKEN_ENDPOINT)) {
        additionalProperties.put(APIConstants.KeyManager.PRODUCTION_TOKEN_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.PRODUCTION_TOKEN_ENDPOINT));
    }
    if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.PRODUCTION_REVOKE_ENDPOINT)) {
        additionalProperties.put(APIConstants.KeyManager.PRODUCTION_REVOKE_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.PRODUCTION_REVOKE_ENDPOINT));
    }
    if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.SANDBOX_TOKEN_ENDPOINT)) {
        additionalProperties.put(APIConstants.KeyManager.SANDBOX_TOKEN_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.SANDBOX_TOKEN_ENDPOINT));
    }
    if (keyManagerConfigurationDTO.getAdditionalProperties().containsKey(APIConstants.KeyManager.SANDBOX_REVOKE_ENDPOINT)) {
        additionalProperties.put(APIConstants.KeyManager.SANDBOX_REVOKE_ENDPOINT, (String) keyManagerConfigurationDTO.getAdditionalProperties().get(APIConstants.KeyManager.SANDBOX_REVOKE_ENDPOINT));
    }
    keyManagerInfoDTO.setAdditionalProperties(additionalProperties);
    keyManagerInfoDTO.setApplicationConfiguration(fromKeyManagerConfigurationDto(keyManagerConfigurationDTO.getType()));
    return keyManagerInfoDTO;
}
Also used : JsonArray(com.google.gson.JsonArray) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ArrayList(java.util.ArrayList) List(java.util.List) KeyManagerInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.KeyManagerInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)4 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)3 KeyManagerInfoDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerInfoDTO)2 KeyManagerInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerInfoDTO)2 KeyManagerInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.KeyManagerInfoDTO)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 List (java.util.List)1 KeyManagerListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerListDTO)1 CredentialsDTO (org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO)1 KeyManagerInfoDTO (org.wso2.carbon.apimgt.rest.api.core.dto.KeyManagerInfoDTO)1 KeyManagerListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerListDTO)1 KeyManagerListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.KeyManagerListDTO)1