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
Issue #5486 PropertyFileLoginModule retains PropertyUserStores #5518
Merged
janbartel
merged 3 commits into
jetty-9.4.x
from
jetty-9.4.x-5486-propertyfileloginmodule
Nov 11, 2020
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
101 changes: 101 additions & 0 deletions
101
jetty-jaas/src/main/java/org/eclipse/jetty/jaas/PropertyUserStoreManager.java
This file contains 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,101 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.jaas; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.jetty.jaas.spi.PropertyFileLoginModule; | ||
import org.eclipse.jetty.security.PropertyUserStore; | ||
import org.eclipse.jetty.util.component.AbstractLifeCycle; | ||
import org.eclipse.jetty.util.log.Log; | ||
import org.eclipse.jetty.util.log.Logger; | ||
|
||
/** | ||
* PropertyUserStoreManager | ||
* | ||
* Maintains a map of PropertyUserStores, keyed off the location of the property file containing | ||
* the authentication and authorization information. | ||
* | ||
* This class is used to enable the PropertyUserStores to be cached and shared. This is essential | ||
* for the PropertyFileLoginModules, whose lifecycle is controlled by the JAAS api and instantiated | ||
* afresh whenever a user needs to be authenticated. Without this class, every PropertyFileLoginModule | ||
* instantiation would re-read and reload in all the user information just to authenticate a single user. | ||
*/ | ||
public class PropertyUserStoreManager extends AbstractLifeCycle | ||
{ | ||
private static final Logger LOG = Log.getLogger(PropertyFileLoginModule.class); | ||
|
||
/** | ||
* Map of user authentication and authorization information loaded in from a property file. | ||
* The map is keyed off the location of the file. | ||
*/ | ||
private Map<String, PropertyUserStore> _propertyUserStores; | ||
|
||
public PropertyUserStore getPropertyUserStore(String file) | ||
{ | ||
synchronized (this) | ||
{ | ||
if (_propertyUserStores == null) | ||
return null; | ||
|
||
return _propertyUserStores.get(file); | ||
} | ||
} | ||
|
||
public PropertyUserStore addPropertyUserStore(String file, PropertyUserStore store) | ||
{ | ||
synchronized (this) | ||
{ | ||
Objects.requireNonNull(_propertyUserStores); | ||
PropertyUserStore existing = _propertyUserStores.get(file); | ||
if (existing != null) | ||
return existing; | ||
|
||
_propertyUserStores.put(file, store); | ||
return store; | ||
} | ||
} | ||
|
||
@Override | ||
protected void doStart() throws Exception | ||
{ | ||
_propertyUserStores = new HashMap<String, PropertyUserStore>(); | ||
super.doStart(); | ||
} | ||
|
||
@Override | ||
protected void doStop() throws Exception | ||
{ | ||
for (Map.Entry<String,PropertyUserStore> entry: _propertyUserStores.entrySet()) | ||
{ | ||
try | ||
{ | ||
entry.getValue().stop(); | ||
} | ||
catch (Exception e) | ||
{ | ||
LOG.warn("Error stopping PropertyUserStore at {}", entry.getKey(), e); | ||
} | ||
} | ||
_propertyUserStores = null; | ||
super.doStop(); | ||
} | ||
} |
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an unusual way to share the
LoginService
with theLoginModule
.Would it be better to do this with a
Callback
instead? similar how we would useServletRequestCallback
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that we allow the user to supply their own CallbackHandler class, which might not know anything about the special jetty Callbacks, therefore couldn't supply a value for the JAASLoginService.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that seems strange to me, how would you ever use
ServletRequestCallback
orRequestParameterCallback
inside a login module because they only ever get set on theDefaultCallbackHandler
? Seems like using this would also just break if they supplied a customCallbackHandler
.