private void checkPasswordValidity(UserStoreException e) throws IdentityRecoveryClientException { Throwable cause = e.getCause(); while (cause != null) { if (cause instanceof IdentityEventException) { String errorCode = ((IdentityEventException) cause).getErrorCode(); if (StringUtils.equals(errorCode, "22001")) { throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages .ERROR_CODE_HISTORY_VIOLATE, null, e); } } if (cause instanceof PolicyViolationException) { throw IdentityException.error(IdentityRecoveryClientException.class, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_POLICY_VIOLATION.getCode(), cause.getMessage(), e); } cause = cause.getCause(); } }
private boolean validateUserCredentials(OAuth2AccessTokenReqDTO tokenReq) throws IdentityOAuth2Exception { boolean authenticated; try { UserStoreManager userStoreManager = getUserStoreManager(tokenReq); String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(tokenReq.getResourceOwnerUsername()); authenticated = userStoreManager.authenticate(tenantAwareUserName, tokenReq.getResourceOwnerPassword()); if (log.isDebugEnabled()) { log.debug("user " + tokenReq.getResourceOwnerUsername() + " authenticated: " + authenticated); } if (!authenticated) { if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(MultitenantUtils.getTenantDomain (tokenReq.getResourceOwnerUsername()))) { throw new IdentityOAuth2Exception("Authentication failed for " + tenantAwareUserName); } throw new IdentityOAuth2Exception("Authentication failed for " + tokenReq.getResourceOwnerUsername()); } } catch (UserStoreException e) { String message = e.getMessage(); if (!(e.getCause() instanceof IdentityException)) { throw new IdentityOAuth2Exception(message, e); } IdentityException identityException = (IdentityException) (e.getCause()); // Set error code to message if available. if (StringUtils.isNotBlank(identityException.getErrorCode())) { message = identityException.getErrorCode() + " " + e.getMessage(); } throw new IdentityOAuth2Exception(message, e); } return true; }