org.wso2.carbon.user.api.Property Java Examples

The following examples show how to use org.wso2.carbon.user.api.Property. 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 6 votes vote down vote up
private static MaskedProperty[] getMaskedProperties(String userStoreClass, String maskValue,
                                                    RealmConfiguration secondaryRealmConfiguration) {
    //First check for mandatory field with #encrypt
    Property[] mandatoryProperties = getMandatoryProperties(userStoreClass);
    ArrayList<MaskedProperty> maskedProperties = new ArrayList<>();
    for (Property property : mandatoryProperties) {
        String propertyName = property.getName();
        if (property.getDescription().contains(UserStoreConfigurationConstant.ENCRYPT_TEXT)) {
            MaskedProperty maskedProperty = new MaskedProperty();
            maskedProperty.setName(propertyName);
            maskedProperty.setValue(secondaryRealmConfiguration.getUserStoreProperty(propertyName));
            maskedProperty.setMask(maskValue);
            maskedProperties.add(maskedProperty);
        }
    }
    return maskedProperties.toArray(new MaskedProperty[0]);
}
 
Example #2
Source File: UserStoreConfigurationDeployer.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Get the list of properties from  mandatoryProperties list
 *
 * @param userStoreClass class name of user store
 * @return ArrayList consisting of mandatory properties to be encrypted
 */
private static ArrayList<String> getEncryptPropertyList(String userStoreClass) {
    //First check for mandatory field with #encrypt
    Property[] mandatoryProperties = UserStoreManagerRegistry.getUserStoreProperties(userStoreClass).
            getMandatoryProperties();
    ArrayList<String> propertyList = new ArrayList<String>();
    for (Property property : mandatoryProperties) {
        if (property != null) {
            String propertyName = property.getName();
            if (propertyName != null && property.getDescription().contains
                    (UserStoreConfigurationConstants.ENCRYPT_TEXT)) {
                propertyList.add(propertyName);
            }
        }
    }
    return propertyList;
}
 
Example #3
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Generate the RandomPassword[] from secondaryRealmConfiguration for given userStoreClass
 *
 * @param userStoreClass              Extract the mandatory properties of this class
 * @param randomPhrase                The randomly generated keyword which will be stored in
 *                                    RandomPassword object
 * @param secondaryRealmConfiguration RealmConfiguration object consists the properties
 * @return RandomPassword[] array for each property
 */
private RandomPassword[] getRandomPasswordProperties(String userStoreClass,
                                                     String randomPhrase, RealmConfiguration secondaryRealmConfiguration) {
    //First check for mandatory field with #encrypt
    Property[] mandatoryProperties = getMandatoryProperties(userStoreClass);
    ArrayList<RandomPassword> randomPasswordArrayList = new ArrayList<RandomPassword>();
    for (Property property : mandatoryProperties) {
        String propertyName = property.getName();
        if (property.getDescription().contains(UserStoreConfigurationConstant.ENCRYPT_TEXT)) {
            RandomPassword randomPassword = new RandomPassword();
            randomPassword.setPropertyName(propertyName);
            randomPassword.setPassword(secondaryRealmConfiguration.getUserStoreProperty(propertyName));
            randomPassword.setRandomPhrase(randomPhrase);
            randomPasswordArrayList.add(randomPassword);
        }
    }
    return randomPasswordArrayList.toArray(new RandomPassword[randomPasswordArrayList.size()]);
}
 
Example #4
Source File: UserStoreConfigurationDeployer.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get the list of properties from  mandatoryProperties list
 *
 * @param userStoreClass class name of user store
 * @return ArrayList consisting of mandatory properties to be encrypted
 */
private static ArrayList<String> getEncryptPropertyList(String userStoreClass) {
    //First check for mandatory field with #encrypt
    Property[] mandatoryProperties = UserStoreManagerRegistry.getUserStoreProperties(userStoreClass).
            getMandatoryProperties();
    ArrayList<String> propertyList = new ArrayList<String>();
    for (Property property : mandatoryProperties) {
        if (property != null) {
            String propertyName = property.getName();
            if (propertyName != null && property.getDescription().contains
                    (UserStoreConfigurationConstants.ENCRYPT_TEXT)) {
                propertyList.add(propertyName);
            }
        }
    }
    return propertyList;
}
 
Example #5
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs attributes for individual properties.
 *
 * @param properties Array of user store properties.
 * @return List<Attribute>
 */
private List<Attribute> buildAttributes(Property[] properties) {

    if (ArrayUtils.isEmpty(properties)) {
        return null;
    }

    List<Attribute> attributes = new ArrayList<>();
    for (Property property : properties) {
        Attribute attribute = new Attribute();
        attribute.setName(property.getName());
        attribute.setValue(property.getValue());
        attributes.add(attribute);
    }
    return attributes;
}
 
Example #6
Source File: UserStoreConfigAdminService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get User Store Manager default properties for a given implementation
 *
 * @param className Implementation class name for the user store
 * @return list of default properties(mandatory+optional)
 */
public Properties getUserStoreManagerProperties(String className) throws IdentityUserStoreMgtException {
    Properties properties = UserStoreManagerRegistry.getUserStoreProperties(className);

    if (properties != null && properties.getOptionalProperties() != null) {

        Property[] optionalProperties = properties.getOptionalProperties();
        boolean foundUniqueIDProperty = false;
        for (Property property : optionalProperties) {
            if (UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT.equals(property.getName())) {
                foundUniqueIDProperty = true;
                break;
            }
        }
        if (!foundUniqueIDProperty) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Inserting property : " + UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT +
                          " since " + UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT +
                          " property not defined as an optional property in " + className + " class");
            }
            List<Property> optionalPropertyList = new ArrayList<>(Arrays.asList(optionalProperties));
            Property uniqueIDProperty = new Property(
                    UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, "", "", null);
            optionalPropertyList.add(uniqueIDProperty);

            properties.setOptionalProperties(
                    optionalPropertyList.toArray(new Property[optionalPropertyList.size()]));
        }
    }

    return properties;
}
 
Example #7
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given property should be encrypted or not.
 *
 * @param mandatoryProperties mandatory property array
 * @param propertyName        property name
 * @return returns true if the property should be encrypted
 */
private static boolean isPropertyToBeEncrypted(Property[] mandatoryProperties,
                                               String propertyName) {

    for (Property property : mandatoryProperties) {
        if (propertyName.equalsIgnoreCase(property.getName())) {
            return property.getDescription().contains(UserStoreConfigurationConstant.ENCRYPT_TEXT);
        }
    }
    return false;
}
 
Example #8
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Build user store properties response of created or updated user store.
 *
 * @param userStoreReq {@link UserStoreReq} to insert.
 * @return List<AddUserStorePropertiesRes>.
 */
private List<AddUserStorePropertiesRes> buildUserStorePropertiesRes(UserStoreReq userStoreReq) {

    List<org.wso2.carbon.identity.api.server.userstore.v1.model.Property> values = userStoreReq.getProperties();
    List<AddUserStorePropertiesRes> propertiesToAdd = new ArrayList<>();

    for (org.wso2.carbon.identity.api.server.userstore.v1.model.Property value : values) {
        AddUserStorePropertiesRes addUserStorePropertiesRes = new AddUserStorePropertiesRes();
        addUserStorePropertiesRes.setName(value.getName());
        addUserStorePropertiesRes.setValue(value.getValue());
        propertiesToAdd.add(addUserStorePropertiesRes);
    }
    return propertiesToAdd;
}
 
Example #9
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Construct PropertyDTO array for POST request.
 *
 * @param userStoreReq {@link UserStoreReq}.
 * @return PropertyDTO[].
 */
private PropertyDTO[] createPropertyListDTO(UserStoreReq userStoreReq) {

    List<org.wso2.carbon.identity.api.server.userstore.v1.model.Property> values = userStoreReq.getProperties();
    ArrayList<PropertyDTO> propertiesToAdd = new ArrayList<>();

    for (org.wso2.carbon.identity.api.server.userstore.v1.model.Property value : values) {
        PropertyDTO propertyDTO = new PropertyDTO();
        propertyDTO.setName(value.getName());
        propertyDTO.setValue(value.getValue());
        propertiesToAdd.add(propertyDTO);
    }
    return generatePropertiesWithUniqueIDProperty (propertiesToAdd);
}
 
Example #10
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Get User Store Manager default properties for a given implementation
 *
 * @param className:Implementation class name for the user store
 * @return : list of default properties(mandatory+optional)
 */
public Properties getUserStoreManagerProperties(String className) throws IdentityUserStoreMgtException {
    Properties properties = UserStoreManagerRegistry.getUserStoreProperties(className);

    if (properties != null && properties.getOptionalProperties() != null) {

        Property[] optionalProperties =  properties.getOptionalProperties();

        boolean foundUniqueIDProperty = false;
        for (Property property : optionalProperties) {
            if (UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT.equals(property.getName())) {
                foundUniqueIDProperty = true;
                break;
            }
        }
        if (!foundUniqueIDProperty) {
            if (log.isDebugEnabled()) {
                log.debug("Inserting property : " + UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT +
                        " since " + UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT +
                        " property not defined as an optional property in " + className + " class");
            }
            List<Property> optionalPropertyList = new ArrayList<>(Arrays.asList(optionalProperties));
            Property uniqueIDProperty = new Property(
                    UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, "", "", null);
            optionalPropertyList.add(uniqueIDProperty);

            properties.setOptionalProperties(
                    optionalPropertyList.toArray(new Property[optionalPropertyList.size()]));
        }
    }

    return properties;
}
 
Example #11
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether the given property should be encrypted or not.
 *
 * @param mandatoryProperties mandatory property array
 * @param propertyName        property name
 * @return returns true if the property should be encrypted
 */
private boolean isPropertyToBeEncrypted(Property[] mandatoryProperties,
                                        String propertyName) {
    for (Property property : mandatoryProperties) {
        if (propertyName.equalsIgnoreCase(property.getName())) {
            return property.getDescription().contains(UserStoreConfigurationConstant.ENCRYPT_TEXT);
        }
    }
    return false;
}
 
Example #12
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Construct properties list in the response.
 *
 * @param properties array of user store properties.
 * @return List<PropertiesRes>.
 */
private List<PropertiesRes> buildPropertiesRes(Property[] properties) {

    List<PropertiesRes> propertiesToAdd = new ArrayList<>();

    for (Property property : properties) {
        PropertiesRes propertiesRes = new PropertiesRes();
        propertiesRes.setName(property.getName());
        propertiesRes.setDefaultValue(property.getValue());
        propertiesRes.setDescription(property.getDescription());
        propertiesRes.setAttributes(buildAttributes(property.getChildProperties()));
        propertiesToAdd.add(propertiesRes);
    }
    return propertiesToAdd;
}
 
Example #13
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 #14
Source File: CarbonRemoteUserStoreManger.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 *
 */

@Override
public Properties getDefaultUserStoreProperties() {
    Properties properties = new Properties();
    Property[] mandatoryProperties = null;
    Property[] optionalProperties = null;
    Property remoteServerUserName = new Property(
            REMOTE_USER_NAME,
            "",
            "Remote Sever Username#Name of a user from the remote server, having enough privileges for user management",
            null);
    Property password = new Property(PASSWORD, "",
            "Remote Server Password#The password correspoing to the remote server " +
                    "username#encrypt",
            null);
    Property serverUrls = new Property(
            SERVER_URLS,
            "",
            "Remote Server URL(s)#Remote server URLs. e.g.: https://ca-datacenter/services,https://va-datacenter/services",
            null);
    Property disabled = new Property("Disabled", "false", "Disabled#Check to disable the user store", null);

    Property passwordJavaScriptRegEx = new Property(
            UserStoreConfigConstants.passwordJavaScriptRegEx, "^[\\S]{5,30}$",
            "Password RegEx (Javascript)#"
                    + UserStoreConfigConstants.passwordJavaScriptRegExDescription, null);
    Property usernameJavaScriptRegEx = new Property(
            UserStoreConfigConstants.usernameJavaScriptRegEx, "^[\\S]{3,30}$",
            "Username RegEx (Javascript)#"
                    + UserStoreConfigConstants.usernameJavaRegExDescription, null);
    Property roleNameJavaScriptRegEx = new Property(
            UserStoreConfigConstants.roleNameJavaScriptRegEx, "^[\\S]{3,30}$",
            "Role Name RegEx (Javascript)#"
                    + UserStoreConfigConstants.roleNameJavaScriptRegExDescription, null);

    mandatoryProperties = new Property[] {remoteServerUserName, password, serverUrls, passwordJavaScriptRegEx,
            usernameJavaScriptRegEx, roleNameJavaScriptRegEx};
    optionalProperties = new Property[] {disabled};

    properties.setOptionalProperties(optionalProperties);
    properties.setMandatoryProperties(mandatoryProperties);
    return properties;
}
 
Example #15
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);
        }
    }
}
 
Example #16
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains the mandatory properties for a given userStoreClass
 *
 * @param userStoreClass userStoreClass name
 * @return Property[] of Mandatory Properties
 */
private static Property[] getMandatoryProperties(String userStoreClass) {

    return UserStoreManagerRegistry.getUserStoreProperties(userStoreClass).getMandatoryProperties();
}
 
Example #17
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains the mandatory properties for a given userStoreClass
 *
 * @param userStoreClass userStoreClass name
 * @return Property[] of Mandatory Properties
 */
private Property[] getMandatoryProperties(String userStoreClass) {
    return UserStoreManagerRegistry.getUserStoreProperties(userStoreClass).getMandatoryProperties();
}