Search in sources :

Example 1 with HashProviderFactory

use of org.wso2.carbon.user.core.hash.HashProviderFactory in project carbon-identity-framework by wso2.

the class UserStoreHashProviderConfigListenerImpl method validateHashProviderParams.

/**
 * Derive the userStoreProperties from UserStoreDTO and Validating HashProvider params.
 *
 * @param userStoreDTO Data transfer object of userStore properties.
 * @throws UserStoreException The exception thrown at validating the hashProvider params.
 */
private void validateHashProviderParams(UserStoreDTO userStoreDTO) throws UserStoreException {
    PropertyDTO[] userStoreProperty = userStoreDTO.getProperties();
    String userstoreDomainId = userStoreDTO.getDomainId();
    String digestFunction = null;
    String hashProviderParamsJSON = null;
    if (ArrayUtils.isEmpty(userStoreProperty)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No userstore properties found for userstore: " + userstoreDomainId);
        }
        return;
    }
    for (PropertyDTO propertyDTO : userStoreProperty) {
        if (DIGEST_FUNCTION.equals(propertyDTO.getName())) {
            digestFunction = propertyDTO.getValue();
        }
        if (HASH_PROVIDER_PARAMS_JSON.equals(propertyDTO.getName())) {
            hashProviderParamsJSON = propertyDTO.getValue();
        }
    }
    if (StringUtils.isBlank(hashProviderParamsJSON)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No hash provider configurations found for: " + userstoreDomainId);
        }
        return;
    }
    // Retrieve the corresponding HashProviderFactory for the defined hashing function.
    HashProviderFactory hashProviderFactory = UserStoreConfigListenersHolder.getInstance().getHashProviderFactory(digestFunction);
    if (hashProviderFactory == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("No HashProviderFactory found digest function : %s for userstore: %s", digestFunction, userstoreDomainId));
        }
        return;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("HashProviderFactory: %s found for digest function: %s for userstore: %s", hashProviderFactory.getAlgorithm(), digestFunction, userstoreDomainId));
    }
    Set<String> hashProviderMetaProperties = hashProviderFactory.getHashProviderConfigProperties();
    validateParams(hashProviderParamsJSON, hashProviderMetaProperties);
    Map<String, Object> hashProviderPropertiesMap = getHashProviderInitConfigs(hashProviderParamsJSON);
    try {
        hashProviderFactory.getHashProvider(hashProviderPropertiesMap);
    } catch (HashProviderException e) {
        throw new UserStoreException("Error occurred while initializing the hashProvider.", e);
    }
}
Also used : HashProviderException(org.wso2.carbon.user.core.exceptions.HashProviderException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) HashProviderFactory(org.wso2.carbon.user.core.hash.HashProviderFactory) JsonObject(com.google.gson.JsonObject) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)

Aggregations

JsonObject (com.google.gson.JsonObject)1 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1 HashProviderException (org.wso2.carbon.user.core.exceptions.HashProviderException)1 HashProviderFactory (org.wso2.carbon.user.core.hash.HashProviderFactory)1