Search in sources :

Example 16 with UserStoreClientException

use of org.wso2.carbon.user.core.UserStoreClientException in project carbon-identity-framework by wso2.

the class UserStoreConfigServiceImpl method getUserStores.

@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));
    }
    UserStoreDTO[] userStoreDTOS = userStoreDTOList.toArray(new UserStoreDTO[0]);
    // Trigger post get listeners.
    try {
        triggerListenersOnUserStoresPostGet(userStoreDTOS);
    } catch (UserStoreClientException e) {
        throw buildIdentityUserStoreClientException("Userstores cannot be retrieved.", e);
    } catch (UserStoreException e) {
        throw new IdentityUserStoreMgtException("Error occurred while triggering userstores post get listener.", e);
    }
    return userStoreDTOS;
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) UserStoreClientException(org.wso2.carbon.user.api.UserStoreClientException) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) Map(java.util.Map)

Example 17 with UserStoreClientException

use of org.wso2.carbon.user.core.UserStoreClientException in project carbon-identity-framework by wso2.

the class UserStoreConfigServiceImpl method updateUserStore.

@Override
public void updateUserStore(UserStoreDTO userStoreDTO, boolean isStateChange) throws IdentityUserStoreMgtException {
    loadTenant();
    try {
        triggerListenersOnUserStorePreUpdate(userStoreDTO, isStateChange);
        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.");
            }
            validateConnectionUrl(userStoreDTO);
            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 {
            validateConnectionUrl(userStoreDTO);
            SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().updateUserStore(userStoreDTO, false);
        }
    } catch (UserStoreClientException e) {
        throw buildIdentityUserStoreClientException("Userstore " + userStoreDTO.getDomainId() + " cannot be updated.", e);
    } catch (UserStoreException e) {
        String errorMessage = e.getMessage();
        throw new IdentityUserStoreMgtException(errorMessage, e);
    }
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) UserStoreClientException(org.wso2.carbon.user.api.UserStoreClientException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 18 with UserStoreClientException

use of org.wso2.carbon.user.core.UserStoreClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManager method deleteUser.

@Override
public void deleteUser(String userId) throws NotFoundException, CharonException, BadRequestException {
    if (log.isDebugEnabled()) {
        log.debug("Deleting user: " + userId);
    }
    // get the user name of the user with this id
    org.wso2.carbon.user.core.common.User coreUser = null;
    String userName = null;
    try {
        // Set thread local property to signal the downstream SCIMUserOperationListener
        // about the provisioning route.
        SCIMCommonUtils.setThreadLocalIsManagedThroughSCIMEP(true);
        String userIdLocalClaim = SCIMCommonUtils.getSCIMtoLocalMappings().get(SCIMConstants.CommonSchemaConstants.ID_URI);
        if (StringUtils.isNotBlank(userIdLocalClaim)) {
            // We cannot use getUserWithID because it throws exception when the user cannot be found.
            // (Generic user store exception). If we can send a specific user not found exception in user core level
            // we can use that method.
            List<org.wso2.carbon.user.core.common.User> coreUsers = carbonUM.getUserListWithID(userIdLocalClaim, userId, UserCoreConstants.DEFAULT_PROFILE);
            if (coreUsers.size() > 0) {
                coreUser = coreUsers.get(0);
            }
        }
        String userStoreDomainFromSP = null;
        try {
            userStoreDomainFromSP = getUserStoreDomainFromSP();
        } catch (IdentityApplicationManagementException e) {
            throw new CharonException("Error retrieving User Store name. ", e);
        }
        if (coreUser == null) {
            // Resource with given id not found
            if (log.isDebugEnabled()) {
                log.debug("User with id: " + userId + " not found.");
            }
            throw new NotFoundException();
        } else if (userStoreDomainFromSP != null && !(userStoreDomainFromSP.equalsIgnoreCase(coreUser.getUserStoreDomain()))) {
            throw new CharonException("User :" + coreUser.getUsername() + "is not belong to user store " + userStoreDomainFromSP + "Hence user updating fail");
        } else {
            // We assume (since id is unique per user) only one user exists for a given id.
            userName = coreUser.getUsername();
            String userStoreDomainName = coreUser.getUserStoreDomain();
            // Check if SCIM is enabled for the user store.
            if (!isSCIMEnabled(userStoreDomainName)) {
                throw new CharonException("Cannot delete user: " + userName + " through SCIM from user store: " + userStoreDomainName + ". SCIM is not enabled for user store: " + userStoreDomainName);
            }
            carbonUM.deleteUserWithID(coreUser.getUserID());
            if (log.isDebugEnabled()) {
                log.debug("User: " + userName + " is deleted through SCIM.");
            }
        }
    } catch (UserStoreClientException e) {
        String errorMessage;
        if (isNotifyUserstoreStatusEnabled()) {
            errorMessage = String.format("Error occurred while deleting user with ID: %s. %s", userId, e.getMessage());
        } else {
            errorMessage = "Error occurred while deleting user with ID: " + userId;
        }
        throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
    } catch (org.wso2.carbon.user.core.UserStoreException e) {
        String errorMessage;
        if (isNotifyUserstoreStatusEnabled()) {
            errorMessage = String.format("Error occurred while deleting user with ID: %s. %s", userId, e.getMessage());
        } else {
            errorMessage = "Error occurred while deleting user with ID: " + userId;
        }
        /*
            There are scenarios where the client exceptions are wrapped in the super class.Therefore checking for
            possible client exception.
             */
        Throwable ex = ExceptionUtils.getRootCause(e);
        if (ex instanceof UserStoreClientException) {
            throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
        }
        throw resolveError(e, errorMessage);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) UserStoreClientException(org.wso2.carbon.user.core.UserStoreClientException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) NotFoundException(org.wso2.charon3.core.exceptions.NotFoundException) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Example 19 with UserStoreClientException

use of org.wso2.carbon.user.core.UserStoreClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.

the class SCIMUserManager method listUsernamesUsingLegacyAPIs.

/**
 * Method to list usernames of all users from a specific user store using legacy APIs.
 *
 * @param domainName Name of the user store
 * @return Usernames list
 * @throws CharonException Error while listing usernames
 * @throws BadRequestException
 */
private Set<org.wso2.carbon.user.core.common.User> listUsernamesUsingLegacyAPIs(String domainName) throws CharonException, BadRequestException {
    Set<org.wso2.carbon.user.core.common.User> users = null;
    try {
        Map<String, String> scimToLocalClaimsMap = SCIMCommonUtils.getSCIMtoLocalMappings();
        String userIdLocalClaim = scimToLocalClaimsMap.get(SCIMConstants.CommonSchemaConstants.ID_URI);
        String claimValue = domainName.toUpperCase() + CarbonConstants.DOMAIN_SEPARATOR + SCIMCommonConstants.ANY;
        if (StringUtils.isNotBlank(userIdLocalClaim)) {
            if (removeDuplicateUsersInUsersResponseEnabled) {
                users = new TreeSet<>(Comparator.comparing(org.wso2.carbon.user.core.common.User::getFullQualifiedUsername));
            } else {
                users = new LinkedHashSet<>();
            }
            users.addAll(carbonUM.getUserListWithID(userIdLocalClaim, claimValue, null));
        }
        return users;
    } catch (UserStoreClientException e) {
        String errorMessage = String.format("Error while listing usernames from domain: %s. %s", domainName, e.getMessage());
        if (log.isDebugEnabled()) {
            log.debug(errorMessage, e);
        }
        throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
    } catch (UserStoreException e) {
        // Sometimes client exceptions are wrapped in the super class.
        // Therefore checking for possible client exception.
        Throwable ex = ExceptionUtils.getRootCause(e);
        if (ex instanceof UserStoreClientException) {
            String errorMessage = String.format("Error while listing usernames from domain: %s. %s", domainName, ex.getMessage());
            if (log.isDebugEnabled()) {
                log.debug(errorMessage, ex);
            }
            throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
        }
        throw new CharonException(String.format("Error while listing usernames from domain: %s.", domainName), e);
    }
}
Also used : User(org.wso2.charon3.core.objects.User) UserStoreClientException(org.wso2.carbon.user.core.UserStoreClientException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) SCIMUserStoreException(org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreException) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) CharonException(org.wso2.charon3.core.exceptions.CharonException)

Aggregations

UserStoreException (org.wso2.carbon.user.api.UserStoreException)15 UserStoreClientException (org.wso2.carbon.user.core.UserStoreClientException)11 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)8 SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)8 UserStoreClientException (org.wso2.carbon.user.api.UserStoreClientException)8 IdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)6 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)6 CharonException (org.wso2.charon3.core.exceptions.CharonException)5 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)4 SCIMUserStoreException (org.wso2.carbon.identity.scim2.common.extenstion.SCIMUserStoreException)4 User (org.wso2.charon3.core.objects.User)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)3 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 AbstractUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory)3 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)3 Path (java.nio.file.Path)2 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)2 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)2