Skip to content

[SYNCOPE-2010] DefaultPasswordGenerator.merge() ignores usernameAllowed - #1606

Merged
ilgrosso merged 3 commits into
apache:masterfrom
gianpaolo-pestilli:fixDefaultPasswordGenerator
Nov 13, 2026
Merged

ilgrosso merged 3 commits into
apache:masterfrom
gianpaolo-pestilli:fixDefaultPasswordGenerator

Conversation

@gianpaolo-pestilli

Copy link
Copy Markdown
Contributor

Problem

DefaultPasswordGenerator.merge(List<DefaultPasswordRuleConf>) always returns
a configuration with usernameAllowed == true, even when every input
configuration has usernameAllowed == false.

How to reproduce

The test added in this PR fails on current master without the fix:

@Test
void allForbid() {
    List<DefaultPasswordRuleConf> rules = new ArrayList();
    rules.add(configRule(false));
    rules.add(configRule(false));
    assertFalse(passwordGenerator.merge(rules).isUsernameAllowed());
}

Cause

In merge, result is initialized with result.setUsernameAllowed(true)
and is never set to false before the following check

if (!result.isUsernameAllowed()) {
result.setUsernameAllowed(ruleConf.isUsernameAllowed());
}

if (!result.isUsernameAllowed()) {
    result.setUsernameAllowed(ruleConf.isUsernameAllowed());
}

The condition can therefore never be true, and the value of
usernameAllowed in the input configurations is never read.

Proposed fix

Remove the negation, so that usernameAllowed stays true only if all the
configurations allow it (consistently with the other fields, where the most
restrictive value wins):

if (result.isUsernameAllowed()) {
    result.setUsernameAllowed(ruleConf.isUsernameAllowed());
}

Tests

Added PasswordGeneratorTest.allForbid(): with
two configurations both having usernameAllowed == false, merge() must
return usernameAllowed == false. It fails without the fix and passes with it.

Note

If the current behavior is intended, please let me know and I will adjust
or close this PR.

cc @gulyx

@ilgrosso

ilgrosso commented Nov 9, 2026

Copy link
Copy Markdown
Member

Hi @gianpaolo-pestilli thanks for this PR.
Have you already submitted your ICLA?

@ilgrosso

Copy link
Copy Markdown
Member

@gianpaolo-pestilli I was able to verify this issue.
Besides providing information about your ICLA (I wasn't able to find any match in the ASF records), please also go ahead and open an issue on JIRA to track this problem.

@ilgrosso ilgrosso changed the title DefaultPasswordGenerator.merge() ignores usernameAllowed [SYNCOPE-2010] DefaultPasswordGenerator.merge() ignores usernameAllowed Nov 11, 2026
@ilgrosso

Copy link
Copy Markdown
Member

I went ahead and created https://issues.apache.org/jira/browse/SYNCOPE-2010

@gianpaolo-pestilli

Copy link
Copy Markdown
Contributor Author

Hi @ilgrosso, and sorry for the late reply.

I have just pushed a new commit with the requested changes:

I added tests for the other combinations: with the fix applied, all of them pass.
I replaced new ArrayList() with new ArrayList<>(), as you pointed out.

Thank you for verifying the issue. I was waiting to reply because I don’t have a JIRA account yet.

Regarding the ICLA, I haven’t submitted it yet: this is my first contribution to an open source project and I wasn’t sure about it. I’m going to look into it and will let you know here.

Thanks for your patience and your help!

@ilgrosso

Copy link
Copy Markdown
Member

@gianpaolo-pestilli the PR looks good now.
We are awaiting only your ICLA submission to merge it.

@gianpaolo-pestilli

Copy link
Copy Markdown
Contributor Author

Thanks @ilgrosso! I have just sent my signed ICLA: please let me know if there’s anything else I should do.

@ilgrosso
ilgrosso merged commit 37aba81 into apache:master Nov 13, 2026
@ilgrosso

Copy link
Copy Markdown
Member

Thank you very much @gianpaolo-pestilli !
As you can see, I have merged this PR into master and cherry-picked the resulting commit into the 4_2_X and 4_1_X branches.

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.

2 participants