Search in sources :

Example 1 with IdentityUserStoreClientException

use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project carbon-identity-framework by wso2.

the class UserStoreConfigAdminService method deleteUserStoresSetFromRepository.

/**
 * Delete the given list of user stores from any repository
 *
 * @param userStoreDTOs an array instance of {@link UserStoreDTO}
 * @throws IdentityUserStoreMgtException throws when an error occured while deleting the user store.
 */
public void deleteUserStoresSetFromRepository(UserStoreDTO[] userStoreDTOs) throws IdentityUserStoreMgtException {
    if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled()) {
        for (String repositoryClass : UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories().keySet()) {
            List<String> domains = new ArrayList<>();
            for (UserStoreDTO userStoreDTO : userStoreDTOs) {
                if (repositoryClass.equals(userStoreDTO.getRepositoryClass())) {
                    domains.add(userStoreDTO.getDomainId());
                }
            }
            if (CollectionUtils.isNotEmpty(domains)) {
                AbstractUserStoreDAOFactory userStoreDAOFactory = UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories().get(repositoryClass);
                try {
                    userStoreDAOFactory.getInstance().deleteUserStores(domains.toArray(new String[0]));
                } catch (IdentityUserStoreClientException e) {
                    throw buildIdentityUserStoreMgtException(e, "Error while deleting the userstore list.");
                }
            }
        }
    } else {
        List<String> domainList = new ArrayList<>();
        for (UserStoreDTO userStoreDTO : userStoreDTOs) {
            if (StringUtils.equals(userStoreDTO.getRepositoryClass(), FILE_BASED_REPOSITORY_CLASS)) {
                domainList.add(userStoreDTO.getDomainId());
            }
        }
        String[] domains = domainList.toArray(new String[0]);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Attempting to remove " + "user-stores with file-based configurations. For user-stores " + String.join(",", domainList));
        }
        deleteUserStoresSet(domains);
    }
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)

Example 2 with IdentityUserStoreClientException

use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project carbon-identity-framework by wso2.

the class FileBasedUserStoreDAOImpl method doAddUserStore.

@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);
    }
}
Also used : Path(java.nio.file.Path) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)

Example 3 with IdentityUserStoreClientException

use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project identity-api-server by wso2.

the class ServerUserStoreService method deleteUserStore.

/**
 * Delete a userStore by its domainId.
 *
 * @param userstoreDomainId base64 encoded url value of userStore domain Id.
 */
public void deleteUserStore(String userstoreDomainId) {
    try {
        UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
        userStoreConfigService.deleteUserStore(base64URLDecodeId(userstoreDomainId));
    } catch (IdentityUserStoreClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e);
        }
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_USER_STORE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)

Example 4 with IdentityUserStoreClientException

use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project identity-api-server by wso2.

the class ServerUserStoreService method handleIdentityUserStoreMgtException.

/**
 * 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;
    if (exception instanceof IdentityUserStoreServerException) {
        errorResponse = getErrorBuilder(errorEnum).build(LOG, exception, errorEnum.getDescription());
        status = Response.Status.INTERNAL_SERVER_ERROR;
        return handleIdentityUserStoreException(exception, errorResponse, status);
    } else if (exception instanceof IdentityUserStoreClientException) {
        errorResponse = getErrorBuilder(errorEnum).build(LOG, exception.getMessage());
        if (ERROR_CODE_RESOURCE_LIMIT_REACHED.equals(exception.getErrorCode())) {
            return handleResourceLimitReached();
        }
        // 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
        errorResponse = getErrorBuilder(errorEnum).build(LOG, exception, errorEnum.getDescription());
        status = Response.Status.INTERNAL_SERVER_ERROR;
        return new APIError(status, errorResponse);
    }
}
Also used : UserStoreListResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse) UserStoreAttributeMappingResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) UserStoreResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse) ConnectionEstablishedResponse(org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse) IdentityUserStoreServerException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreServerException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 5 with IdentityUserStoreClientException

use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project carbon-identity-framework by wso2.

the class FileBasedUserStoreDAOImpl method doUpdateUserStore.

@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);
    }
}
Also used : Path(java.nio.file.Path) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)

Aggregations

IdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)8 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)4 Path (java.nio.file.Path)3 SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)1 UserStoreAttributeMappingResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse)1 UserStoreListResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)1 UserStoreResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)1 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)1 AbstractUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory)1 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)1 IdentityUserStoreServerException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreServerException)1 UserStoreClientException (org.wso2.carbon.user.api.UserStoreClientException)1