Search in sources :

Example 1 with PropertyDTO

use of org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO in project carbon-identity-framework by wso2.

the class AbstractUserStoreDAO method getUserStoreProperty.

private UserStoreDTO getUserStoreProperty(UserStoreDTO userStoreDTO) throws IdentityUserStoreMgtException {
    boolean newState = userStoreDTO.getDisabled();
    UserStoreDTO userStoreDTOTemp = getUserStore(userStoreDTO.getDomainId());
    if (userStoreDTOTemp != null) {
        userStoreDTO = userStoreDTOTemp;
        userStoreDTO.setDisabled(newState);
        PropertyDTO[] propertyDTO = userStoreDTO.getProperties();
        for (PropertyDTO propertyDTOValue : propertyDTO) {
            if (propertyDTOValue.getName().equals(DISABLED)) {
                propertyDTOValue.setValue(String.valueOf(newState));
            }
        }
    }
    return userStoreDTO;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)

Example 2 with PropertyDTO

use of org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO in project carbon-identity-framework by wso2.

the class SecondaryUserStoreConfigurationUtil method addProperties.

/**
 * Adds an array of properties
 *
 * @param propertyDTOs List of user store properties
 * @param doc          Document
 * @param parent       Parent element of the properties to be added
 */
private static void addProperties(String userStoreDomain, String userStoreClass, PropertyDTO[] propertyDTOs, Document doc, Element parent, boolean editSecondaryUserStore) throws IdentityUserStoreMgtException {
    if (editSecondaryUserStore) {
        String uniqueID = getUniqueIDFromUserDTO(propertyDTOs);
        if (uniqueID == null) {
            throw new IdentityUserStoreMgtException("UniqueID property is not provided.");
        }
    }
    // First check for mandatory field with #encrypt
    Property[] mandatoryProperties = getMandatoryProperties(userStoreClass);
    Map<String, String> secondaryUserStoreProperties = getSecondaryUserStorePropertiesFromTenantUserRealm(userStoreDomain);
    for (PropertyDTO propertyDTO : propertyDTOs) {
        String propertyDTOName = propertyDTO.getName();
        if (UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT.equalsIgnoreCase(propertyDTOName)) {
            continue;
        }
        String propertyDTOValue = propertyDTO.getValue();
        if (propertyDTOValue != null) {
            boolean encrypted = false;
            if (isPropertyToBeEncrypted(mandatoryProperties, propertyDTOName)) {
                propertyDTOValue = getPropertyValueIfMasked(secondaryUserStoreProperties, propertyDTOName, propertyDTOValue);
                try {
                    propertyDTOValue = SecondaryUserStoreConfigurationUtil.encryptPlainText(propertyDTOValue);
                    encrypted = true;
                } catch (IdentityUserStoreMgtException e) {
                    LOG.error("addProperties failed to encrypt", e);
                // its ok to continue from here
                }
            }
            addProperty(propertyDTOName, propertyDTOValue, doc, parent, encrypted);
        }
    }
}
Also used : MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty) Property(org.wso2.carbon.user.api.Property) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)

Example 3 with PropertyDTO

use of org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO 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)

Example 4 with PropertyDTO

use of org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO in project carbon-identity-framework by wso2.

the class PolicyPublisher method populateProperties.

private void populateProperties(PublisherDataHolder holder, PublisherDataHolder oldHolder, Resource resource) {
    PublisherPropertyDTO[] propertyDTOs = holder.getPropertyDTOs();
    for (PublisherPropertyDTO dto : propertyDTOs) {
        if (dto.getId() != null && dto.getValue() != null && dto.getValue().trim().length() > 0) {
            ArrayList<String> list = new ArrayList<String>();
            if (dto.isSecret()) {
                PublisherPropertyDTO propertyDTO = null;
                if (oldHolder != null) {
                    propertyDTO = oldHolder.getPropertyDTO(dto.getId());
                }
                if (propertyDTO == null || !propertyDTO.getValue().equalsIgnoreCase(dto.getValue())) {
                    try {
                        String encryptedValue = CryptoUtil.getDefaultCryptoUtil().encryptAndBase64Encode(dto.getValue().getBytes());
                        dto.setValue(encryptedValue);
                    } catch (CryptoException e) {
                        log.error("Error while encrypting secret value of subscriber. " + "Secret would not be persist.", e);
                        continue;
                    }
                }
            }
            list.add(dto.getValue());
            list.add(dto.getDisplayName());
            list.add(Integer.toString(dto.getDisplayOrder()));
            list.add(Boolean.toString(dto.isRequired()));
            list.add(Boolean.toString(dto.isSecret()));
            resource.setProperty(dto.getId(), list);
        }
    }
    resource.setProperty(PublisherDataHolder.MODULE_NAME, holder.getModuleName());
}
Also used : ArrayList(java.util.ArrayList) PublisherPropertyDTO(org.wso2.carbon.identity.entitlement.dto.PublisherPropertyDTO) CryptoException(org.wso2.carbon.core.util.CryptoException)

Example 5 with PropertyDTO

use of org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO in project identity-governance by wso2-extensions.

the class LiteApiServiceImpl method litePost.

@Override
public Response litePost(LiteUserRegistrationRequestDTO liteUserRegistrationRequestDTO) {
    // reject if username is not present.
    if (liteUserRegistrationRequestDTO == null || (StringUtils.isBlank(liteUserRegistrationRequestDTO.getEmail()) && StringUtils.isBlank(liteUserRegistrationRequestDTO.getMobile()))) {
        Utils.handleBadRequest(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getMessage(), IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_BAD_LITE_REGISTER_REQUEST.getCode());
    }
    String tenantFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    List<PropertyDTO> properties = new ArrayList<>();
    User user = new User();
    user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    user.setUserStoreDomain(IdentityUtil.getPrimaryDomainName());
    user.setUserName(liteUserRegistrationRequestDTO.getEmail());
    PropertyDTO propertyDTO = new PropertyDTO();
    propertyDTO.setKey(IdentityRecoveryConstants.IS_LITE_SIGN_UP);
    propertyDTO.setValue("true");
    properties.add(propertyDTO);
    if (StringUtils.isNotBlank(liteUserRegistrationRequestDTO.getRealm())) {
        user.setUserStoreDomain(liteUserRegistrationRequestDTO.getRealm());
    }
    if (StringUtils.isNotBlank(tenantFromContext)) {
        user.setTenantDomain(tenantFromContext);
    }
    UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
    NotificationResponseBean notificationResponseBean = null;
    properties.addAll(liteUserRegistrationRequestDTO.getProperties());
    try {
        notificationResponseBean = userSelfRegistrationManager.registerLiteUser(user, Utils.getClaims(liteUserRegistrationRequestDTO.getClaims()), Utils.getProperties(properties));
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while self registering lite user ", e);
        }
        if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            Utils.handleConflict(e.getMessage(), e.getErrorCode());
        } else {
            Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
        }
    } catch (IdentityRecoveryException e) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return buildSuccessfulAPIResponse(notificationResponseBean);
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) NotificationResponseBean(org.wso2.carbon.identity.recovery.bean.NotificationResponseBean) UserSelfRegistrationManager(org.wso2.carbon.identity.recovery.signup.UserSelfRegistrationManager) ArrayList(java.util.ArrayList) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Aggregations

ArrayList (java.util.ArrayList)23 PropertyDTO (org.wso2.carbon.identity.user.endpoint.dto.PropertyDTO)18 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)10 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.PropertyDTO)10 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO)9 File (java.io.File)7 Test (org.testng.annotations.Test)7 H2DataBaseManager (org.wso2.carbon.automation.test.utils.dbutils.H2DataBaseManager)6 ResendCodeRequestDTO (org.wso2.carbon.identity.user.endpoint.dto.ResendCodeRequestDTO)6 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)6 Property (org.wso2.carbon.user.api.Property)5 AddUserStorePropertiesRes (org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes)3 PropertyDTO (org.wso2.carbon.identity.recovery.endpoint.dto.PropertyDTO)3 ErrorDTO (org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO)3 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)3 JDBCUserStoreManager (org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager)3 PublisherDataHolder (org.wso2.carbon.identity.entitlement.stub.dto.PublisherDataHolder)2 PublisherPropertyDTO (org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO)2 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)2 NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)2