All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.webmacro.resource.UserProvider

java.lang.Object
   |
   +----org.webmacro.resource.UserProvider

public class UserProvider
extends Object
implements ResourceProvider
This is the reference implementation of a "user" ResourceProvider. It operates under a ResourceBroker and doles out objects of type "user" by returning resource objects which implement the User interface.

You should implement your own UserProvider using a database or other source, as this one is not particularly good. It's provided as an example so that you can write one that is compatible with code that may want to use it.

It is recommended that implementations of the "user" resource be compatible (from a ResourceProvider standpoint) with this one. That way WebMacro developers can write applications using the "user" resource type and be independent of the actual mechanism used to save and retreive User objects.

This implementation is fairly limited. It simply maintains a hashtable of users, which it serializes out to disk on shutdown, and reads on startup. This has obvious performance problems if you intend to have a large number of users. It does, however, store passwords as a cryptographically strong one-way hash so that they are not accessible to people who manage to get a copy of the underlying data. It is recommended that all implementation of the User interface follow this security practice as well (many people naively use the same password everywhere, so even if your servlet is not security sensitive you may be exposing your users up to undue risk elsewhere).

You could implement a much better UserProvider and use it instead of this one simply by registering your ResourceProvider as the "user" with the ResourceBroker rather than this one.

For example, you could implement a version of the "user" resource which retreives and saves data to an LDAP server, SQL database, PSE, or other mechanism.

See Also:
User, ResourceBroker, ResoruceProvider

Variable Index

 o TYPE
Constant containing the ResourceBroker and Log type for this class

Constructor Index

 o UserProvider()

Method Index

 o destroy()
Shut down means save state
 o getTypes()
Handles requests of type REMOVE_USER, ADD_USER, and NEW_USER
 o init(ResourceBroker)
Create a new User database that reads and writes its information from the supplied file.
 o main(String[])
Test harness
 o resourceCreate(CreateResourceEvent)
Create user
 o resourceDelete(ResourceEvent)
Delete user
 o resourceExpireTime()
How long to cache things (1 minute)
 o resourceRequest(RequestResourceEvent)
Get user
 o resourceSave(ResourceEvent)
Save user
 o resourceThreads()
Desired level of concurrency--we are all in memory, so none.
 o toString()
Returns the filename of this user database

Variables

 o TYPE
 public static final String TYPE
Constant containing the ResourceBroker and Log type for this class

Constructors

 o UserProvider
 public UserProvider()

Methods

 o init
 public void init(ResourceBroker broker) throws InitException
Create a new User database that reads and writes its information from the supplied file.

Throws: InitException
if initialization of provider failed
 o resourceThreads
 public final int resourceThreads()
Desired level of concurrency--we are all in memory, so none.

 o resourceExpireTime
 public final int resourceExpireTime()
How long to cache things (1 minute)

 o resourceRequest
 public final synchronized void resourceRequest(RequestResourceEvent evt)
Get user

 o resourceCreate
 public final synchronized void resourceCreate(CreateResourceEvent evt) throws ResourceUnavailableException
Create user

Throws: ResourceUnavailableException
to indicate user cannot be found and the search should be aborted
 o resourceSave
 public final synchronized boolean resourceSave(ResourceEvent evt)
Save user

 o resourceDelete
 public final synchronized boolean resourceDelete(ResourceEvent evt)
Delete user

 o getTypes
 public final synchronized String[] getTypes()
Handles requests of type REMOVE_USER, ADD_USER, and NEW_USER

 o destroy
 public final synchronized void destroy()
Shut down means save state

 o toString
 public final String toString()
Returns the filename of this user database

Overrides:
toString in class Object
 o main
 public static final void main(String arg[])
Test harness


All Packages  Class Hierarchy  This Package  Previous  Next  Index