Top Description Fields Constructors Methods
org.apache.catalina.realm

public Class MemoryRealm

extends RealmBase
Class Inheritance
Known Direct Subclasses
org.apache.catalina.realm.JAASMemoryLoginModule
Imports
java.io.IOException, .InputStream, java.security.Principal, java.util.ArrayList, .HashMap, .List, .Map, org.apache.catalina.LifecycleException, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.digester.Digester, org.apache.tomcat.util.file.ConfigFileLoader

Simple implementation of Realm that reads an XML file to configure the valid users, passwords, and roles. The file format (and default file location) are identical to those currently supported by Tomcat 3.X.

Implementation Note

It is assumed that the in-memory collection representing our defined users (and their roles) is initialized at application startup and never modified again. Therefore, no thread synchronization is performed around accesses to the principals collection.

Author
Craig R. McClanahan

Field Summary

Modifier and TypeField and Description
private final Map<String, String>
credentials

The set of credentials for this Realm, keyed by user name.

private static Digester
digester

The Digester we will use to process in-memory database files.

private static final Object
private static final Log
private String
pathname

The pathname (absolute or relative to Catalina's current working directory) of the XML file containing our database information.

private final Map<String, GenericPrincipal>
principals

The set of valid Principals for this Realm, keyed by user name.

Inherited from org.apache.catalina.realm.RealmBase:
allRolesModecontainercontainerLogrealmPathsmstripRealmForGsssupportUSER_ATTRIBUTES_DELIMITERUSER_ATTRIBUTES_WILDCARDuserAttributesuserAttributesListvalidatex509UsernameRetrieverx509UsernameRetrieverClassName

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addUser(String
User's username
username
,
String
User's password (clear text)
password
,
String
Comma-delimited set of roles associated with this user
roles
)

Add a new user to the in-memory database.

public Principal
authenticate(String
Username of the Principal to look up
username
,
String
Password or other credentials to use in authenticating this username
credentials
)

Overrides org.apache.catalina.realm.RealmBase.authenticate.

Implements org.apache.catalina.Realm.authenticate.

Try to authenticate using the specified username and credentials.

protected Digester

Returns:

a configured Digester to use for processing the XML input file, creating a new one if necessary.
getDigester
()

protected String
getPassword(String
The user name
username
)

Implements abstract org.apache.catalina.realm.RealmBase.getPassword.

Get the password for the specified user.

public String

Returns:

the pathname of our XML file containing user definitions.
getPathname
()

protected Principal
getPrincipal(String
The user name
username
)

Implements abstract org.apache.catalina.realm.RealmBase.getPrincipal.

Get the principal associated with the specified user.

public void
setPathname(String
The new pathname
pathname
)

Set the pathname of our XML file containing user definitions.

protected void
startInternal()

Overrides org.apache.catalina.realm.RealmBase.startInternal.

Prepare for the beginning of active use of the public methods of this component and implement the requirements of org.apache.catalina.util.LifecycleBase#startInternal().

Inherited from org.apache.catalina.realm.RealmBase:
addPropertyChangeListenerauthenticateauthenticateauthenticateauthenticateauthenticateauthenticatebackgroundProcessfindSecurityConstraintsgetAllRolesModegetContainergetCredentialHandlergetDigestgetDigestgetDomainInternalgetObjectNameKeyPropertiesgetPrincipalgetPrincipalgetRealmPathgetRealmSuffixgetServergetTransportGuaranteeRedirectStatusgetUserAttributesgetValidategetX509UsernameRetrieverClassNamehasMessageDigesthasResourcePermissionhasRolehasRoleInternalhasUserDataPermissioninitInternalisStripRealmForGssmainparseUserAttributesremovePropertyChangeListenersetAllRolesModesetContainersetCredentialHandlersetRealmPathsetStripRealmForGsssetTransportGuaranteeRedirectStatussetUserAttributessetValidatesetX509UsernameRetrieverClassNamestopInternaltoString

Field Detail

credentialsback to summary
private final Map<String, String> credentials

The set of credentials for this Realm, keyed by user name.

digesterback to summary
private static Digester digester

The Digester we will use to process in-memory database files.

digesterLockback to summary
private static final Object digesterLock
logback to summary
private static final Log log

Hides org.apache.catalina.realm.RealmBase.log.

pathnameback to summary
private String pathname

The pathname (absolute or relative to Catalina's current working directory) of the XML file containing our database information.

principalsback to summary
private final Map<String, GenericPrincipal> principals

The set of valid Principals for this Realm, keyed by user name.

Constructor Detail

MemoryRealmback to summary
public MemoryRealm()

Method Detail

addUserback to summary
pack-priv void addUser(String username, String password, String roles)

Add a new user to the in-memory database.

Parameters
username:String

User's username

password:String

User's password (clear text)

roles:String

Comma-delimited set of roles associated with this user

authenticateback to summary
public Principal authenticate(String username, String credentials)

Overrides org.apache.catalina.realm.RealmBase.authenticate.

Implements org.apache.catalina.Realm.authenticate.

Doc from org.apache.catalina.Realm.authenticate.

Try to authenticate using the specified username and credentials.

Parameters
username:String

Username of the Principal to look up

credentials:String

Password or other credentials to use in authenticating this username

Returns:Principal

the associated principal, or null if there is none

Annotations
@Override
getDigesterback to summary
protected Digester getDigester()
Returns:Digester

a configured Digester to use for processing the XML input file, creating a new one if necessary.

getPasswordback to summary
protected String getPassword(String username)

Implements abstract org.apache.catalina.realm.RealmBase.getPassword.

Doc from org.apache.catalina.realm.RealmBase.getPassword.

Get the password for the specified user.

Parameters
username:String

The user name

Returns:String

the password associated with the given principal's user name.

Annotations
@Override
getPathnameback to summary
public String getPathname()
Returns:String

the pathname of our XML file containing user definitions.

getPrincipalback to summary
protected Principal getPrincipal(String username)

Implements abstract org.apache.catalina.realm.RealmBase.getPrincipal.

Doc from org.apache.catalina.realm.RealmBase.getPrincipal.

Get the principal associated with the specified user.

Parameters
username:String

The user name

Returns:Principal

the Principal associated with the given user name.

Annotations
@Override
setPathnameback to summary
public void setPathname(String pathname)

Set the pathname of our XML file containing user definitions. If a relative pathname is specified, it is resolved against "catalina.base".

Parameters
pathname:String

The new pathname

startInternalback to summary
protected void startInternal() throws LifecycleException

Overrides org.apache.catalina.realm.RealmBase.startInternal.

Doc from org.apache.catalina.realm.RealmBase.startInternal.

Prepare for the beginning of active use of the public methods of this component and implement the requirements of org.apache.catalina.util.LifecycleBase#startInternal().

Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that prevents this component from being used