Search in sources :

Example 1 with UserFunctionalityManagementClientException

use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementClientException in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerImpl method isUserIdExists.

private boolean isUserIdExists(String userId, int tenantId) throws UserFunctionalityManagementClientException, UserFunctionalityManagementServerException {
    boolean isUserExists;
    try {
        UniqueIDUserStoreManager uniqueIdEnabledUserStoreManager = getUniqueIdEnabledUserStoreManager(UserFunctionalityManagerComponentDataHolder.getInstance().getRealmService(), IdentityTenantUtil.getTenantDomain(tenantId));
        isUserExists = uniqueIdEnabledUserStoreManager.isExistingUserWithID(userId);
        return isUserExists;
    } catch (UserStoreException e) {
        if (isUserNotExistingError(e, userId)) {
            if (log.isDebugEnabled()) {
                log.debug("Cannot retrieve user from userId: " + userId, e);
            }
            throw buildUserNotFoundError();
        }
        throw new UserFunctionalityManagementServerException(UserFunctionalityMgtConstants.ErrorMessages.ERROR_OCCURRED_WHILE_RETRIEVING_USER.getCode(), UserFunctionalityMgtConstants.ErrorMessages.ERROR_OCCURRED_WHILE_RETRIEVING_USER.getDescription());
    }
}
Also used : UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserFunctionalityManagementServerException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException)

Example 2 with UserFunctionalityManagementClientException

use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementClientException in project carbon-identity-framework by wso2.

the class UserFunctionalityManagerImpl method getUniqueIdEnabledUserStoreManager.

private UniqueIDUserStoreManager getUniqueIdEnabledUserStoreManager(RealmService realmService, String tenantDomain) throws UserStoreException, UserFunctionalityManagementClientException {
    UserStoreManager userStoreManager = realmService.getTenantUserRealm(IdentityTenantUtil.getTenantId(tenantDomain)).getUserStoreManager();
    if (!(userStoreManager instanceof UniqueIDUserStoreManager)) {
        if (log.isDebugEnabled()) {
            String msg = "Provided user store manager does not support unique user IDs in the tenant domain" + tenantDomain;
            log.debug(msg);
        }
        throw buildUserNotFoundError();
    }
    return (UniqueIDUserStoreManager) userStoreManager;
}
Also used : UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) UniqueIDUserStoreManager(org.wso2.carbon.user.core.UniqueIDUserStoreManager)

Example 3 with UserFunctionalityManagementClientException

use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementClientException in project identity-governance by wso2-extensions.

the class SecurityQuestionPasswordRecoveryManager method getFunctionalityStatusOfUser.

/**
 * Get the lock status of a functionality given the tenant domain, user name and the functionality identifier.
 *
 * @param user                    User.
 * @param functionalityIdentifier Identifier of the the functionality.
 * @return The status of the functionality, {@link FunctionalityLockStatus}.
 */
private FunctionalityLockStatus getFunctionalityStatusOfUser(User user, String functionalityIdentifier) throws IdentityRecoveryServerException {
    int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain());
    String userId = Utils.getUserId(user.getUserName(), tenantId);
    UserFunctionalityManager userFunctionalityManager = IdentityRecoveryServiceDataHolder.getInstance().getUserFunctionalityManagerService();
    try {
        return userFunctionalityManager.getLockStatus(userId, tenantId, functionalityIdentifier);
    } catch (UserFunctionalityManagementException e) {
        String mappedErrorCode = Utils.prependOperationScenarioToErrorCode(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_GET_LOCK_STATUS_FOR_FUNCTIONALITY.getCode(), IdentityRecoveryConstants.PASSWORD_RECOVERY_SCENARIO);
        StringBuilder message = new StringBuilder(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_GET_LOCK_STATUS_FOR_FUNCTIONALITY.getMessage());
        if (isDetailedErrorMessagesEnabled) {
            message.append(String.format("functionalityIdentifier: %s for %s.", IdentityRecoveryConstants.FunctionalityTypes.FUNCTIONALITY_SECURITY_QUESTION_PW_RECOVERY.getFunctionalityIdentifier(), user.getUserName()));
        }
        String errorMessage = "Error occurred while getting functionality status of user.";
        if (e instanceof UserFunctionalityManagementClientException) {
            if (log.isDebugEnabled()) {
                log.debug(errorMessage, e);
            }
        } else {
            log.error(errorMessage, e);
        }
        throw Utils.handleServerException(mappedErrorCode, message.toString(), null);
    }
}
Also used : UserFunctionalityManagementException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException) UserFunctionalityManagementClientException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementClientException) UserFunctionalityManager(org.wso2.carbon.identity.user.functionality.mgt.UserFunctionalityManager)

Aggregations

UniqueIDUserStoreManager (org.wso2.carbon.user.core.UniqueIDUserStoreManager)2 UserFunctionalityManager (org.wso2.carbon.identity.user.functionality.mgt.UserFunctionalityManager)1 UserFunctionalityManagementClientException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementClientException)1 UserFunctionalityManagementException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException)1 UserFunctionalityManagementServerException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)1