Java Code Examples for org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO#getValue()

The following examples show how to use org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the UniqueID ID constant value from the propertyDTO object which was set well
 * before sending the edit request.
 *
 * @param propertyDTOs PropertyDTO[] object passed from JSP page
 * @return unique id string value
 */
private static String getUniqueIDFromUserDTO(PropertyDTO[] propertyDTOs) {

    int length = propertyDTOs.length;
    for (int i = length - 1; i >= 0; i--) {
        PropertyDTO propertyDTO = propertyDTOs[i];
        if (propertyDTO != null && propertyDTO.getName() != null && propertyDTO.getName()
                .equalsIgnoreCase(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT)) {
            return propertyDTO.getValue();
        }
    }

    return null;
}
 
Example 2
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the UniqueID ID constant value from the propertyDTO object which was set well
 * before sending the edit request.
 *
 * @param propertyDTOs PropertyDTO[] object passed from JSP page
 * @return unique id string value
 */
private String getUniqueIDFromUserDTO(PropertyDTO[] propertyDTOs) {

    int length = propertyDTOs.length;
    for (int i = length - 1; i >= 0; i--) {
        PropertyDTO propertyDTO = propertyDTOs[i];
        if (propertyDTO != null && propertyDTO.getName() != null && propertyDTO.getName()
                .equalsIgnoreCase(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT)) {
            return propertyDTO.getValue();
        }
    }

    return null;
}
 
Example 3
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 4
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * 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 void addProperties(String userStoreClass, PropertyDTO[] propertyDTOs, Document doc, Element parent,
                           boolean editSecondaryUserStore) throws IdentityUserStoreMgtException {

    RandomPasswordContainer randomPasswordContainer = null;
    if (editSecondaryUserStore) {
        String uniqueID = getUniqueIDFromUserDTO(propertyDTOs);
        randomPasswordContainer = getAndRemoveRandomPasswordContainer(uniqueID);
        if (randomPasswordContainer == null) {
            String errorMsg = "randomPasswordContainer is null for uniqueID therefore " +
                    "proceeding without encryption=" + uniqueID;
            log.error(errorMsg);//need this error log to further identify the reason for throwing this exception
            throw new IdentityUserStoreMgtException("Longer delay causes the edit operation be to " +
                    "abandoned");
        }
    }
    //First check for mandatory field with #encrypt
    Property[] mandatoryProperties = getMandatoryProperties(userStoreClass);
    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)) {
                if (randomPasswordContainer != null) {
                    RandomPassword randomPassword = getRandomPassword(randomPasswordContainer, propertyDTOName);
                    if (randomPassword != null) {
                        if (propertyDTOValue.equalsIgnoreCase(randomPassword.getRandomPhrase())) {
                            propertyDTOValue = randomPassword.getPassword();
                        }
                    }
                }

                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);
        }
    }
}