org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO Java Examples

The following examples show how to use org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO. 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: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void addUserStore(UserStoreDTO userStoreDTO) throws IdentityUserStoreMgtException {

    try {
        if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() &&
                StringUtils.isNotBlank(userStoreDTO.getRepositoryClass())) {
            AbstractUserStoreDAOFactory userStoreDAOFactory = UserStoreConfigListenersHolder.
                    getInstance().getUserStoreDAOFactories().get(userStoreDTO.getRepositoryClass());
            userStoreDAOFactory.getInstance().addUserStore(userStoreDTO);
        } else {
            if (StringUtils.isNotBlank(userStoreDTO.getRepositoryClass())) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Repository separation of user-stores has been disabled. Adding user-store " +
                              userStoreDTO.getDomainId() + " with file-based configuration.");
                }
            }
            SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().addUserStore(userStoreDTO);
        }
    } catch (UserStoreException e) {
        String errorMessage = e.getMessage();
        throw new IdentityUserStoreMgtException(errorMessage, e);
    }
}
 
Example #2
Source File: AbstractUserStoreDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
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;
    }
 
Example #3
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private static Document getDocument(UserStoreDTO userStoreDTO, boolean editSecondaryUserStore,
                                    DocumentBuilder documentBuilder, String existingDomainName)
        throws IdentityUserStoreMgtException {

    Document doc = documentBuilder.newDocument();

    //create UserStoreManager element
    Element userStoreElement = doc.createElement(UserCoreConstants.RealmConfig.LOCAL_NAME_USER_STORE_MANAGER);
    doc.appendChild(userStoreElement);

    Attr attrClass = doc.createAttribute("class");
    if (userStoreDTO != null) {
        attrClass.setValue(userStoreDTO.getClassName());
        userStoreElement.setAttributeNode(attrClass);
        if (userStoreDTO.getClassName() != null) {
            addProperties(existingDomainName, userStoreDTO.getClassName(), userStoreDTO.getProperties(),
                    doc, userStoreElement, editSecondaryUserStore);
        }
        addProperty(UserStoreConfigConstants.DOMAIN_NAME, userStoreDTO.getDomainId(), doc, userStoreElement, false);
        addProperty(UserStoreConfigurationConstant.DESCRIPTION, userStoreDTO.getDescription(), doc,
                    userStoreElement, false);
    }
    return doc;
}
 
Example #4
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 #5
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void writeToUserStoreConfigurationFile(Path userStoreConfigFile, UserStoreDTO userStoreDTO,
                                               boolean editSecondaryUserStore, boolean isStateChange,
                                               String existingDomainName)
        throws IdentityUserStoreMgtException {

    try {
        writeUserMgtXMLFile(userStoreConfigFile, userStoreDTO, editSecondaryUserStore, isStateChange,
                existingDomainName);
        if (log.isDebugEnabled()) {
            log.debug("New user store successfully written to the file" + userStoreConfigFile.toAbsolutePath());
        }
    } catch (IdentityUserStoreMgtException e) {
        String errorMessage = e.getMessage();
        throw new IdentityUserStoreMgtException(errorMessage);
    }
}
 
Example #6
Source File: UserStoreConfigAdminService.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Update a domain to be disabled/enabled in file repository.
 *
 * @param domain Name of the domain to be updated
 * @param isDisable Whether to disable/enable domain(true/false)
 * @throws IdentityUserStoreMgtException If error occurs during domain validation
 * @throws TransformerConfigurationException If error occurs during configuration transformation
 */
public void changeUserStoreState(String domain, Boolean isDisable) throws IdentityUserStoreMgtException,
        TransformerConfigurationException {

    validateDomain(domain, isDisable);

    try {
        triggerListenersOnUserStorePreStateChange(domain, isDisable);
    } catch (UserStoreException e) {
        throw new IdentityUserStoreMgtException("Error occurred while triggering the user store pre state change" +
                " listeners.");
    }

    UserStoreDTO userStoreDTO = getUserStoreDTO(domain, isDisable, null);
    updateStateInFileRepository(userStoreDTO);
}
 
Example #7
Source File: UserStoreConfigAdminService.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get user stores from all the repositories.
 *
 * @param repositoryClassName repository class name
 * @return userstore {@link UserStoreDTO}
 * @throws IdentityUserStoreMgtException
 */
public UserStoreDTO[] getSecondaryRealmConfigurationsOnRepository(String repositoryClassName)
        throws IdentityUserStoreMgtException {

    if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled()) {
        Map<String, AbstractUserStoreDAOFactory> userStoreDAOFactories = UserStoreConfigListenersHolder.
                getInstance().getUserStoreDAOFactories();

        AbstractUserStoreDAOFactory userStoreDAOFactory = userStoreDAOFactories.get(repositoryClassName);
        if (userStoreDAOFactory != null) {
            return userStoreDAOFactory.getInstance().getUserStores();
        } else {
            return new UserStoreDTO[0];
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Returning empty " +
                      "UserStoreDTO array.");
        }
        return new UserStoreDTO[0];
    }
}
 
Example #8
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public UserStoreDTO[] getUserStores() throws IdentityUserStoreMgtException {

    List<UserStoreDTO> userStoreDTOList = new ArrayList<>();
    Map<String, AbstractUserStoreDAOFactory> userStoreDAOFactories = UserStoreConfigListenersHolder.
            getInstance().getUserStoreDAOFactories();
    for (Map.Entry<String, AbstractUserStoreDAOFactory> entry : userStoreDAOFactories.entrySet()) {

        if (!SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() &&
                StringUtils.equals(entry.getKey(), DB_BASED_REPOSITORY_CLASS)) {
            continue;
        }

        UserStoreDTO[] allUserStores = entry.getValue().getInstance().getUserStores();
        userStoreDTOList.addAll(Arrays.asList(allUserStores));
    }
    return userStoreDTOList.toArray(new UserStoreDTO[0]);
}
 
Example #9
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
/**
 * Construct response list with configured user stores details.
 *
 * @param userStoreDTOS array of UserStoreDTO object.
 * @return List<UserStoreListResponse>.
 */
private List<UserStoreListResponse> buildUserStoreListResponse(UserStoreDTO[] userStoreDTOS,
                                                               String requiredAttributes) {

    List<UserStoreListResponse> userStoreListResponseToAdd = new ArrayList<>();
    if (ArrayUtils.isNotEmpty(userStoreDTOS)) {
        for (UserStoreDTO jsonObject : userStoreDTOS) {
            UserStoreListResponse userStoreList = new UserStoreListResponse();
            userStoreList.setDescription(jsonObject.getDescription());
            userStoreList.setName(jsonObject.getDomainId());
            userStoreList.setId(base64URLEncodeId(jsonObject.getDomainId()));
            userStoreList.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT +
                            UserStoreConstants.USER_STORE_PATH_COMPONENT + "/%s",
                    base64URLEncodeId(jsonObject.getDomainId()))).toString());

            if (StringUtils.isNotBlank(requiredAttributes)) {
                String[] requiredAttributesArray = requiredAttributes.split(REGEX_COMMA);
                addUserstoreProperties(jsonObject, userStoreList, Arrays.asList(requiredAttributesArray));
            }
            userStoreListResponseToAdd.add(userStoreList);
        }
    }
    return userStoreListResponseToAdd;
}
 
Example #10
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
/**
 * To retrieve the configured user store lists.
 *
 * @param limit  items per page.
 * @param offset 0 based index to get the results starting from this index + 1.
 * @param filter to specify the filtering capabilities.
 * @param sort   to specify the sorting order.
 * @return List<UserStoreListResponse>.
 */
public List<UserStoreListResponse> getUserStoreList(Integer limit, Integer offset, String filter, String sort,
                                                    String requiredAttributes) {

    handleNotImplementedBehaviour(limit, offset, filter, sort);

    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance()
            .getUserStoreConfigService();
    try {
        UserStoreDTO[] userStoreDTOS = userStoreConfigService.getUserStores();
        return buildUserStoreListResponse(userStoreDTOS, requiredAttributes);

    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum =
                UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
 
Example #11
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public UserStoreDTO getUserStore(String domain) throws IdentityUserStoreMgtException {

    UserStoreDTO[] userStoreDTOS = new UserStoreDTO[0];
    Map<String, AbstractUserStoreDAOFactory> userStoreDAOFactories = UserStoreConfigListenersHolder.
            getInstance().getUserStoreDAOFactories();
    for (Map.Entry<String, AbstractUserStoreDAOFactory> entry : userStoreDAOFactories.entrySet()) {

        if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() &&
                StringUtils.equals(entry.getKey(), DB_BASED_REPOSITORY_CLASS)) {
            return entry.getValue().getInstance().getUserStore(domain);
        }
        try {
            userStoreDTOS = SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().getUserStores();
        } catch (UserStoreException e) {
            throw new IdentityUserStoreMgtException("Error occurred while retrieving the user stores from file" +
                    " based system.", e);
        }
    }
    if (userStoreDTOS != null) {
        for (UserStoreDTO userStoreDTO : userStoreDTOS) {
            if (userStoreDTO.getDomainId().equals(domain)) {
                return userStoreDTO;
            }
        }
    }
    return null;
}
 
Example #12
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void updateUserStoreByDomainName(String previousDomainName, UserStoreDTO userStoreDTO)
        throws IdentityUserStoreMgtException {

    try {
        if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() &&
                StringUtils.isNotEmpty(userStoreDTO.getRepositoryClass())) {
            AbstractUserStoreDAOFactory userStoreDAOFactory = UserStoreConfigListenersHolder.getInstance().
                    getUserStoreDAOFactories().get(userStoreDTO.getRepositoryClass());
            userStoreDAOFactory.getInstance().updateUserStoreDomainName(previousDomainName, userStoreDTO);
        } else if (StringUtils.equals(userStoreDTO.getRepositoryClass(), FILE_BASED_REPOSITORY_CLASS)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Repository separation of user-stores has been disabled. Updating user-store " +
                          "domain name " + userStoreDTO.getDomainId() + " with file-based configuration.");
            }
            SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().updateUserStoreDomainName
                    (previousDomainName, userStoreDTO);
        } else if (StringUtils.isNotEmpty(userStoreDTO.getRepositoryClass())) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Repository separation of user-stores has been disabled. Unable to update " +
                          "user-store domain name " + userStoreDTO.getDomainId() + " with repository class " +
                          userStoreDTO.getRepositoryClass());
            }
        } else {
            SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().
                    updateUserStoreDomainName(previousDomainName, userStoreDTO);
        }
    } catch (UserStoreException e) {
        String errorMessage = e.getMessage();
        throw new IdentityUserStoreMgtException(errorMessage);
    }
}
 
Example #13
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void updateUserStore(UserStoreDTO userStoreDTO, boolean isStateChange) throws IdentityUserStoreMgtException {

    try {
        if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() &&
                StringUtils.isNotEmpty(userStoreDTO.getRepositoryClass())) {

            AbstractUserStoreDAOFactory userStoreDAOFactory = UserStoreConfigListenersHolder.getInstance().
                    getUserStoreDAOFactories().get(userStoreDTO.getRepositoryClass());
            userStoreDAOFactory.getInstance().updateUserStore(userStoreDTO, false);
        } else if (StringUtils.equals(userStoreDTO.getRepositoryClass(), FILE_BASED_REPOSITORY_CLASS)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Repository separation of user-stores has been disabled. Editing user-store " +
                          userStoreDTO.getDomainId() + " with file-based configuration.");
            }
            SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().updateUserStore(userStoreDTO,
                    false);
        } else if (StringUtils.isNotEmpty(userStoreDTO.getRepositoryClass())) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Repository separation of user-stores has been disabled. Unable to edit " +
                          "user-store " + userStoreDTO.getDomainId() + " with repository class " +
                          userStoreDTO.getRepositoryClass());
            }
        } else {
            SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().updateUserStore(userStoreDTO,
                    false);
        }
    } catch (UserStoreException e) {
        String errorMessage = e.getMessage();
        throw new IdentityUserStoreMgtException(errorMessage, e);
    }
}
 
Example #14
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve user store by its domain id.
 *
 * @param domainId the user store domain id.
 * @return UserStoreConfigurationsRes.
 */
public UserStoreConfigurationsRes getUserStoreByDomainId(String domainId) {

    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance()
            .getUserStoreConfigService();
    List<AddUserStorePropertiesRes> propertiesTobeAdd = new ArrayList<>();
    try {
        UserStoreDTO userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId));
        if (userStoreDTO == null) {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.
                    ERROR_CODE_NOT_FOUND);
        }
        UserStoreConfigurationsRes userStoreConfigurations = new UserStoreConfigurationsRes();
        userStoreConfigurations.setClassName(userStoreDTO.getClassName());
        userStoreConfigurations.setDescription(userStoreDTO.getDescription());
        userStoreConfigurations.setName(userStoreDTO.getDomainId());
        userStoreConfigurations.setTypeId(base64URLEncodeId(Objects.requireNonNull
                (getUserStoreTypeName(userStoreDTO.getClassName()))));
        userStoreConfigurations.setTypeName(getUserStoreTypeName(userStoreDTO.getClassName()));
        PropertyDTO[] dtoProperties = userStoreDTO.getProperties();
        for (PropertyDTO propertyDTO : dtoProperties) {
            AddUserStorePropertiesRes userStorePropertiesRes = new AddUserStorePropertiesRes();
            userStorePropertiesRes.setName(propertyDTO.getName());
            userStorePropertiesRes.setValue(propertyDTO.getValue());
            propertiesTobeAdd.add(userStorePropertiesRes);
        }
        userStoreConfigurations.setProperties(propertiesTobeAdd);
        return userStoreConfigurations;

    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum =
                UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_USER_STORE_BY_DOMAIN_ID;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
 
Example #15
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 #16
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyUserStoreState(String domain, Boolean isDisable, String repositoryClass)
        throws IdentityUserStoreMgtException {

    UserStoreDTO userStoreDTO;
    if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() &&
            StringUtils.isNotEmpty(repositoryClass)) {
        Map<String, AbstractUserStoreDAOFactory> userStoreDAOFactories = UserStoreConfigListenersHolder.
                getInstance().getUserStoreDAOFactories();
        AbstractUserStoreDAOFactory userStoreDAOFactory = userStoreDAOFactories.get(repositoryClass);
        userStoreDTO = getUserStoreDTO(domain, isDisable, repositoryClass);
        userStoreDAOFactory.getInstance().updateUserStore(userStoreDTO, true);
    } else if (StringUtils.equals(repositoryClass, FILE_BASED_REPOSITORY_CLASS)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Modifying state for " +
                      "user-store " + domain + " with file-based configuration.");
        }
        userStoreDTO = getUserStoreDTO(domain, isDisable, null);
        updateStateInFileRepository(userStoreDTO);
    } else if (StringUtils.isNotEmpty(repositoryClass)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Unable to modify state " +
                      "for user-store " + domain + " with repository class " + repositoryClass);
        }
    } else {
        userStoreDTO = getUserStoreDTO(domain, isDisable, null);
        updateStateInFileRepository(userStoreDTO);
    }
}
 
Example #17
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 #18
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To update the state in file repository.
 *
 * @param userStoreDTO {@link UserStoreDTO}
 * @throws IdentityUserStoreMgtException
 */
private void updateStateInFileRepository(UserStoreDTO userStoreDTO) throws IdentityUserStoreMgtException {

    try {
        SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().updateUserStore(userStoreDTO, true);
    } catch (Exception e) {
        String errorMessage = e.getMessage();
        throw new IdentityUserStoreMgtException(errorMessage);
    }
}
 
Example #19
Source File: AbstractUserStoreDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private UserStorePersistanceDTO getUserStorePersistanceDTO(UserStoreDTO userStoreDTO, String userStoreProperties) {

        UserStorePersistanceDTO userStorePersistanceDTO = new UserStorePersistanceDTO();
        userStorePersistanceDTO.setUserStoreDTO(userStoreDTO);
        userStorePersistanceDTO.setUserStoreProperties(userStoreProperties);
        return userStorePersistanceDTO;
    }
 
Example #20
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To construct UserStoreDTO object to get user store details.
 *
 * @param domain          the domain name
 * @param isDisable       the boolean value to specify whether user store should enable or disable
 * @param repositoryClass the repository class
 * @return UserStoreDTO
 */
private UserStoreDTO getUserStoreDTO(String domain, Boolean isDisable, String repositoryClass) {

    UserStoreDTO userStoreDTO = new UserStoreDTO();
    userStoreDTO.setDomainId(domain);
    userStoreDTO.setDisabled(isDisable);
    userStoreDTO.setRepositoryClass(repositoryClass);
    return userStoreDTO;
}
 
Example #21
Source File: AbstractUserStoreDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public UserStoreDTO[] getUserStores() throws IdentityUserStoreMgtException {

    UserStorePersistanceDTO[] userStorePersistanceDTOS = doGetAllUserStores();
    List<UserStoreDTO> userStoreDTOs = new ArrayList<>();
    for (UserStorePersistanceDTO userStorePersistanceDTO : userStorePersistanceDTOS) {
        userStoreDTOs.add(userStorePersistanceDTO.getUserStoreDTO());
    }
    return userStoreDTOs.toArray(new UserStoreDTO[userStoreDTOs.size()]);
}
 
Example #22
Source File: AbstractUserStoreDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public UserStoreDTO getUserStore(String domain) throws IdentityUserStoreMgtException {

    UserStorePersistanceDTO userStorePersistanceDTO = doGetUserStore(domain);
    if (userStorePersistanceDTO != null) {
        return userStorePersistanceDTO.getUserStoreDTO();
    }
    return null;
}
 
Example #23
Source File: AbstractUserStoreDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void updateUserStore(UserStoreDTO userStoreDTO, boolean isStateChange) throws IdentityUserStoreMgtException {

    if (isStateChange) {
        userStoreDTO = getUserStoreProperty(userStoreDTO);
    }
    UserStorePersistanceDTO userStorePersistanceDTO = getUserStorePersistanceDTO(userStoreDTO,
            getUserStoreProperties(userStoreDTO, userStoreDTO.getDomainId()));
    userStorePersistanceDTO.setUserStoreDTO(userStoreDTO);
    doUpdateUserStore(userStorePersistanceDTO, isStateChange);
}
 
Example #24
Source File: AbstractUserStoreDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void addUserStore(UserStoreDTO userStoreDTO) throws IdentityUserStoreMgtException {

    UserStorePersistanceDTO userStorePersistanceDTO = getUserStorePersistanceDTO(userStoreDTO,
            getUserStoreProperties(userStoreDTO, userStoreDTO.getDomainId()));
    doAddUserStore(userStorePersistanceDTO);
}
 
Example #25
Source File: AbstractUserStoreDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void updateUserStoreDomainName(String previousDomainName, UserStoreDTO userStoreDTO)
        throws IdentityUserStoreMgtException {

    UserStorePersistanceDTO userStorePersistanceDTO = getUserStorePersistanceDTO(userStoreDTO,
            getUserStoreProperties(userStoreDTO, previousDomainName));
    doUpdateUserStoreDomainName(previousDomainName, userStorePersistanceDTO);
}
 
Example #26
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private static void updateUserStoreProperties(Path userStoreConfigFile, UserStoreDTO userStoreDTO,
                                              boolean editSecondaryUserStore, DocumentBuilder documentBuilder,
                                              String existingDomainName)
        throws IdentityUserStoreMgtException, IOException, TransformerException {

    Document doc = getDocument(userStoreDTO, editSecondaryUserStore, documentBuilder, existingDomainName);
    StreamResult result = new StreamResult(Files.newOutputStream(userStoreConfigFile));
    DOMSource source = new DOMSource(doc);
    transformProperties().transform(source, result);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing the output stream from " + userStoreConfigFile);
    }
    result.getOutputStream().close();

}
 
Example #27
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 #28
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Construct the response for patch replace.
 *
 * @param userStoreDTO {@link UserStoreDTO}.
 * @param propertyDTOS array of {@link PropertyDTO}.
 * @return UserStoreResponse.
 */
private UserStoreResponse buildResponseForPatchReplace(UserStoreDTO userStoreDTO, PropertyDTO[] propertyDTOS) {

    UserStoreResponse userStoreResponseDTO = new UserStoreResponse();
    userStoreResponseDTO.setId((base64URLEncodeId(userStoreDTO.getDomainId())));
    userStoreResponseDTO.setName(userStoreDTO.getDomainId());
    userStoreResponseDTO.setTypeId(base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName
            (userStoreDTO.getClassName()))));
    userStoreResponseDTO.setTypeName(getUserStoreTypeName(userStoreDTO.getClassName()));
    userStoreResponseDTO.setDescription(userStoreDTO.getDescription());
    userStoreResponseDTO.setProperties(patchUserStoreProperties(propertyDTOS));
    return userStoreResponseDTO;
}
 
Example #29
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 #30
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Add requested user store properties to the response.
 *
 * @param userStoreDTO            userStoreDTO object.
 * @param userStoreListResponse   userStoreListResponse object.
 * @param requestedAttributesList Requested user store properties name list.
 */
private void addUserstoreProperties(UserStoreDTO userStoreDTO, UserStoreListResponse userStoreListResponse,
                                    List<String> requestedAttributesList) {

    for (PropertyDTO propertyDTO : userStoreDTO.getProperties()) {
        if (requestedAttributesList.contains(propertyDTO.getName()) &&
                StringUtils.isNotBlank(propertyDTO.getValue())) {
            AddUserStorePropertiesRes addUserStorePropertiesRes = new AddUserStorePropertiesRes();
            addUserStorePropertiesRes.setName(propertyDTO.getName());
            addUserStorePropertiesRes.setValue(propertyDTO.getValue());
            userStoreListResponse.addPropertiesItem(addUserStorePropertiesRes);
        }
    }
}