This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 4_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit 0fa4f47d52165805a19b6a2cb168f98320a05b86
Author: Gianpaolo <[email protected]>
AuthorDate: Fri Nov 13 08:44:13 2026 +0100

    [SYNCOPE-2010] DefaultPasswordGenerator.merge() ignores usernameAllowed 
(#1606)
---
 .../markup/html/form/AjaxGridBottomToolbar.java    |  1 +
 .../spring/security/DefaultPasswordGenerator.java  |  2 +-
 .../spring/security/PasswordGeneratorTest.java     | 63 ++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)

diff --git 
a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxGridBottomToolbar.java
 
b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxGridBottomToolbar.java
index d6d706be71..259b38e3d5 100644
--- 
a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxGridBottomToolbar.java
+++ 
b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxGridBottomToolbar.java
@@ -123,6 +123,7 @@ public abstract class AjaxGridBottomToolbar<T, S> extends 
AbstractEditableToolba
         };
     }
 
+    @SuppressWarnings("unchecked")
     protected List<AbstractEditablePropertyColumn<T, S>> getEditableColumns() {
         List<AbstractEditablePropertyColumn<T, S>> columns = new ArrayList<>();
         getTable().getColumns().stream().
diff --git 
a/core/spring/src/main/java/org/apache/syncope/core/spring/security/DefaultPasswordGenerator.java
 
b/core/spring/src/main/java/org/apache/syncope/core/spring/security/DefaultPasswordGenerator.java
index 98e82b737a..7a1ee5d38e 100644
--- 
a/core/spring/src/main/java/org/apache/syncope/core/spring/security/DefaultPasswordGenerator.java
+++ 
b/core/spring/src/main/java/org/apache/syncope/core/spring/security/DefaultPasswordGenerator.java
@@ -150,7 +150,7 @@ public class DefaultPasswordGenerator implements 
PasswordGenerator {
                 result.setRepeatSame(ruleConf.getRepeatSame());
             }
 
-            if (!result.isUsernameAllowed()) {
+            if (result.isUsernameAllowed()) {
                 result.setUsernameAllowed(ruleConf.isUsernameAllowed());
             }
 
diff --git 
a/core/spring/src/test/java/org/apache/syncope/core/spring/security/PasswordGeneratorTest.java
 
b/core/spring/src/test/java/org/apache/syncope/core/spring/security/PasswordGeneratorTest.java
index 4e830342ca..ccc1387774 100644
--- 
a/core/spring/src/test/java/org/apache/syncope/core/spring/security/PasswordGeneratorTest.java
+++ 
b/core/spring/src/test/java/org/apache/syncope/core/spring/security/PasswordGeneratorTest.java
@@ -19,11 +19,13 @@
 package org.apache.syncope.core.spring.security;
 
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.json.JsonMapper;
+import java.util.ArrayList;
 import java.util.List;
 import org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf;
 import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
@@ -150,4 +152,65 @@ public class PasswordGeneratorTest {
         password = passwordGenerator.generate(List.of(new 
TestPasswordPolicy(passwordRule)));
         assertNotNull(password);
     }
+
+    private static DefaultPasswordRuleConf configRule(final boolean 
usernameAllowed) {
+        DefaultPasswordRuleConf conf = new DefaultPasswordRuleConf();
+        conf.setUsernameAllowed(usernameAllowed);
+        return conf;
+    }
+
+    @Test
+    public void allForbid() {
+        List<DefaultPasswordRuleConf> rules = new ArrayList<>();
+        rules.add(configRule(false));
+        rules.add(configRule(false));
+        assertFalse(passwordGenerator.merge(rules).isUsernameAllowed());
+    }
+
+    @Test
+    public void singleTrue() {
+        List<DefaultPasswordRuleConf> rules = new ArrayList<>();
+        rules.add(configRule(true));
+        assertTrue(passwordGenerator.merge(rules).isUsernameAllowed());
+    }
+
+    @Test
+    public void singleFalse() {
+        List<DefaultPasswordRuleConf> rules = new ArrayList<>();
+        rules.add(configRule(false));
+        assertFalse(passwordGenerator.merge(rules).isUsernameAllowed());
+    }
+
+    @Test
+    public void twoTrue() {
+        List<DefaultPasswordRuleConf> rules = new ArrayList<>();
+        rules.add(configRule(true));
+        rules.add(configRule(true));
+        assertTrue(passwordGenerator.merge(rules).isUsernameAllowed());
+    }
+
+    @Test
+    public void trueThenFalse() {
+        List<DefaultPasswordRuleConf> rules = new ArrayList<>();
+        rules.add(configRule(true));
+        rules.add(configRule(false));
+        assertFalse(passwordGenerator.merge(rules).isUsernameAllowed());
+    }
+
+    @Test
+    public void falseThenTrue() {
+        List<DefaultPasswordRuleConf> rules = new ArrayList<>();
+        rules.add(configRule(false));
+        rules.add(configRule(true));
+        assertFalse(passwordGenerator.merge(rules).isUsernameAllowed());
+    }
+
+    @Test
+    public void falseInTheMiddle() {
+        List<DefaultPasswordRuleConf> rules = new ArrayList<>();
+        rules.add(configRule(true));
+        rules.add(configRule(false));
+        rules.add(configRule(true));
+        assertFalse(passwordGenerator.merge(rules).isUsernameAllowed());
+    }
 }

Reply via email to