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

mraible pushed a commit to branch previous-external-login-markers
in repository https://gitbox.apache.org/repos/asf/roller.git

commit 2dc0ef023769415a88736a814519aebdd93b89b4
Author: Matt Raible <[email protected]>
AuthorDate: Thu Nov 19 17:38:24 2026 -0700

    Recognize previously configured external-login markers
    
    Accounts created before users.passwords.externalAuthValue changed still 
have the old marker stored, encoded or not, and the encoder only recognized the 
current marker and the default, so the old marker matched at login. The new 
users.passwords.externalAuthValue.previous setting lists earlier markers, which 
are refused at login and can't be chosen as passwords, the same as the current 
one. Empty entries are ignored so an empty password never counts as a marker.
---
 .../ui/core/security/RollerPasswordEncoders.java   | 29 +++++++++++----
 .../roller/weblogger/config/roller.properties      |  5 +++
 .../security/ExternalLoginPlaceholderTest.java     | 42 ++++++++++++++++++++++
 3 files changed, 69 insertions(+), 7 deletions(-)

diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java
index 3e1886af3..691212ba4 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerPasswordEncoders.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.config.WebloggerConfig;
@@ -57,14 +58,28 @@ public final class RollerPasswordEncoders {
     }
 
     /**
-     * Whether a password is the configured external-login marker or the
-     * default one, which accounts may still have stored from before the
-     * setting changed. Neither matches at login, so neither can be chosen as a
-     * Roller password.
+     * Whether a password is the configured external-login marker, the default
+     * one, or one listed in users.passwords.externalAuthValue.previous, which
+     * accounts may still have stored from before the setting changed. None of
+     * them matches at login, so none can be chosen as a Roller password.
      */
     public static boolean isExternalLoginMarker(CharSequence password) {
-        return password != null && 
(externalLoginMarker().contentEquals(password)
-                || DEFAULT_EXTERNAL_LOGIN_MARKER.contentEquals(password));
+        if (password == null) {
+            return false;
+        }
+        if (externalLoginMarker().contentEquals(password)
+                || DEFAULT_EXTERNAL_LOGIN_MARKER.contentEquals(password)) {
+            return true;
+        }
+        String previous = 
WebloggerConfig.getProperty("users.passwords.externalAuthValue.previous");
+        for (String marker : 
StringUtils.split(StringUtils.defaultString(previous), ',')) {
+            // an empty entry is never a marker, so an empty password isn't one
+            String trimmed = marker.trim();
+            if (!trimmed.isEmpty() && trimmed.contentEquals(password)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     @SuppressWarnings("deprecation")
@@ -126,7 +141,7 @@ public final class RollerPasswordEncoders {
      * Users who log in through LDAP or the servlet container have no Roller
      * password; Roller stores users.passwords.externalAuthValue in its place.
      * That placeholder is not a password, so it never matches, and neither do
-     * the default placeholder and an empty password.
+     * the default or a previous placeholder and an empty password.
      */
     private record ExternalLoginAware(PasswordEncoder delegate) implements 
PasswordEncoder {
 
diff --git 
a/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties 
b/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties
index 970dac6f4..000a7411e 100644
--- 
a/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties
+++ 
b/app/src/main/resources/org/apache/roller/weblogger/config/roller.properties
@@ -360,6 +360,11 @@ weblog.inlineImages.maxFieldBytes=60000
 # Empty value used for passphrase in roller_user table when LDAP, CMA, or OIDC 
used.
 users.passwords.externalAuthValue=<externalAuth>
 
+# Comma-separated values that users.passwords.externalAuthValue had before.
+# Accounts created then still have them stored, so list them here when changing
+# that setting; none of them is accepted as a password.
+users.passwords.externalAuthValue.previous=
+
 # OIDC provider configuration. To configure a provider, set all three required
 # properties using the pattern oidc.{registrationId}.{property}.
 # Multiple providers can be configured with different registration IDs.
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java
index 8f83b8857..50ca127e5 100644
--- 
a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginPlaceholderTest.java
@@ -139,6 +139,48 @@ class ExternalLoginPlaceholderTest {
         assertFalse(RollerPasswordEncoders.create().matches("<ldap>", 
"<ldap>"));
     }
 
+    @Test
+    void aPreviousEncodedPlaceholderIsNotAPasswordAfterTheSettingChanges() 
throws Exception {
+        setProperty("authentication.method", "cma");
+        // as Register stored it for container-managed sign-ups
+        User user = TestUtils.setupUser("oldcmauser");
+        userName = user.getUserName();
+        user.setPassword(RollerPasswordEncoders.create().encode("<old>"));
+        WebloggerFactory.getWeblogger().getUserManager().saveUser(user);
+        TestUtils.endSession(true);
+
+        setProperty("users.passwords.externalAuthValue", "<new>");
+        setProperty("users.passwords.externalAuthValue.previous", 
"<older>,<old>");
+
+        assertThrows(AuthenticationException.class, () -> 
provider().authenticate(
+                UsernamePasswordAuthenticationToken.unauthenticated(userName, 
"<old>")));
+    }
+
+    @Test
+    void aPreviousUnencodedPlaceholderIsNotAPasswordAfterTheSettingChanges() 
throws Exception {
+        setProperty("authentication.method", "ldap");
+        setProperty("users.passwords.externalAuthValue", "<new>");
+        setProperty("users.passwords.externalAuthValue.previous", 
"{noop}secret");
+        // as CustomUserRegistry stored it before the setting changed
+        User user = TestUtils.setupUser("oldldapuser");
+        userName = user.getUserName();
+        user.setPassword("{noop}secret");
+        WebloggerFactory.getWeblogger().getUserManager().saveUser(user);
+        TestUtils.endSession(true);
+
+        assertThrows(AuthenticationException.class, () -> 
provider().authenticate(
+                UsernamePasswordAuthenticationToken.unauthenticated(userName, 
"secret")));
+    }
+
+    @Test
+    void emptyEntriesInThePreviousPlaceholdersAreIgnored() throws Exception {
+        setProperty("users.passwords.externalAuthValue.previous", "<old>,, ,");
+
+        assertTrue(RollerPasswordEncoders.isExternalLoginMarker("<old>"));
+        assertFalse(RollerPasswordEncoders.isExternalLoginMarker(""));
+        assertFalse(RollerPasswordEncoders.isExternalLoginMarker(" "));
+    }
+
     @Test
     void anEmptyConfiguredPlaceholderIsNotAPassword() throws Exception {
         setProperty("authentication.method", "db");

Reply via email to