Search in sources :

Example 11 with UserFunctionalityManagementException

use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException 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)

Example 12 with UserFunctionalityManagementException

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

the class UserAccountRecoveryManager method getFunctionalityStatusOfUser.

/**
 * Get the lock status of a functionality given the tenant domain, user name and the functionality identifier.
 *
 * @param tenantDomain            Tenant domain of the user.
 * @param userName                Username of the user.
 * @param functionalityIdentifier Identifier of the the functionality.
 * @return The status of the functionality, {@link FunctionalityLockStatus}.
 */
private FunctionalityLockStatus getFunctionalityStatusOfUser(String userName, String tenantDomain, String functionalityIdentifier) throws IdentityRecoveryServerException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    String userId = Utils.getUserId(userName, 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);
        String message = IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_GET_LOCK_STATUS_FOR_FUNCTIONALITY.getMessage();
        throw Utils.handleServerException(mappedErrorCode, message, null);
    }
}
Also used : UserFunctionalityManagementException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException) UserFunctionalityManager(org.wso2.carbon.identity.user.functionality.mgt.UserFunctionalityManager)

Example 13 with UserFunctionalityManagementException

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

the class PasswordRecoveryManagerImpl method getFunctionalityStatusOfUser.

/**
 * Get the lock status of a functionality given the tenant domain, user name and the functionality type.
 *
 * @param tenantDomain            Tenant domain of the user.
 * @param userName                Username of the user.
 * @param functionalityIdentifier Identifier of the the functionality.
 * @return The status of the functionality, {@link FunctionalityLockStatus}.
 */
private FunctionalityLockStatus getFunctionalityStatusOfUser(String tenantDomain, String userName, String functionalityIdentifier) throws IdentityRecoveryServerException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    String userId = Utils.getUserId(userName, 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("functionality: %s for %s.", IdentityRecoveryConstants.FunctionalityTypes.FUNCTIONALITY_SECURITY_QUESTION_PW_RECOVERY.getFunctionalityIdentifier(), userName));
        }
        throw Utils.handleServerException(mappedErrorCode, message.toString(), null);
    }
}
Also used : UserFunctionalityManagementException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException) UserFunctionalityManager(org.wso2.carbon.identity.user.functionality.mgt.UserFunctionalityManager)

Example 14 with UserFunctionalityManagementException

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

the class SecurityQuestionPasswordRecoveryManager method resetRecoveryPasswordProperties.

private void resetRecoveryPasswordProperties(User user, boolean resetFailedLoginLockOutCount) throws IdentityRecoveryException {
    Property[] connectorConfigs = getConnectorConfigs(user.getTenantDomain());
    for (Property connectorConfig : connectorConfigs) {
        if ((PROPERTY_ACCOUNT_LOCK_ON_FAILURE.equals(connectorConfig.getName())) && !Boolean.parseBoolean(connectorConfig.getValue())) {
            return;
        }
    }
    int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain());
    String userId = Utils.getUserId(user.getUserName(), tenantId);
    UserFunctionalityManager userFunctionalityManager = IdentityRecoveryServiceDataHolder.getInstance().getUserFunctionalityManagerService();
    if (resetFailedLoginLockOutCount) {
        try {
            userFunctionalityManager.unlock(userId, tenantId, IdentityRecoveryConstants.FunctionalityTypes.FUNCTIONALITY_SECURITY_QUESTION_PW_RECOVERY.getFunctionalityIdentifier());
            userFunctionalityManager.deleteAllPropertiesForUser(userId, tenantId, IdentityRecoveryConstants.FunctionalityTypes.FUNCTIONALITY_SECURITY_QUESTION_PW_RECOVERY.getFunctionalityIdentifier());
        } catch (UserFunctionalityManagementException e) {
            throw Utils.handleFunctionalityLockMgtServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_UNLOCK_FUNCTIONALITY_FOR_USER, userId, tenantId, IdentityRecoveryConstants.FunctionalityTypes.FUNCTIONALITY_SECURITY_QUESTION_PW_RECOVERY.getFunctionalityIdentifier(), isDetailedErrorMessagesEnabled);
        }
    } else {
        try {
            Map<String, String> propertiesToUpdate = new HashMap<String, String>();
            propertiesToUpdate.put(IdentityRecoveryConstants.FUNCTION_FAILED_ATTEMPTS_PROPERTY, "0");
            userFunctionalityManager.setProperties(userId, tenantId, IdentityRecoveryConstants.FunctionalityTypes.FUNCTIONALITY_SECURITY_QUESTION_PW_RECOVERY.getFunctionalityIdentifier(), propertiesToUpdate);
        } catch (UserFunctionalityManagementException e) {
            throw Utils.handleFunctionalityLockMgtServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FAILED_TO_UPDATE_PROPERTIES_FOR_FUNCTIONALITY, userId, tenantId, IdentityRecoveryConstants.FunctionalityTypes.FUNCTIONALITY_SECURITY_QUESTION_PW_RECOVERY.getFunctionalityIdentifier(), isDetailedErrorMessagesEnabled);
        }
    }
}
Also used : UserFunctionalityManagementException(org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException) HashMap(java.util.HashMap) UserFunctionalityManager(org.wso2.carbon.identity.user.functionality.mgt.UserFunctionalityManager) Property(org.wso2.carbon.identity.application.common.model.Property)

Aggregations

UserFunctionalityManagementException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementException)12 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 DataSource (javax.sql.DataSource)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Test (org.testng.annotations.Test)7 UserStoreException (org.wso2.carbon.user.api.UserStoreException)7 UserFunctionalityManager (org.wso2.carbon.identity.user.functionality.mgt.UserFunctionalityManager)5 HashMap (java.util.HashMap)2 FunctionalityLockStatus (org.wso2.carbon.identity.user.functionality.mgt.model.FunctionalityLockStatus)2 Matchers.anyString (org.mockito.Matchers.anyString)1 Property (org.wso2.carbon.identity.application.common.model.Property)1 UserFunctionalityManagementClientException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementClientException)1 UserFunctionalityManagementServerException (org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException)1 TestUtils.getConnection (org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.getConnection)1 TestUtils.mockDataSource (org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.mockDataSource)1 TestUtils.spyConnection (org.wso2.carbon.identity.user.functionality.mgt.util.TestUtils.spyConnection)1