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


##########
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)) {

Review Comment:
   Registration, the profile page and the admin user editor now reject the 
external-login marker (and the default "<externalAuth>") as a new password with 
a validation message; ExternalLoginMarkerPasswordTest covers each form. An 
account that already has it can be recovered by an administrator setting a new 
password in the user editor.



##########
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)) {

Review Comment:
   An empty configured marker now falls back to "<externalAuth>" for what 
CustomUserRegistry and Register store, and the encoder never matches an empty 
password. ExternalLoginPlaceholderTest covers both with an empty configured 
value and plaintext lazy upgrade.



##########
app/src/main/java/org/apache/roller/weblogger/ui/core/RollerContext.java:
##########
@@ -278,7 +279,7 @@ protected void initializeSecurityFeatures(ServletContext 
context) {
             }
         }
 
-        encoder = createPasswordEncoder();
+        encoder = new 
ExternalLoginAwarePasswordEncoder(createPasswordEncoder());

Review Comment:
   Added ExternalLoginPlaceholderTest, which builds DaoAuthenticationProvider 
with RollerUserDetailsService and gives it its encoder through 
RollerContext.initializeSecurityFeatures, then checks encoded, plaintext, 
default and empty placeholders and an ordinary plaintext password.



-- 
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