Top Description Inners Fields Constructors Methods
org.eclipse.jetty.security

public Class PropertyUserStore

extends UserStore
implements DiscreteListener
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Scanner.DiscreteListener, org.eclipse.jetty.util.Scanner.Listener
Imports
java.io.IOException, .InputStream, java.nio.file.Path, java.util.ArrayList, .HashSet, .List, .Map, .Properties, .Set, org.eclipse.jetty.util.Scanner, .StringUtil, org.eclipse.jetty.util.resource.Resource, .Resources, org.eclipse.jetty.util.security.Credential, org.slf4j.Logger, .LoggerFactory

This class monitors a property file of the format mentioned below and notifies registered listeners of the changes to the the given file.

 username: password [,rolename ...]

Passwords may be clear text, obfuscated or checksummed. The class org.eclipse.jetty.util.security.Password should be used to generate obfuscated passwords or password checksums.

If DIGEST Authentication is used, the password must be in a recoverable format, either plain text or obfuscated.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
protected Resource
protected boolean
protected List<PropertyUserStore.UserListener>
protected int
protected Scanner
private static final Logger
Inherited from org.eclipse.jetty.security.UserStore:
_users

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Depending on the value of the refresh interval, this method will either start up a scanner thread that will monitor the properties file for changes after it has initially loaded it.

protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

public Resource

Returns:

the config path as a string
getConfig
()

Get the config (as a string)

public Resource
getConfigResource()
Deprecated for removal.

Returns: the resource associated with the configured properties file, creating it if necessary

public int

Returns:

the period in seconds to scan for property file changes, or 0 for no scanning
getReloadInterval
()

Get the period in seconds to scan for property file changes, or 0 for no scanning.

public boolean

Returns:

true if hot reload was enabled before startup
isHotReload
()
Deprecated use getReloadInterval()

Is hot reload enabled on this user store

protected void
loadUsers()

Load the user data from the property file.

private void
notifyRemove(String
the user that was removed
username
)

Notifies the registered listeners that a user has been removed.

private void
notifyUpdate(String
the user that was updated
username
,
Credential
the updated credentials
credential
,
String[]
the updated roles
roleArray
)

Notifies the registered listeners of potential updates to a user

public void
pathAdded(Path
the Path#toRealPath(LinkOption...) of the added file
path
)

Overrides default org.eclipse.jetty.util.Scanner.DiscreteListener.pathAdded.

Called when a file is added.

public void
pathChanged(Path
the Path#toRealPath(LinkOption...) of the changed file
path
)

Overrides default org.eclipse.jetty.util.Scanner.DiscreteListener.pathChanged.

Called when a file is changed.

public void
pathRemoved(Path
the Path#toRealPath(LinkOption...) of the removed file
path
)

Overrides default org.eclipse.jetty.util.Scanner.DiscreteListener.pathRemoved.

Called when a file is removed.

public void
registerUserListener(PropertyUserStore.UserListener
the user listener
listener
)

Registers a listener to be notified of the contents of the property file

public void
setConfig(Resource
the config file TODO: reintroduce setConfig(String) and internal ResourceFactory usage
config
)

Set the Config Path from a String reference to a file

public void
setHotReload(boolean
true to enable to a 1 second scan, false to disable
enable
)
Deprecated use setReloadInterval(int)

Enable Hot Reload of the Property File

public void
setReloadInterval(int
the period in seconds to scan for property file changes, or 0 for no scanning
scanSeconds
)

Enable Hot Reload of the Property File

public String
toString()

Overrides org.eclipse.jetty.security.UserStore.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.security.UserStore:
addUsergetRolePrincipalsgetUserPrincipalremoveUser

Field Detail

_configResourceback to summary
protected Resource _configResource
_firstLoadback to summary
protected boolean _firstLoad
_listenersback to summary
protected List<PropertyUserStore.UserListener> _listeners

Hides org.eclipse.jetty.util.component.ContainerLifeCycle._listeners.

_reloadIntervalback to summary
protected int _reloadInterval
_scannerback to summary
protected Scanner _scanner
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.ContainerLifeCycle.LOG.

Constructor Detail

PropertyUserStoreback to summary
public PropertyUserStore()

Method Detail

doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Depending on the value of the refresh interval, this method will either start up a scanner thread that will monitor the properties file for changes after it has initially loaded it. Otherwise the users will be loaded and there will be no active monitoring thread so changes will not be detected.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

If there was a problem stopping. Will cause a transition to FAILED state

getConfigback to summary
public Resource getConfig()

Get the config (as a string)

Returns:Resource

the config path as a string

getConfigResourceback to summary
public Resource getConfigResource()

Deprecated

for removal.

Returns:Resource

the resource associated with the configured properties file, creating it if necessary

Annotations
@Deprecated
forRemoval:true
getReloadIntervalback to summary
public int getReloadInterval()

Get the period in seconds to scan for property file changes, or 0 for no scanning.

Returns:int

the period in seconds to scan for property file changes, or 0 for no scanning

isHotReloadback to summary
public boolean isHotReload()

Deprecated

use getReloadInterval()

Is hot reload enabled on this user store

Returns:boolean

true if hot reload was enabled before startup

Annotations
@Deprecated
loadUsersback to summary
protected void loadUsers() throws IOException

Load the user data from the property file.

Exceptions
IOException:
If the users cannot be loaded
notifyRemoveback to summary
private void notifyRemove(String username)

Notifies the registered listeners that a user has been removed.

Parameters
username:String

the user that was removed

notifyUpdateback to summary
private void notifyUpdate(String username, Credential credential, String[] roleArray)

Notifies the registered listeners of potential updates to a user

Parameters
username:String

the user that was updated

credential:Credential

the updated credentials

roleArray:String[]

the updated roles

pathAddedback to summary
public void pathAdded(Path path) throws Exception

Overrides default org.eclipse.jetty.util.Scanner.DiscreteListener.pathAdded.

Doc from org.eclipse.jetty.util.Scanner.DiscreteListener.pathAdded.

Called when a file is added. Default implementation calls fileAdded(String).

Parameters
path:Path

the Path#toRealPath(LinkOption...) of the added file

Annotations
@Override
Exceptions
Exception:
May be thrown for handling errors
pathChangedback to summary
public void pathChanged(Path path) throws Exception

Overrides default org.eclipse.jetty.util.Scanner.DiscreteListener.pathChanged.

Doc from org.eclipse.jetty.util.Scanner.DiscreteListener.pathChanged.

Called when a file is changed. Default implementation calls fileChanged(String).

Parameters
path:Path

the Path#toRealPath(LinkOption...) of the changed file

Annotations
@Override
Exceptions
Exception:
May be thrown for handling errors
pathRemovedback to summary
public void pathRemoved(Path path) throws Exception

Overrides default org.eclipse.jetty.util.Scanner.DiscreteListener.pathRemoved.

Doc from org.eclipse.jetty.util.Scanner.DiscreteListener.pathRemoved.

Called when a file is removed. Default implementation calls fileRemoved(String).

Parameters
path:Path

the Path#toRealPath(LinkOption...) of the removed file

Annotations
@Override
Exceptions
Exception:
May be thrown for handling errors
registerUserListenerback to summary
public void registerUserListener(PropertyUserStore.UserListener listener)

Registers a listener to be notified of the contents of the property file

Parameters
listener:PropertyUserStore.UserListener

the user listener

setConfigback to summary
public void setConfig(Resource config)

Set the Config Path from a String reference to a file

Parameters
config:Resource

the config file TODO: reintroduce setConfig(String) and internal ResourceFactory usage

setHotReloadback to summary
public void setHotReload(boolean enable)

Deprecated

use setReloadInterval(int)

Enable Hot Reload of the Property File

Parameters
enable:boolean

true to enable to a 1 second scan, false to disable

Annotations
@Deprecated
setReloadIntervalback to summary
public void setReloadInterval(int scanSeconds)

Enable Hot Reload of the Property File

Parameters
scanSeconds:int

the period in seconds to scan for property file changes, or 0 for no scanning

toStringback to summary
public String toString()

Overrides org.eclipse.jetty.security.UserStore.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jetty.security back to summary

public Interface PropertyUserStore.UserListener


Method Summary

Modifier and TypeMethod and Description
public void
remove(String username)

public void
update(String username, Credential credential, String[] roleArray)

Method Detail

removeback to summary
public void remove(String username)
updateback to summary
public void update(String username, Credential credential, String[] roleArray)