Skip to content

server: fix NPE on first LDAP login - #14098

Open
xujiantop-crypto wants to merge 1 commit into
apache:mainfrom
xujiantop-crypto:fix/ldap-first-login-npe
Open

server: fix NPE on first LDAP login#14098
xujiantop-crypto wants to merge 1 commit into
apache:mainfrom
xujiantop-crypto:fix/ldap-first-login-npe

Conversation

@xujiantop-crypto

Copy link
Copy Markdown

Description

On a user's first LDAP login, getActiveUserAccount returns null before loginUser authenticates the LDAP user and creates the CloudStack user. After the successful login, the OAuth login-detail cleanup dereferences that stale null value and turns the successful login into an NPE.

Only remove the OAuth login detail when the user already existed before authentication. A newly created LDAP user cannot have that pre-existing detail, so its successful login response is now returned normally.

Fixes #14095

Testing

Added DefaultLoginAPIAuthenticatorCmdTest.testAuthenticateFirstLdapLoginWithoutExistingUser to reproduce the first-login flow and verify that OAuth-detail cleanup is skipped for a user that did not exist before LDAP authentication.

mvn -pl server -am -Dtest=DefaultLoginAPIAuthenticatorCmdTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test

Result: 1 test passed; all 26 reactor modules succeeded; Checkstyle reported 0 violations.

Signed-off-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
@boring-cyborg

boring-cyborg Bot commented Sep 9, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@sudo87 sudo87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clgtm

@sureshanaparti

Copy link
Copy Markdown
Contributor

hi @xujiantop-crypto can you rebase/change the target branch to 4.20 if the fix is relevant there.

@sureshanaparti

Copy link
Copy Markdown
Contributor

hi @xujiantop-crypto can you rebase/change the target branch to 4.20 if the fix is relevant there.

ignore this, the change is added in 4.23 (in this PR: #12294)

@sureshanaparti sureshanaparti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cgltm

@sureshanaparti sureshanaparti added this to the 24.0 milestone Sep 9, 2026
@sureshanaparti

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.80%. Comparing base (cddd2c6) to head (061f1c9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...loud/api/auth/DefaultLoginAPIAuthenticatorCmd.java 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #14098   +/-   ##
=========================================
  Coverage     19.79%   19.80%           
- Complexity    20021    20023    +2     
=========================================
  Files          6371     6371           
  Lines        575954   575955    +1     
  Branches      70521    70522    +1     
=========================================
+ Hits         114035   114056   +21     
+ Misses       449483   449456   -27     
- Partials      12436    12443    +7     
Flag Coverage Δ
uitests 3.52% <ø> (ø)
unittests 21.07% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xujiantop-crypto

Copy link
Copy Markdown
Author

Thanks for the clarification. I will keep the target branch as main. The package and CI checks are running now; I will keep an eye on the results.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE found when a ldap user tries to login for thefirst time

4 participants