Search in sources :

Example 1 with ConfigurationDto

use of org.wso2.carbon.apimgt.api.model.ConfigurationDto in project carbon-apimgt by wso2.

the class AbstractKeyManager method validateOAuthAppCreationProperties.

protected void validateOAuthAppCreationProperties(OAuthApplicationInfo oAuthApplicationInfo) throws APIManagementException {
    String type = getType();
    List<String> missedRequiredValues = new ArrayList<>();
    KeyManagerConnectorConfiguration keyManagerConnectorConfiguration = ServiceReferenceHolder.getInstance().getKeyManagerConnectorConfiguration(type);
    if (keyManagerConnectorConfiguration != null) {
        List<ConfigurationDto> applicationConfigurationDtoList = keyManagerConnectorConfiguration.getApplicationConfigurations();
        Object additionalProperties = oAuthApplicationInfo.getParameter(APIConstants.JSON_ADDITIONAL_PROPERTIES);
        try {
            if (additionalProperties != null) {
                JSONObject additionalPropertiesJson;
                if (additionalProperties instanceof JSONObject) {
                    additionalPropertiesJson = (JSONObject) additionalProperties;
                } else {
                    additionalPropertiesJson = (JSONObject) new JSONParser().parse((String) additionalProperties);
                }
                for (ConfigurationDto configurationDto : applicationConfigurationDtoList) {
                    Object value = additionalPropertiesJson.get(configurationDto.getName());
                    if (value == null) {
                        if (configurationDto.isRequired()) {
                            missedRequiredValues.add(configurationDto.getName());
                        }
                    }
                }
                if (!missedRequiredValues.isEmpty()) {
                    throw new APIManagementException("Missing required properties to create/update oauth " + "application", ExceptionCodes.KEY_MANAGER_MISSING_REQUIRED_PROPERTIES_IN_APPLICATION);
                }
            }
        } catch (ParseException e) {
            throw new APIManagementException("Error while parsing the addition properties of OAuth " + "application");
        }
    } else {
        throw new APIManagementException("Invalid Key Manager Type " + type, ExceptionCodes.KEY_MANAGER_NOT_REGISTERED);
    }
}
Also used : KeyManagerConnectorConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration) ConfigurationDto(org.wso2.carbon.apimgt.api.model.ConfigurationDto) JSONObject(org.json.simple.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 2 with ConfigurationDto

use of org.wso2.carbon.apimgt.api.model.ConfigurationDto in project carbon-apimgt by wso2.

the class KeyManagerMappingUtil method fromKeyManagerConfigurationDtoToKeyManagerInfoDto.

private static KeyManagerInfoDTO fromKeyManagerConfigurationDtoToKeyManagerInfoDto(KeyManagerConfigurationDTO configurationDto) {
    KeyManagerInfoDTO keyManagerInfoDTO = new KeyManagerInfoDTO();
    keyManagerInfoDTO.setName(configurationDto.getName());
    keyManagerInfoDTO.setDisplayName(configurationDto.getDisplayName());
    keyManagerInfoDTO.setDescription(configurationDto.getDescription());
    keyManagerInfoDTO.setId(configurationDto.getUuid());
    keyManagerInfoDTO.setEnabled(configurationDto.isEnabled());
    keyManagerInfoDTO.setType(configurationDto.getType());
    return keyManagerInfoDTO;
}
Also used : KeyManagerInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerInfoDTO)

Example 3 with ConfigurationDto

use of org.wso2.carbon.apimgt.api.model.ConfigurationDto in project carbon-apimgt by wso2.

the class AbstractKeyManagerConnectorConfiguration method convertJsonToConnectorConfiguration.

private void convertJsonToConnectorConfiguration() {
    configListMap.put(CONNECTOR_CONFIGURATION, Collections.emptyList());
    configListMap.put(APPLICATION_CONFIGURATIONS, Collections.EMPTY_LIST);
    String connectorConfigPath = CarbonBaseUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "keyManager-extensions" + File.separator + getType() + ".json";
    File file = new File(connectorConfigPath);
    if (file.exists()) {
        try (FileInputStream fileInputStream = new FileInputStream(file)) {
            String content = IOUtils.toString(fileInputStream);
            Gson gson = new Gson();
            Type configurationDtoType = new TypeToken<Map<String, List<ConfigurationDto>>>() {
            }.getType();
            configListMap = gson.fromJson(content, configurationDtoType);
        } catch (IOException e) {
            log.error("Error while reading connector configuration", e);
        }
    }
}
Also used : Type(java.lang.reflect.Type) ConfigurationDto(org.wso2.carbon.apimgt.api.model.ConfigurationDto) Gson(com.google.gson.Gson) IOException(java.io.IOException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 4 with ConfigurationDto

use of org.wso2.carbon.apimgt.api.model.ConfigurationDto in project carbon-apimgt by wso2.

the class DefaultKeyManagerConnectorConfiguration method getApplicationConfigurations.

@Override
public List<ConfigurationDto> getApplicationConfigurations() {
    List<ConfigurationDto> applicationConfigurationsList = new ArrayList();
    applicationConfigurationsList.add(new ConfigurationDto(APIConstants.KeyManager.APPLICATION_ACCESS_TOKEN_EXPIRY_TIME, "Application Access Token Expiry Time ", "input", "Type Application Access Token Expiry Time " + "in seconds ", APIConstants.KeyManager.NOT_APPLICABLE_VALUE, false, false, Collections.EMPTY_LIST, false));
    applicationConfigurationsList.add(new ConfigurationDto(APIConstants.KeyManager.USER_ACCESS_TOKEN_EXPIRY_TIME, "User Access Token Expiry Time ", "input", "Type User Access Token Expiry Time " + "in seconds ", APIConstants.KeyManager.NOT_APPLICABLE_VALUE, false, false, Collections.EMPTY_LIST, false));
    applicationConfigurationsList.add(new ConfigurationDto(APIConstants.KeyManager.REFRESH_TOKEN_EXPIRY_TIME, "Refresh Token Expiry Time ", "input", "Type Refresh Token Expiry Time " + "in seconds ", APIConstants.KeyManager.NOT_APPLICABLE_VALUE, false, false, Collections.EMPTY_LIST, false));
    applicationConfigurationsList.add(new ConfigurationDto(APIConstants.KeyManager.ID_TOKEN_EXPIRY_TIME, "Id Token Expiry Time", "input", "Type ID Token Expiry Time " + "in seconds ", APIConstants.KeyManager.NOT_APPLICABLE_VALUE, false, false, Collections.EMPTY_LIST, false));
    ConfigurationDto configurationDtoPkceMandatory = new ConfigurationDto(APIConstants.KeyManager.PKCE_MANDATORY, "Enable PKCE", "checkbox", "Enable PKCE", String.valueOf(false), false, false, Collections.EMPTY_LIST, false);
    applicationConfigurationsList.add(configurationDtoPkceMandatory);
    ConfigurationDto configurationDtoPkcePlainText = new ConfigurationDto(APIConstants.KeyManager.PKCE_SUPPORT_PLAIN, "Support PKCE Plain text", "checkbox", "S256 is recommended, plain text too can be used.", String.valueOf(false), false, false, Collections.EMPTY_LIST, false);
    applicationConfigurationsList.add(configurationDtoPkcePlainText);
    ConfigurationDto configurationDtoBypassClientCredentials = new ConfigurationDto(APIConstants.KeyManager.BYPASS_CLIENT_CREDENTIALS, "Public client", "checkbox", "Allow authentication without the client secret.", String.valueOf(false), false, false, Collections.EMPTY_LIST, false);
    applicationConfigurationsList.add(configurationDtoBypassClientCredentials);
    return applicationConfigurationsList;
}
Also used : ConfigurationDto(org.wso2.carbon.apimgt.api.model.ConfigurationDto) ArrayList(java.util.ArrayList)

Example 5 with ConfigurationDto

use of org.wso2.carbon.apimgt.api.model.ConfigurationDto in project carbon-apimgt by wso2.

the class APIAdminImpl method encryptKeyManagerConfigurationValues.

private void encryptKeyManagerConfigurationValues(KeyManagerConfigurationDTO retrievedKeyManagerConfigurationDTO, KeyManagerConfigurationDTO updatedKeyManagerConfigurationDto) throws APIManagementException {
    KeyManagerConnectorConfiguration keyManagerConnectorConfiguration = ServiceReferenceHolder.getInstance().getKeyManagerConnectorConfiguration(updatedKeyManagerConfigurationDto.getType());
    if (keyManagerConnectorConfiguration != null) {
        Map<String, Object> additionalProperties = updatedKeyManagerConfigurationDto.getAdditionalProperties();
        for (ConfigurationDto configurationDto : keyManagerConnectorConfiguration.getConnectionConfigurations()) {
            if (configurationDto.isMask()) {
                String value = (String) additionalProperties.get(configurationDto.getName());
                if (APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD.equals(value)) {
                    Object unModifiedValue = retrievedKeyManagerConfigurationDTO.getAdditionalProperties().get(configurationDto.getName());
                    additionalProperties.replace(configurationDto.getName(), unModifiedValue);
                } else if (StringUtils.isNotEmpty(value)) {
                    additionalProperties.replace(configurationDto.getName(), encryptValues(value));
                }
            }
        }
    }
}
Also used : KeyManagerConnectorConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration) ConfigurationDto(org.wso2.carbon.apimgt.api.model.ConfigurationDto) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.simple.JSONObject)

Aggregations

ConfigurationDto (org.wso2.carbon.apimgt.api.model.ConfigurationDto)8 KeyManagerConnectorConfiguration (org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration)5 JsonObject (com.google.gson.JsonObject)4 JSONObject (org.json.simple.JSONObject)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 Map (java.util.Map)1 JSONParser (org.json.simple.parser.JSONParser)1 ParseException (org.json.simple.parser.ParseException)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerConfigurationDTO)1 SettingsKeyManagerConfigurationDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.SettingsKeyManagerConfigurationDTO)1 KeyManagerInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.KeyManagerInfoDTO)1 KeyManagerApplicationConfigurationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.KeyManagerApplicationConfigurationDTO)1