Search in sources :

Example 6 with NotificationPasswordRecoveryManager

use of org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager in project identity-governance by wso2-extensions.

the class NotificationPasswordRecoveryManager method updateNewPassword.

/**
 * Update the new password of the user.
 *
 * @param user                            User
 * @param password                        New password
 * @param domainQualifiedName             Domain qualified name
 * @param userRecoveryData                User recovery data
 * @param isNotificationInternallyManaged Whether the notifications are internally managed.
 * @throws IdentityRecoveryException Error while checking for account state claim
 * @throws IdentityRecoveryException Error while updating the password
 */
private void updateNewPassword(User user, String password, String domainQualifiedName, UserRecoveryData userRecoveryData, boolean isNotificationInternallyManaged) throws IdentityEventException, IdentityRecoveryException {
    try {
        int tenantId = IdentityTenantUtil.getTenantId(userRecoveryData.getUser().getTenantDomain());
        UserStoreManager userStoreManager = IdentityRecoveryServiceDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
        userStoreManager.updateCredentialByAdmin(domainQualifiedName, password);
        // Get the claims that related to a password reset.
        HashMap<String, String> userClaims = getAccountStateClaims(userRecoveryData, isNotificationInternallyManaged);
        if (MapUtils.isNotEmpty(userClaims)) {
            // Update the retrieved claims set.
            userStoreManager.setUserClaimValues(domainQualifiedName, userClaims, null);
        }
    } catch (UserStoreException e) {
        checkPasswordValidity(e, user);
        if (log.isDebugEnabled()) {
            log.debug("NotificationPasswordRecoveryManager: Unexpected Error occurred while updating password " + "for the user: " + domainQualifiedName, e);
        }
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED, null, e);
    }
}
Also used : UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager)

Aggregations

IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)4 NotificationPasswordRecoveryManager (org.wso2.carbon.identity.recovery.password.NotificationPasswordRecoveryManager)4 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)3 User (org.wso2.carbon.identity.application.common.model.User)2 ResolvedUserResult (org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult)2 Test (org.testng.annotations.Test)1 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)1 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)1 NotificationResponseBean (org.wso2.carbon.identity.recovery.bean.NotificationResponseBean)1 org.wso2.carbon.identity.recovery.endpoint (org.wso2.carbon.identity.recovery.endpoint)1 RetryErrorDTO (org.wso2.carbon.identity.recovery.endpoint.dto.RetryErrorDTO)1 Property (org.wso2.carbon.identity.recovery.model.Property)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)1