Repository navigation
Don't match the external-login placeholder as a password #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9785114
Don't match the external-login placeholder as a password
mraible f59b841
Reject the external-login placeholder as a chosen password and never …
mraible 2537a6d
Merge remote-tracking branch 'origin/roller-6.1.x' into external-logi…
mraible 09ff2d2
Don't let a stored external-login marker reach the delegate encoder
mraible d984431
Make registration null-safe and use one external-login marker for rem…
mraible 8c48ca3
Recognize previously configured external-login markers
mraible c1b80b7
Merge remote-tracking branch 'origin/roller-6.1.x' into external-logi…
mraible 1b0bd5e
Refuse a password that BCrypt treats as equal to an external-login ma…
mraible d2beeaf
Don't pass a missing or empty stored password to the delegate encoder
mraible ab76765
Log when a password is refused as an external-login marker
mraible c8347ce
Document the limits of users.passwords.externalAuthValue.previous
mraible bfb4371
Test previous external-login markers in the password forms and the en…
mraible b396cb5
Mention users.passwords.externalAuthValue.previous in CHANGES
mraible File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
.../java/org/apache/roller/weblogger/ui/core/security/ExternalLoginAwarePasswordEncoder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * 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.LinkedHashSet; | ||
| import java.util.Set; | ||
|
|
||
| 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; | ||
| 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 or a previous placeholder, nor a password the delegate treats | ||
| * as equal to one of them, nor an empty password. | ||
| */ | ||
| public class ExternalLoginAwarePasswordEncoder implements PasswordEncoder { | ||
|
|
||
| private static final Log log = LogFactory.getLog(ExternalLoginAwarePasswordEncoder.class); | ||
|
|
||
| /** 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; | ||
| if (externalLoginMarker().contains(",")) { | ||
| log.warn("users.passwords.externalAuthValue contains a comma, so it can't be listed in" | ||
| + " users.passwords.externalAuthValue.previous if the setting changes later."); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 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, 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 && externalLoginMarkers().contains(password.toString()); | ||
| } | ||
|
|
||
| /** | ||
| * The configured marker, the default one and the previous ones. The | ||
| * previous ones are a comma-separated list, so a marker that contains a | ||
| * comma can't be listed there. | ||
| */ | ||
| private static Set<String> externalLoginMarkers() { | ||
| Set<String> markers = new LinkedHashSet<>(); | ||
| markers.add(externalLoginMarker()); | ||
| markers.add(DEFAULT_EXTERNAL_LOGIN_MARKER); | ||
| 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()) { | ||
| markers.add(trimmed); | ||
| } | ||
| } | ||
| return markers; | ||
| } | ||
|
|
||
| @Override | ||
| public String encode(CharSequence rawPassword) { | ||
| return delegate.encode(rawPassword); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean matches(CharSequence rawPassword, String encodedPassword) { | ||
| // the delegate can throw for a missing or empty stored value | ||
| if (rawPassword == null || rawPassword.length() == 0 | ||
| || encodedPassword == null || encodedPassword.isEmpty()) { | ||
| return false; | ||
| } | ||
| Set<String> markers = externalLoginMarkers(); | ||
| // a stored marker is checked before the delegate sees it, since a | ||
| // marker such as {noop}secret would otherwise match its own suffix | ||
| if (markers.contains(encodedPassword)) { | ||
| return false; | ||
| } | ||
| if (markers.contains(rawPassword.toString())) { | ||
| logRefusal(); | ||
| return false; | ||
| } | ||
| if (!delegate.matches(rawPassword, encodedPassword)) { | ||
| return false; | ||
| } | ||
| // BCrypt, for one, treats some other passwords as equal to a marker, | ||
| // so refuse any password whose stored value a marker matches too | ||
| for (String marker : markers) { | ||
| if (delegate.matches(marker, encodedPassword)) { | ||
| logRefusal(); | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private static void logRefusal() { | ||
| // the password itself is never logged | ||
| log.info("Refused a password that Roller treats as an external-login marker" | ||
| + " (users.passwords.externalAuthValue or its .previous list). An" | ||
| + " administrator can set a new password for an account that uses one."); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean upgradeEncoding(String encodedPassword) { | ||
| return delegate.upgradeEncoding(encodedPassword); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.