This is an automated email from the ASF dual-hosted git repository. mraible pushed a commit to branch external-login-placeholder-6.1.x in repository https://gitbox.apache.org/repos/asf/roller.git
commit 97851146f09f55ef6259180ec6b4e366063e7d9f Author: Matt Raible <[email protected]> AuthorDate: Mon Nov 16 22:04:10 2026 -0700 Don't match the external-login placeholder as a password Users who log in through LDAP or the servlet container have users.passwords.externalAuthValue stored in place of a Roller password. Roller's password encoder no longer matches that placeholder, so it isn't treated as a password anywhere the encoder checks one. --- .../roller/weblogger/ui/core/RollerContext.java | 5 +- .../ExternalLoginAwarePasswordEncoder.java | 54 ++++++++++++++++++++ .../ExternalLoginAwarePasswordEncoderTest.java | 59 ++++++++++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerContext.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerContext.java index 0955747bc..7fee33870 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerContext.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerContext.java @@ -44,6 +44,7 @@ import org.apache.roller.weblogger.business.WebloggerFactory; import org.apache.roller.weblogger.business.startup.WebloggerStartup; import org.apache.roller.weblogger.ui.core.plugins.UIPluginManager; import org.apache.roller.weblogger.ui.core.plugins.UIPluginManagerImpl; +import org.apache.roller.weblogger.ui.core.security.ExternalLoginAwarePasswordEncoder; import org.apache.roller.weblogger.ui.core.security.AutoProvision; import org.apache.roller.weblogger.ui.core.security.BootstrapSecurity; import org.apache.roller.weblogger.util.Reflection; @@ -70,7 +71,7 @@ public class RollerContext extends ContextLoaderListener private static final Log log = LogFactory.getLog(RollerContext.class); private static ServletContext servletContext = null; - private static DelegatingPasswordEncoder encoder; + private static PasswordEncoder encoder; public RollerContext() { @@ -278,7 +279,7 @@ public class RollerContext extends ContextLoaderListener } } - encoder = createPasswordEncoder(); + encoder = new ExternalLoginAwarePasswordEncoder(createPasswordEncoder()); String daoBeanName = "org.springframework.security.authentication.dao.DaoAuthenticationProvider#0"; diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoder.java b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoder.java new file mode 100644 index 000000000..afe5949bd --- /dev/null +++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoder.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.roller.weblogger.ui.core.security; + +import org.apache.roller.weblogger.config.WebloggerConfig; +import org.springframework.security.crypto.password.PasswordEncoder; + +/** + * 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 this encoder never matches it. + */ +public class ExternalLoginAwarePasswordEncoder implements PasswordEncoder { + + private final PasswordEncoder delegate; + + public ExternalLoginAwarePasswordEncoder(PasswordEncoder delegate) { + this.delegate = delegate; + } + + @Override + public String encode(CharSequence rawPassword) { + return delegate.encode(rawPassword); + } + + @Override + public boolean matches(CharSequence rawPassword, String encodedPassword) { + String marker = WebloggerConfig.getProperty("users.passwords.externalAuthValue", "<externalAuth>"); + if (rawPassword != null && marker != null && !marker.isEmpty() && marker.contentEquals(rawPassword)) { + return false; + } + return delegate.matches(rawPassword, encodedPassword); + } + + @Override + public boolean upgradeEncoding(String encodedPassword) { + return delegate.upgradeEncoding(encodedPassword); + } +} diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoderTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoderTest.java new file mode 100644 index 000000000..8bad9ab63 --- /dev/null +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoderTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.roller.weblogger.ui.core.security; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.DelegatingPasswordEncoder; +import org.springframework.security.crypto.password.NoOpPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ExternalLoginAwarePasswordEncoderTest { + + @SuppressWarnings("deprecation") + private static PasswordEncoder encoder() { + Map<String, PasswordEncoder> encoders = new HashMap<>(); + // as with passwds.encryption.lazyUpgradeFrom=plaintext + encoders.put(null, NoOpPasswordEncoder.getInstance()); + encoders.put("bcrypt", new BCryptPasswordEncoder()); + return new ExternalLoginAwarePasswordEncoder(new DelegatingPasswordEncoder("bcrypt", encoders)); + } + + @Test + void thePlaceholderIsNotAPassword() { + PasswordEncoder encoder = encoder(); + // as Register stores it for container-managed and LDAP sign-ups + assertFalse(encoder.matches("<externalAuth>", encoder.encode("<externalAuth>"))); + // as CustomUserRegistry stores it for directory users + assertFalse(encoder.matches("<externalAuth>", "<externalAuth>")); + } + + @Test + void otherPasswordsStillWork() { + PasswordEncoder encoder = encoder(); + assertTrue(encoder.matches("secret", encoder.encode("secret"))); + assertTrue(encoder.matches("old-plain", "old-plain")); + assertFalse(encoder.matches("wrong", encoder.encode("secret"))); + } +}
