Skip to content

allow linking a domain to a LDAP when it was already used before - #13948

Open
DaanHoogland wants to merge 5 commits into
4.20from
ghi11471-relinkLdapDomain
Open

DaanHoogland wants to merge 5 commits into
4.20from
ghi11471-relinkLdapDomain

Conversation

@DaanHoogland

Copy link
Copy Markdown
Contributor

Description

This PR...

Fixes: #11471

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov

codecov Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.48276% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.45%. Comparing base (6136ac9) to head (5e8cde6).
⚠️ Report is 20 commits behind head on 4.20.

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/user/dao/UserDaoImpl.java 38.46% 8 Missing ⚠️
...va/org/apache/cloudstack/ldap/LdapManagerImpl.java 97.77% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #13948      +/-   ##
============================================
+ Coverage     16.32%   16.45%   +0.13%     
- Complexity    13556    13723     +167     
============================================
  Files          5669     5669              
  Lines        501399   504403    +3004     
  Branches      60902    62149    +1247     
============================================
+ Hits          81847    83014    +1167     
- Misses       410390   412126    +1736     
- Partials       9162     9263     +101     
Flag Coverage Δ
uitests 4.12% <ø> (-0.03%) ⬇️
unittests 17.33% <84.48%> (+0.15%) ⬆️

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.

@DaanHoogland DaanHoogland moved this from Backlog to conflict/waiting in CloudStack Testing Sep 1, 2026
@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

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

@DaanHoogland
DaanHoogland requested a lite review from Copilot September 9, 2026 18:18

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Enables re-linking a domain to LDAP by safely replacing any existing domain-wide mapping, while preventing accidental takeover of account-linked groups and protecting LDAP-provisioned accounts that still depend on the old domain mapping.

Changes:

  • Wrap domain-to-LDAP linking in a DB transaction that checks for conflicts, clears old domain mappings, and persists the new mapping atomically.
  • Add guards to (a) prevent domains from claiming a group/OU already mapped to a live account and (b) prevent removing a domain mapping still required by LDAP-sourced accounts.
  • Add regression/unit tests covering re-linking, conflict detection, and failure/rollback behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java Adds transactional re-linking flow plus dependency/conflict checks for domain LDAP mappings.
plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapManagerImplTest.java Adds regression tests validating re-linking behavior and the new safety checks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +521 to +532
private void ensureOldDomainMappingNotInUse(Long domainId, LdapTrustMapVO oldMapping) {
List<String> dependentAccountNames = new ArrayList<>();
for (AccountVO account : accountDao.findActiveAccountsForDomain(domainId)) {
if (_ldapTrustMapDao.findByAccount(domainId, account.getAccountId()) != null) {
continue;
}
boolean hasLdapUser = userDao.listByAccount(account.getAccountId()).stream()
.anyMatch(user -> User.Source.LDAP.equals(user.getSource()));
if (hasLdapUser) {
dependentAccountNames.add(account.getAccountName());
}
}
Comment on lines +435 to +438
LdapTrustMapVO vo = Transaction.execute((TransactionCallback<LdapTrustMapVO>) status -> {
ensureGroupNotClaimedByLiveAccount(domainId, name);
clearOldDomainMapping(domainId);
return _ldapTrustMapDao.persist(new LdapTrustMapVO(domainId, linkType, name, accountType, 0));
@sonarqubecloud

Copy link
Copy Markdown

@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

This branch has not been deployed

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

Projects

Status: conflict/waiting

Development

Successfully merging this pull request may close these issues.

4 participants