mraible commented on code in PR #306:
URL: https://github.com/apache/roller/pull/306#discussion_r4609304612


##########
app/src/main/java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoder.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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, nor
+ * the default placeholder, nor an empty password.
+ */
+public class ExternalLoginAwarePasswordEncoder implements PasswordEncoder {
+
+    /** Stored in place of a password when no other value is configured. */
+    public static final String DEFAULT_EXTERNAL_LOGIN_MARKER = 
"<externalAuth>";
+
+    private final PasswordEncoder delegate;
+
+    public ExternalLoginAwarePasswordEncoder(PasswordEncoder delegate) {
+        this.delegate = delegate;
+    }
+
+    /**
+     * The value stored in place of a Roller password for users who log in
+     * through LDAP or the servlet container: 
users.passwords.externalAuthValue,
+     * or the default when that setting is empty.
+     */
+    public static String externalLoginMarker() {
+        String marker = 
WebloggerConfig.getProperty("users.passwords.externalAuthValue");
+        return marker == null || marker.isEmpty() ? 
DEFAULT_EXTERNAL_LOGIN_MARKER : marker;
+    }
+
+    /**
+     * 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.
+     */
+    public static boolean isExternalLoginMarker(CharSequence password) {
+        return password != null && 
(externalLoginMarker().contentEquals(password)
+                || DEFAULT_EXTERNAL_LOGIN_MARKER.contentEquals(password));
+    }
+
+    @Override
+    public String encode(CharSequence rawPassword) {
+        return delegate.encode(rawPassword);
+    }
+
+    @Override
+    public boolean matches(CharSequence rawPassword, String encodedPassword) {
+        if (rawPassword == null || rawPassword.length() == 0 || 
isExternalLoginMarker(rawPassword)) {
+            return false;
+        }
+        return delegate.matches(rawPassword, encodedPassword);

Review Comment:
   Fixed in 09ff2d2fd: the encoder now refuses a stored value that is the 
configured or default marker before the delegate sees it, so a marker such as 
`{noop}secret` no longer matches `secret`. The new provider-level 
`aStoredPlaceholderWithAnEncoderPrefixIsNotAPassword` stores `{noop}secret` the 
way `CustomUserRegistry` does and fails without the change. #304 has the same 
change (959a35144), and #333, #343 and #321 include it through their stacks.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to