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

Resolved NPE in self-registering a user to an invalid user realm through API #833

Conversation

KaveeshaPiumini
Copy link
Contributor

@KaveeshaPiumini KaveeshaPiumini commented Jul 10, 2024

Description

This refactors the getRealmConfiguration method in 'org/wso2/carbon/identity/recovery/util/Utils.java' to handle NullPointerException when retrieving the RealmConfiguration based on the user's domain.

Proposed changes in this pull request

  • Added a null check before retrieving RealmConfiguration to prevent NullPointerException when getSecondaryUserStoreManager returns null.
  • Added a error throw with handleClientException to throw an UserStoreClientException when an invalid user store domain is provided.
  • Added a test to check whether the checkPasswordPatternViolation method throws IdentityRecoveryClientException for a user with invalid domain

Related Issue

Cause of Issue

The existing implementation did not handle the case where getSecondaryUserStoreManager returned null when an invalid user store domain is provided, which caused an unexpected NullPointerException during runtime.

@CLAassistant
Copy link

CLAassistant commented Jul 11, 2024

CLA assistant check
All committers have signed the CLA.

sadilchamishka
sadilchamishka previously approved these changes Jul 12, 2024
UserStoreManager secondaryUserStoreManager =
((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getSecondaryUserStoreManager(
user.getUserStoreDomain());
if (secondaryUserStoreManager != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return exception if null first and return the result at the end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning exception at the end of the logic given a wrong expression.

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/10035889426

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/10035889426
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/10035889426

@sadilchamishka sadilchamishka merged commit c683231 into wso2-extensions:master Jul 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants