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

The following examples show how to use org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO#setProperties() . 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: DatabaseBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private UserStoreDTO getUserStoreDTO(RealmConfiguration realmConfiguration) {

        Map<String, String> userStoreProperties = realmConfiguration.getUserStoreProperties();

        String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
        if (uuid == null) {
            uuid = UUID.randomUUID().toString();
        }

        String className = realmConfiguration.getUserStoreClass();
        UserStoreDTO userStoreDTO = getUserStoreDTO(realmConfiguration, userStoreProperties);
        userStoreProperties.put("Class", className);
        userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
        MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(realmConfiguration,
                userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);

        userStoreDTO.setProperties(convertMapToArray(userStoreProperties));

        // Now revert back to original password.
        for (MaskedProperty maskedProperty : maskedProperties) {
            userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
        }

        return userStoreDTO;
    }
 
Example 2
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * To handle the patch REPLACE request.
 *
 * @param domainId user store domain id.
 * @param path     patch operation path
 * @param value    property value
 * @return UserStoreResponse
 */
private UserStoreResponse performPatchReplace(String domainId, String path, String value) {

    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance()
            .getUserStoreConfigService();
    try {
        UserStoreDTO userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
        if (userStoreDTO == null) {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.ERROR_CODE_NOT_FOUND);
        }
        if (StringUtils.isBlank(path)) {
            throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage
                    .ERROR_CODE_INVALID_INPUT);
        }
        PropertyDTO[] propertyDTOS = userStoreDTO.getProperties();
        if (path.startsWith(UserStoreConstants.USER_STORE_PROPERTIES)) {
            String[] propertiesList = path.split("/");
            for (PropertyDTO propertyDTO : propertyDTOS) {
                if (propertiesList[2].equals(propertyDTO.getName())) {
                    propertyDTO.setValue(value);
                }
            }
        } else if (path.equals(UserStoreConstants.USER_STORE_DESCRIPTION)) {
            userStoreDTO.setDescription(value);
        } else {
            throw handleException(Response.Status.BAD_REQUEST, UserStoreConstants.ErrorMessage
                    .ERROR_CODE_INVALID_INPUT);
        }
        userStoreDTO.setProperties(propertyDTOS);
        userStoreConfigService.updateUserStore(userStoreDTO, false);
        return buildResponseForPatchReplace(userStoreDTO, propertyDTOS);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum =
                UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
 
Example 3
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * To create UserStoreDTO object for this request.
 *
 * @param userStoreReq {@link UserStoreReq}.
 * @return UserStoreDTO.
 */
private UserStoreDTO createUserStoreDTO(UserStoreReq userStoreReq) {

    UserStoreDTO userStoreDTO = new UserStoreDTO();
    userStoreDTO.setDomainId(userStoreReq.getName());
    userStoreDTO.setClassName(getUserStoreType(base64URLDecodeId(userStoreReq.getTypeId())));
    userStoreDTO.setDescription(userStoreReq.getDescription());
    userStoreDTO.setProperties(createPropertyListDTO(userStoreReq));
    return userStoreDTO;
}
 
Example 4
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public UserStoreDTO[] getUserStores() throws IdentityUserStoreMgtException {

    RealmConfiguration secondaryRealmConfiguration;
    List<UserStoreDTO> domains = new ArrayList<>();
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
                getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    if (secondaryRealmConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("SecondaryRealmConfiguration is null. Can not find any userStore.");
        }
        return new UserStoreDTO[0];
    } else {
        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();
            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }
            String className = secondaryRealmConfiguration.getUserStoreClass();
            UserStoreDTO userStoreDTO = getUserStoreDTO(secondaryRealmConfiguration, userStoreProperties);
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(secondaryRealmConfiguration,
                    userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));
            // Now revert back to original password.
            for (MaskedProperty maskedProperty : maskedProperties) {
                userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
            }
            domains.add(userStoreDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
        } while (secondaryRealmConfiguration != null);
    }
    return domains.toArray(new UserStoreDTO[domains.size()]);
}
 
Example 5
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
protected UserStorePersistanceDTO[] doGetAllUserStores() throws IdentityUserStoreMgtException {

    RealmConfiguration secondaryRealmConfiguration;
    List<UserStorePersistanceDTO> userStorePersistanceDAOList = new ArrayList<>();
    UserStorePersistanceDTO userStorePersistanceDTO = new UserStorePersistanceDTO();
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
                getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    if (secondaryRealmConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("SecondaryRealmConfiguration is null. Can not find any userStore.");
        }
        return new UserStorePersistanceDTO[0];
    } else {
        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();

            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }
            String className = secondaryRealmConfiguration.getUserStoreClass();
            UserStoreDTO userStoreDTO = getUserStoreDTO(secondaryRealmConfiguration, userStoreProperties);
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(secondaryRealmConfiguration,
                    userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));

            // Now revert back to original password.
            for (MaskedProperty maskedProperty : maskedProperties) {
                userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
            }
            userStorePersistanceDTO.setUserStoreDTO(userStoreDTO);
            userStorePersistanceDAOList.add(userStorePersistanceDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();

        } while (secondaryRealmConfiguration != null);
    }
    return userStorePersistanceDAOList.toArray(new UserStorePersistanceDTO[userStorePersistanceDAOList.size()]);
}
 
Example 6
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Get details of current secondary user store configurations
 *
 * @return : Details of all the configured secondary user stores
 * @throws UserStoreException
 */
public UserStoreDTO[] getSecondaryRealmConfigurations() throws IdentityUserStoreMgtException {
    ArrayList<UserStoreDTO> domains = new ArrayList<UserStoreDTO>();

    RealmConfiguration secondaryRealmConfiguration = null;
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
                getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        log.error(errorMessage, e);
        throw new IdentityUserStoreMgtException(errorMessage);
    }

    //not editing primary store
    if (secondaryRealmConfiguration == null) {
        return null;
    } else {

        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();
            UserStoreDTO userStoreDTO = new UserStoreDTO();

            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }

            String randomPhrase = UserStoreConfigurationConstant.RANDOM_PHRASE_PREFIX + uuid;
            String className = secondaryRealmConfiguration.getUserStoreClass();
            userStoreDTO.setClassName(secondaryRealmConfiguration.getUserStoreClass());
            userStoreDTO.setDescription(secondaryRealmConfiguration.getUserStoreProperty(DESCRIPTION));
            userStoreDTO.setDomainId(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigConstants.DOMAIN_NAME));
            if (userStoreProperties.get(DISABLED) != null) {
                userStoreDTO.setDisabled(Boolean.valueOf(userStoreProperties.get(DISABLED)));
            }
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            RandomPassword[] randomPasswords = getRandomPasswordProperties(className, randomPhrase,
                    secondaryRealmConfiguration);
            if (randomPasswords != null) {
                updatePasswordContainer(randomPasswords, uuid);
            }

            String originalPassword = null;
            if (userStoreProperties.containsKey(UserStoreConfigConstants.connectionPassword)) {
                originalPassword = userStoreProperties.get(UserStoreConfigConstants.connectionPassword);
                userStoreProperties.put(UserStoreConfigConstants.connectionPassword, randomPhrase);
            }
            if (userStoreProperties.containsKey(JDBCRealmConstants.PASSWORD)) {
                originalPassword = userStoreProperties.get(JDBCRealmConstants.PASSWORD);
                userStoreProperties.put(JDBCRealmConstants.PASSWORD, randomPhrase);
            }
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));

            //Now revert back to original password
            if (userStoreProperties.containsKey(UserStoreConfigConstants.connectionPassword)) {
                if (originalPassword != null) {
                    userStoreProperties.put(UserStoreConfigConstants.connectionPassword, originalPassword);
                }
            }
            if (userStoreProperties.containsKey(JDBCRealmConstants.PASSWORD)) {
                if (originalPassword != null) {
                    userStoreProperties.put(JDBCRealmConstants.PASSWORD, originalPassword);
                }
            }

            domains.add(userStoreDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();

        } while (secondaryRealmConfiguration != null);
    }
    return domains.toArray(new UserStoreDTO[domains.size()]);
}