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

The following examples show how to use org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO#setDescription() . 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: 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 2
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 3
Source File: DatabaseBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private UserStoreDTO getUserStoreDTO(RealmConfiguration secondaryRealmConfiguration,
                                     Map<String, String> userStoreProperties) {

    UserStoreDTO userStoreDTO = new UserStoreDTO();
    userStoreDTO.setClassName(secondaryRealmConfiguration.getUserStoreClass());
    userStoreDTO.setDescription(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigurationConstant
                                                                                         .DESCRIPTION));
    userStoreDTO.setDomainId(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigConstants
                                                                                      .DOMAIN_NAME));
    userStoreDTO.setRepositoryClass(DATABASE_BASED);
    if (userStoreProperties.get(DISABLED) != null) {
        userStoreDTO.setDisabled(Boolean.valueOf(userStoreProperties.get(DISABLED)));
    }
    return userStoreDTO;
}
 
Example 4
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private UserStoreDTO getUserStoreDTO(RealmConfiguration secondaryRealmConfiguration, Map<String, String>
        userStoreProperties) {

    UserStoreDTO userStoreDTO = new UserStoreDTO();
    userStoreDTO.setClassName(secondaryRealmConfiguration.getUserStoreClass());
    userStoreDTO.setDescription(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigurationConstant
                                                                                         .DESCRIPTION));
    userStoreDTO.setDomainId(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigConstants
                                                                                      .DOMAIN_NAME));
    userStoreDTO.setRepositoryClass(FILE_BASED);
    if (userStoreProperties.get(DISABLED) != null) {
        userStoreDTO.setDisabled(Boolean.valueOf(userStoreProperties.get(DISABLED)));
    }
    return userStoreDTO;
}
 
Example 5
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()]);
}