Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix previous validation error persist in static variable #5968

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/identity-mgt/org.wso2.carbon.identity.mgt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
return bean;
}
} catch (IdentityException e1) {
bean = UserIdentityManagementUtil.getCustomErrorMessagesToVerifyCode(e1, username);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
bean = userIdentityManagementUtil.getCustomErrorMessagesForCodeVerification(e1, username);

Check warning on line 210 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java#L209-L210

Added lines #L209 - L210 were not covered by tests
if (bean.getError() == null) {
bean = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " Invalid confirmation code for user : "
+ username, e1);
Expand Down Expand Up @@ -244,7 +245,8 @@


} catch (IdentityException e) {
bean = UserIdentityManagementUtil.getCustomErrorMessagesToVerifyCode(e, username);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
bean = userIdentityManagementUtil.getCustomErrorMessagesForCodeVerification(e, username);

Check warning on line 249 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java#L248-L249

Added lines #L248 - L249 were not covered by tests
if (bean.getError() == null) {
bean = handleError(VerificationBean.ERROR_CODE_RECOVERY_NOTIFICATION_FAILURE + ": " + VerificationBean.
ERROR_CODE_UNEXPECTED + " Error when sending recovery message for " +
Expand Down Expand Up @@ -319,7 +321,8 @@
log.error(bean.getError());
}
} catch (IdentityException e) {
bean = UserIdentityManagementUtil.getCustomErrorMessagesToVerifyCode(e, username);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
bean = userIdentityManagementUtil.getCustomErrorMessagesForCodeVerification(e, username);
if (bean.getError() == null) {
bean = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " Error verifying confirmation code for " +
"user : " + username, e);
Expand Down Expand Up @@ -397,7 +400,8 @@
}

} catch (IdentityException e) {
bean = UserIdentityManagementUtil.getCustomErrorMessagesToVerifyCode(e, username);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
bean = userIdentityManagementUtil.getCustomErrorMessagesForCodeVerification(e, username);
if (bean.getError() == null) {
bean = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " Error while updating credential " +
"for user: " + username, e);
Expand Down Expand Up @@ -696,7 +700,8 @@
bean.setVerified(false);
}
} catch (IdentityException e) {
bean = UserIdentityManagementUtil.getCustomErrorMessagesToVerifyCode(e, userName);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
bean = userIdentityManagementUtil.getCustomErrorMessagesForCodeVerification(e, userName);
if (bean == null) {
bean = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " " +
" Error verifying confirmation code for user : " + userName, e);
Expand Down Expand Up @@ -788,7 +793,8 @@
}
} catch (IdentityException e) {
log.error("Error while verifying confirmation code.", e);
bean = UserIdentityManagementUtil.getCustomErrorMessagesToVerifyCode(e, userName);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
bean = userIdentityManagementUtil.getCustomErrorMessagesForCodeVerification(e, userName);
if (bean == null) {
bean = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " " +
" Error verifying confirmation code for user : " + userName, e);
Expand Down Expand Up @@ -1089,14 +1095,15 @@
vBean.setVerified(true);
}
} catch (UserStoreException | IdentityException e) {
vBean = UserIdentityManagementUtil.getCustomErrorMessagesWhenRegistering(e, userName);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
vBean = userIdentityManagementUtil.retrieveCustomErrorMessagesForRegistration(e, userName);

Check warning on line 1099 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java#L1098-L1099

Added lines #L1098 - L1099 were not covered by tests
//Rollback if user exists
try {
if (!e.getMessage().contains(IdentityCoreConstants.EXISTING_USER) && userStoreManager.isExistingUser(userName)) {
userStoreManager.deleteUser(userName);
}
} catch (UserStoreException e1) {
vBean = UserIdentityManagementUtil.getCustomErrorMessagesWhenRegistering(e1, userName);
vBean = userIdentityManagementUtil.retrieveCustomErrorMessagesForRegistration(e1, userName);

Check warning on line 1106 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java#L1106

Added line #L1106 was not covered by tests
}

return vBean;
Expand Down Expand Up @@ -1213,7 +1220,8 @@
vBean.setVerified(true);
}
} catch (IdentityException e) {
vBean = UserIdentityManagementUtil.getCustomErrorMessagesWhenRegistering(e, userName);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
vBean = userIdentityManagementUtil.retrieveCustomErrorMessagesForRegistration(e, userName);

Check warning on line 1224 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java#L1223-L1224

Added lines #L1223 - L1224 were not covered by tests
return vBean;
}
} finally {
Expand Down Expand Up @@ -1321,7 +1329,8 @@
log.error("User verification failed against the given confirmation code");
}
} catch (IdentityException e) {
bean = UserIdentityManagementUtil.getCustomErrorMessagesToVerifyCode(e, username);
UserIdentityManagementUtil userIdentityManagementUtil = new UserIdentityManagementUtil();
bean = userIdentityManagementUtil.getCustomErrorMessagesForCodeVerification(e, username);

Check warning on line 1333 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/services/UserInformationRecoveryService.java#L1332-L1333

Added lines #L1332 - L1333 were not covered by tests
if (bean.getError() == null) {
bean = handleError("Error while validating confirmation code for user : " + username, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
private static UserChallengesCollectionDTO userChallengesCollectionDTO = new UserChallengesCollectionDTO();
private static Log log = LogFactory.getLog(UserIdentityManagementUtil.class);

private UserIdentityManagementUtil() {
}
private VerificationBean vBeanInstance = new VerificationBean();

/**
* Returns the registration information such as the temporary password or
Expand Down Expand Up @@ -631,6 +630,10 @@
}
}

/**
* @deprecated Use {@link #retrieveCustomErrorMessagesForRegistration} instead.
*/
@Deprecated
public static VerificationBean getCustomErrorMessagesWhenRegistering(Exception e, String userName) {
if (e.getMessage() != null) {
if (e.getMessage().contains(PASSWORD_INVALID)) {
Expand Down Expand Up @@ -688,6 +691,68 @@
}
}

public VerificationBean retrieveCustomErrorMessagesForRegistration(Exception e, String userName) {

if (e.getMessage() != null) {
if (e.getMessage().contains(PASSWORD_INVALID)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_CREDENTIALS +
" Credential not valid. Credential must be a non null for the user : " + userName, e);
} else if (e.getMessage().contains(EXISTING_USER)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_USER +
" Username '" + userName + "' already exists in the system. Please enter another username.", e);
} else if (e.getMessage().contains(INVALID_CLAIM_URL)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " Invalid claim uri has been provided.", e);
} else if (e.getMessage().contains(INVALID_USER_NAME)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_USER +
" Username " + userName + " is not valid. User name must be a non null", e);
} else if (e.getMessage().contains(READ_ONLY_STORE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED +
" Read-only UserStoreManager. Roles cannot be added or modified.", e);
} else if (e.getMessage().contains(READ_ONLY_PRIMARY_STORE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED +
" Cannot add role to Read Only user store unless it is primary.", e);
} else if (e.getMessage().contains(INVALID_ROLE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED +
" Invalid role name. Role name must be a non null string.", e);
} else if (e.getMessage().contains(NO_READ_WRITE_PERMISSIONS)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED +
" Role cannot be added. User store is read only or cannot write groups.", e);
} else if (e.getMessage().contains(EXISTING_ROLE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED +
" Role already exists in the system. Please enter another role name.", e);
} else if (e.getMessage().contains(SHARED_USER_ROLES)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED +

Check warning on line 724 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L724

Added line #L724 was not covered by tests
" User store doesn't support shared user roles functionality.", e);
} else if (e.getMessage().contains(REMOVE_ADMIN_USER)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " Cannot remove Admin user from Admin role.", e);

Check warning on line 727 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L727

Added line #L727 was not covered by tests
} else if (e.getMessage().contains(LOGGED_IN_USER)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " Cannot remove Admin user from Admin role.", e);

Check warning on line 729 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L729

Added line #L729 was not covered by tests
} else if (e.getMessage().contains(ADMIN_USER)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " Cannot remove Admin user from Admin role.", e);

Check warning on line 731 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L731

Added line #L731 was not covered by tests
} else if (e.getMessage().contains(ANONYMOUS_USER)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED +

Check warning on line 733 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L733

Added line #L733 was not covered by tests
" Cannot delete anonymous user.", e);
} else if (e.getMessage().contains(INVALID_OPERATION)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " Invalid operation. User store is read only.", e);

Check warning on line 736 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L736

Added line #L736 was not covered by tests
} else if (e.getMessage().contains(PASSWORD_POLICY_VIOLATION)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_UNEXPECTED + " " + e.getMessage(), e);
} else {
vBeanInstance = handleError(
VerificationBean.ERROR_CODE_UNEXPECTED + " Error occurred while adding user : " + userName, e);
return vBeanInstance;
}
return vBeanInstance;
} else {
vBeanInstance = handleError(
VerificationBean.ERROR_CODE_UNEXPECTED + " Error occurred while adding user : " + userName, e);
return vBeanInstance;
}
}

/**
* @deprecated Use {@link #getCustomErrorMessagesForCodeVerification} instead.
*/
@Deprecated
public static VerificationBean getCustomErrorMessagesToVerifyCode(IdentityException e, String userName) {
if (e.getMessage() != null) {
if (e.getMessage().contains(VerificationBean.ERROR_CODE_EXPIRED_CODE)) {
Expand Down Expand Up @@ -726,6 +791,45 @@
}
}

public VerificationBean getCustomErrorMessagesForCodeVerification(IdentityException e, String userName) {

if (e.getMessage() != null) {
if (e.getMessage().contains(VerificationBean.ERROR_CODE_EXPIRED_CODE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_EXPIRED_CODE + " The code is " + "expired", e);
} else if (e.getMessage().contains(IdentityMgtConstants.ErrorHandling.INVALID_CONFIRMATION_CODE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " " +
IdentityMgtConstants.ErrorHandling.INVALID_CONFIRMATION_CODE, e);
} else if (e.getMessage().contains(VerificationBean.ERROR_CODE_LOADING_DATA_FAILURE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_LOADING_DATA_FAILURE + " Error" +
" loading data for user : " + userName, e);
} else if (e.getMessage().contains(IdentityMgtConstants.ErrorHandling.EXTERNAL_CODE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " " +
IdentityMgtConstants.ErrorHandling.EXTERNAL_CODE + ": " + userName, e);
} else if (e.getMessage().contains(IdentityMgtConstants.ErrorHandling.NOTIFICATION_FAILURE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_RECOVERY_NOTIFICATION_FAILURE + " " + IdentityMgtConstants.
ErrorHandling.NOTIFICATION_FAILURE + ": " + userName, e);
} else if (e.getMessage().contains(IdentityMgtConstants.ErrorHandling.ERROR_LOADING_EMAIL_TEMP)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_RECOVERY_NOTIFICATION_FAILURE + ": " + IdentityMgtConstants.
ErrorHandling.ERROR_LOADING_EMAIL_TEMP + " " + userName, e);
} else if (e.getMessage().contains(IdentityMgtConstants.ErrorHandling.EXTERNAL_CODE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + ": " + IdentityMgtConstants.

Check warning on line 815 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L815

Added line #L815 was not covered by tests
ErrorHandling.EXTERNAL_CODE + " " + userName, e);
} else if (e.getMessage().contains(IdentityMgtConstants.ErrorHandling.CREATING_NOTIFICATION_ERROR)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_RECOVERY_NOTIFICATION_FAILURE + ": " + IdentityMgtConstants.
ErrorHandling.CREATING_NOTIFICATION_ERROR + " " + userName, e);
} else if (e.getMessage().contains(VerificationBean.ERROR_CODE_LOADING_DATA_FAILURE)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_LOADING_DATA_FAILURE + " Error" +

Check warning on line 821 in components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java

View check run for this annotation

Codecov / codecov/patch

components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/util/UserIdentityManagementUtil.java#L821

Added line #L821 was not covered by tests
" loading data for user : " + userName, e);
} else if (e.getMessage().contains(IdentityMgtConstants.ErrorHandling.USER_ACCOUNT)) {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " No user account found for user", e);
}
return vBeanInstance;
} else {
vBeanInstance = handleError(VerificationBean.ERROR_CODE_INVALID_CODE + " No user account found for user", e);
return vBeanInstance;
}
}

public static ChallengeQuestionIdsDTO getCustomErrorMessagesForChallengeQuestionIds(Exception e, String userName) {
if (e.getMessage() != null) {
if (e.getMessage().contains(VerificationBean.ERROR_CODE_EXPIRED_CODE)) {
Expand Down
Loading
Loading