org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException Java Examples

The following examples show how to use org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException. 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 6 votes vote down vote up
/**
 * Update the user store by its domain Id.
 *
 * @param domainId     the domain name to be replaced
 * @param userStoreReq {@link UserStoreReq} to edit.
 * @return UserStoreResponse.
 */
public UserStoreResponse editUserStore(String domainId, UserStoreReq userStoreReq) {

    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().
            getUserStoreConfigService();
    //domainName and typeName are not allowed to edit. iF domain name wanted to update then use
    // userStoreConfigService.updateUserStoreByDomainName(base64URLDecodeId(domainId),
    //         createUserStoreDTO(userStoreReq, domainId));
    try {
        userStoreConfigService.updateUserStore(createUserStoreDTO(userStoreReq), false);
        return buildUserStoreResponseDTO(userStoreReq);
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum =
                UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
 
Example #2
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void createUserStoreDirectory(String tenantFilePath, String fileName, boolean isTenant)
        throws IdentityUserStoreMgtException {

    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    Path userStore = Paths.get(DEPLOYMENT_DIRECTORY);
    if (isTenant) {
        userStore = Paths.get(tenantFilePath, String.valueOf(tenantId), USERSTORES);
    }
    if (!Files.exists(userStore)) {
        try {
            Files.createDirectory(userStore);
            if (isTenant) {
                log.info("folder 'userstores' created for tenant: " + tenantId + "for the file: " + fileName);
            } else {
                log.info("folder 'userstores' created for super tenant for the file: " + fileName);
            }
        } catch (IOException e) {
            log.error("Error at creating 'userstores' directory to store configurations for super tenant");
            throw new IdentityUserStoreMgtException("Error while updating the userStore.");
        }
    }
}
 
Example #3
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteUserStoreSet(String[] domains) throws IdentityUserStoreMgtException {

    if (domains == null || domains.length <= 0) {
        throw new IdentityUserStoreMgtException("No selected user stores to delete");
    }

    if (!validateDomainsForDelete(domains)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Failed to delete user store : No privileges to delete own user store configurations ");
        }
        throw new IdentityUserStoreClientException("No privileges to delete own user store configurations.");
    }
    try {
        SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().deleteUserStores(domains);
    } catch (UserStoreException e) {
        throw new IdentityUserStoreMgtException("Error occurred while deleting the user store.", e);
    }
}
 
Example #4
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 #5
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 #6
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 #7
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void deleteFile(File file, final String userStoreName) throws IdentityUserStoreMgtException {

        validateFileName(userStoreName, userStoreName);
        File[] deleteCandidates = file.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {

                return name.equalsIgnoreCase(userStoreName);
            }
        });

        if (ArrayUtils.isNotEmpty(deleteCandidates)) {
            for (File file1 : deleteCandidates) {
                if (file1.delete()) {
                    log.info("File " + file.getName() + " deleted successfully");
                } else {
                    log.error("error at deleting file:" + file.getName());
                }
            }
        }
    }
 
Example #8
Source File: DatabaseBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
protected void doAddUserStore(UserStorePersistanceDTO userStorePersistanceDTO) throws
        IdentityUserStoreMgtException {

    String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
    try {
        // Run pre user-store add listeners.
        triggerListenersOnUserStorePreAdd(domainName);
        boolean isValidDomain = xmlProcessorUtils.isValidDomain(domainName, true);
        validateForFederatedDomain(domainName);
        if (isValidDomain) {
            addUserStoreProperties(userStorePersistanceDTO.getUserStoreProperties(), domainName);
            addRealmToSecondaryUserStoreManager(userStorePersistanceDTO);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("The user store domain: " + domainName + "is not a valid domain name.");
            }
        }
    } catch (UserStoreException | XMLStreamException e) {
        throw new IdentityUserStoreMgtException("Error occured while adding the user store with the domain: " +
                domainName, e);
    }
}
 
Example #9
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
protected void doUpdateUserStore(UserStorePersistanceDTO userStorePersistanceDTO, boolean isStateChange)
        throws IdentityUserStoreMgtException {

    boolean isValidDomain;
    String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
    try {
        validateForFederatedDomain(domainName);
        isValidDomain = isDomainNameExists(domainName);
    } catch (UserStoreException e) {
        throw new IdentityUserStoreClientException("Error while updating the user store.", e);
    }
    if (isValidDomain) {
        Path userStoreConfigFile = getUserStoreConfigurationFile(userStorePersistanceDTO.getUserStoreDTO());
        if (!Files.exists(userStoreConfigFile)) {
            throw buildException(userStorePersistanceDTO.getUserStoreDTO().getDomainId(), true);
        }
        writeToUserStoreConfigurationFile(userStoreConfigFile, userStorePersistanceDTO.getUserStoreDTO(),
                true, isStateChange, domainName);
    } else {
        String errorMessage = "Trying to edit an invalid domain : " + domainName;
        throw new IdentityUserStoreClientException(errorMessage);
    }
}
 
Example #10
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * To check whether the provided domain name is valid to add user store.
 *
 * @param domainName user store domain name
 * @return true or false
 * @throws IdentityUserStoreMgtException
 */
private boolean isValidDomainToAdd(String domainName) throws IdentityUserStoreMgtException {

    if (StringUtils.isEmpty(domainName)) {
        throw new IdentityUserStoreClientException(" User store domain name should not be empty.");
    }

    if (domainName.contains("_")) {
        throw new IdentityUserStoreClientException(" User store domain name should not contain \"_\".");
    }

    if (getDomainNames().contains(domainName)) {
        // if add, user store domain name shouldn't already exists
        throw new IdentityUserStoreClientException(UserStoreConfigurationConstant.ErrorMessage.
                ERROR_CODE_USER_STORE_DOMAIN_ALREADY_EXISTS.getCode(),
                " Cannot add user store. Domain name: " + domainName + " already exists.");
    }
    return true;
}
 
Example #11
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 #12
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 #13
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 #14
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the meta of user store type.
 *
 * @param typeId the user store type id.
 * @return MetaUserStoreType.
 */

public MetaUserStoreType getUserStoreManagerProperties(String typeId) {

    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance()
            .getUserStoreConfigService();
    Set<String> classNames;
    try {
        classNames = userStoreConfigService.getAvailableUserStoreClasses();
        if (CollectionUtils.isNotEmpty(classNames) &&
                classNames.contains(getUserStoreType(base64URLDecodeId(typeId)))) {
            return buildUserStoreMetaResponse(typeId);
        } else {
            throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage.
                    ERROR_CODE_NOT_FOUND);
        }
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum =
                UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
 
Example #15
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
/**
 * Check the connection heath for JDBC userstores.
 *
 * @param rdBMSConnectionReq {@link RDBMSConnectionReq}.
 * @return ConnectionEstablishedResponse.
 */
public ConnectionEstablishedResponse testRDBMSConnection(RDBMSConnectionReq rdBMSConnectionReq) {

    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance()
            .getUserStoreConfigService();
    ConnectionEstablishedResponse connectionEstablishedResponse = new ConnectionEstablishedResponse();
    boolean isConnectionEstablished;
    connectionEstablishedResponse.setConnection(false);
    try {
        isConnectionEstablished = userStoreConfigService.testRDBMSConnection("",
                rdBMSConnectionReq.getDriverName(), rdBMSConnectionReq.getConnectionURL(),
                rdBMSConnectionReq.getUsername(), rdBMSConnectionReq.getConnectionPassword(), "");
        if (isConnectionEstablished) {
            connectionEstablishedResponse.setConnection(true);
        }
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum =
                UserStoreConstants.ErrorMessage.ERROR_CODE_DATASOURCE_CONNECTION;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
    return connectionEstablishedResponse;
}
 
Example #16
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 #17
Source File: ServerUserStoreService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
/**
 * Handle handleIdentityUserStoreMgtException, ie, handle the appropriate client and server exception and set
 * proper API Error Response.
 *
 * @param exception Exception thrown
 * @param errorEnum Corresponding error enum
 * @return API Error object.
 */
private APIError handleIdentityUserStoreMgtException(IdentityUserStoreMgtException exception,
                                                     UserStoreConstants.ErrorMessage errorEnum) {
    Response.Status status;
    ErrorResponse errorResponse = getErrorBuilder(errorEnum).build(LOG, exception, errorEnum.getDescription());
    if (exception instanceof IdentityUserStoreServerException) {
        status = Response.Status.INTERNAL_SERVER_ERROR;
        return handleIdentityUserStoreException(exception, errorResponse, status);
    } else if (exception instanceof IdentityUserStoreClientException) {
        // Send client error with specific error code or as a BAD request.
        status = Response.Status.BAD_REQUEST;
        return handleIdentityUserStoreException(exception, errorResponse, status);
    } else {
        // Internal Server error
        status = Response.Status.INTERNAL_SERVER_ERROR;
        return new APIError(status, errorResponse);
    }
}
 
Example #18
Source File: DatabaseBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
protected void doUpdateUserStore(UserStorePersistanceDTO userStorePersistanceDTO, boolean isStateChange)
        throws IdentityUserStoreMgtException {

    String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
    updateUserStoreProperties(domainName, userStorePersistanceDTO);
    try {
        removeRealmFromSecondaryUserStoreManager(domainName);
        addRealmToSecondaryUserStoreManager(userStorePersistanceDTO);
    } catch (UserStoreException | XMLStreamException e) {
        throw new IdentityUserStoreMgtException("Error occured while updating the userstore.", e);
    }
}
 
Example #19
Source File: DatabaseBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
protected void doUpdateUserStoreDomainName(String domainName, UserStorePersistanceDTO userStorePersistanceDTO)
        throws IdentityUserStoreMgtException {

    try {
        triggerListnersOnUserStorePreUpdate(domainName, userStorePersistanceDTO.getUserStoreDTO().getDomainId());
        updateUserStoreProperties(domainName, userStorePersistanceDTO);
        removeRealmFromSecondaryUserStoreManager(domainName);
        addRealmToSecondaryUserStoreManager(userStorePersistanceDTO);
    } catch (UserStoreException | XMLStreamException e) {
        throw new IdentityUserStoreMgtException("Error occured while updating the userstore.", e);
    }
}
 
Example #20
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 #21
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 #22
Source File: UserStoreConfigServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteUserStore(String domain) throws IdentityUserStoreMgtException {

    if (StringUtils.isEmpty(domain)) {
        throw new IdentityUserStoreClientException("No selected user store to delete.");
    }

    if (!validateDomainsForDelete(new String[]{domain})) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Failed to delete user store " + domain + " " +
                      ": No privileges to delete own user store configurations ");
        }
        throw new IdentityUserStoreClientException("No privileges to delete own user store configurations.");
    }
    try {
        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)) {
                entry.getValue().getInstance().deleteUserStore(domain);
            } else {
                SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().deleteUserStore(domain);
            }
        }
    } catch (UserStoreException e) {
        throw new IdentityUserStoreMgtException("Error occurred while deleting the user store.", e);
    }
}
 
Example #23
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 #24
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
protected void doAddUserStore(UserStorePersistanceDTO userStorePersistanceDTO) throws
        IdentityUserStoreMgtException {

    String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
    try {
        // Run pre user-store add listeners.
        triggerListenersOnUserStorePreAdd(domainName);
        boolean validDomain = isValidDomainToAdd(domainName);
        validateForFederatedDomain(domainName);
        if (validDomain) {
            Path userStoreConfigFile = getUserStoreConfigurationFile(userStorePersistanceDTO.getUserStoreDTO());
            if (Files.exists(userStoreConfigFile)) {
                throw buildException(userStorePersistanceDTO.getUserStoreDTO().getDomainId(), false);
            }
            writeToUserStoreConfigurationFile(userStoreConfigFile, userStorePersistanceDTO.getUserStoreDTO(),
                    false, false, domainName);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("The user store domain: " + domainName + "is not a valid domain name.");
            }
        }
    } catch (UserStoreException e) {
        throw new IdentityUserStoreClientException("Error occurred while adding the user store with the domain: " +
                domainName, e);
    }
}
 
Example #25
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 #26
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 #27
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * To check whether the provided domain name already exists to update or delete.
 *
 * @param domainName user store domain name
 * @return true or false
 * @throws IdentityUserStoreMgtException
 */
private boolean isDomainNameExists(String domainName) throws IdentityUserStoreMgtException {

    if (StringUtils.isEmpty(domainName)) {
        throw new IdentityUserStoreClientException(" User store domain name should not be empty.");
    }

    if (!getDomainNames().contains(domainName)) {
        // if edit or delete, user store domain name should already exists
        throw new IdentityUserStoreClientException(UserStoreConfigurationConstant.ErrorMessage.
                ERROR_CODE_USER_STORE_DOMAIN_NOT_FOUND.getCode(), " Cannot find the domain name " +
                domainName + " to perform this operation");
    }
    return true;
}
 
Example #28
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get a List of existing domain names.
 *
 * @return : list of domain names
 * @throws IdentityUserStoreMgtException
 */
private List<String> getDomainNames() throws IdentityUserStoreMgtException {

    List<String> domains = new ArrayList<String>();

    RealmConfiguration realmConfiguration = null;
    try {
        realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration();
    } catch (UserStoreException e) {
        throw new IdentityUserStoreMgtException(" Error occurred while retrieving the realm configuration ", e);
    }

    // To add PRIMARY domain to the domains list
    String domain = realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
    if (domain == null) {
        domain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    domains.add(domain);

    RealmConfiguration secondaryRealmConfiguration = realmConfiguration.getSecondaryRealmConfig();
    while (secondaryRealmConfiguration != null) {
        domains.add(secondaryRealmConfiguration.getUserStoreProperty(UserCoreConstants.
                RealmConfig.PROPERTY_DOMAIN_NAME));
        secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
    }
    return domains;
}
 
Example #29
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteUserStore(String domain) throws IdentityUserStoreMgtException {

    if (isDomainNameExists(domain)) {
        deleteUserStores(new String[]{domain});
    }
}
 
Example #30
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private IdentityUserStoreMgtException buildException(String domainName, boolean editSecondaryUserStore) {

        String msg = "Cannot add user store " + domainName + ". User store already exists.";
        String errorCode = UserStoreConfigurationConstant.ErrorMessage.ERROR_CODE_XML_FILE_ALREADY_EXISTS.getCode();
        if (editSecondaryUserStore) {
            msg = "Cannot edit user store " + domainName + ". User store cannot be edited.";
            errorCode = UserStoreConfigurationConstant.ErrorMessage.ERROR_CODE_XML_FILE_NOT_FOUND.getCode();
        }
        return new IdentityUserStoreClientException(errorCode, msg);
    }