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

public abstract Class RealmBase

extends LifecycleMBeanBase
implements Realm
Class Inheritance
All Implemented Interfaces
org.apache.catalina.Realm, org.apache.catalina.Contained
Known Direct Subclasses
org.apache.catalina.realm.UserDatabaseRealm, org.apache.catalina.startup.Tomcat.SimpleRealm, org.apache.catalina.realm.AuthenticatedUserRealm, org.apache.catalina.realm.CombinedRealm, org.apache.catalina.realm.DataSourceRealm, org.apache.catalina.realm.JAASRealm, org.apache.catalina.realm.JNDIRealm, org.apache.catalina.realm.MemoryRealm, org.apache.catalina.realm.NullRealm
Imports
java.beans.PropertyChangeListener, .PropertyChangeSupport, java.io.IOException, .UnsupportedEncodingException, java.nio.charset.Charset, .StandardCharsets, java.security.NoSuchAlgorithmException, .Principal, java.security.cert.X509Certificate, java.util.ArrayList, .Collections, .List, .Locale, jakarta.servlet.annotation.ServletSecurity.TransportGuarantee, jakarta.servlet.http.HttpServletResponse, org.apache.catalina.Container, .Context, .CredentialHandler, .Engine, .Host, .LifecycleException, .LifecycleState, .Realm, .Server, .Service, .Wrapper, org.apache.catalina.connector.Request, .Response, org.apache.catalina.util.LifecycleMBeanBase, .SessionConfig, .ToStringUtil, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.IntrospectionUtils, org.apache.tomcat.util.buf.B2CConverter, .HexUtils, org.apache.tomcat.util.descriptor.web.SecurityCollection, .SecurityConstraint, org.apache.tomcat.util.res.StringManager, org.apache.tomcat.util.security.ConcurrentMessageDigest, org.ietf.jgss.GSSContext, .GSSCredential, .GSSException, .GSSName

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.
Author
Craig R. McClanahan

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
protected RealmBase.AllRolesMode
allRolesMode

The all role mode.

protected Container
container

The Container with which this Realm is associated.

protected Log
containerLog

Container log

private CredentialHandler
private static final List<Class<? extends DigestCredentialHandlerBase>>
private static final Log
protected String
protected static final StringManager
sm

Hides org.apache.catalina.util.LifecycleMBeanBase.sm.

The string manager for this package.
protected boolean
stripRealmForGss

When processing users authenticated via the GSS-API, should any "@...

protected final PropertyChangeSupport
support

The property change support for this component.

private int
protected static final String
USER_ATTRIBUTES_DELIMITER

The character used for delimiting user attribute names.

protected static final String
USER_ATTRIBUTES_WILDCARD

The character used as wildcard in user attribute lists.

protected String
userAttributes

The comma separated names of user attributes to additionally query from the realm.

protected List<String>
userAttributesList

The list of user attributes to additionally query from the realm.

protected boolean
validate

Should we validate client certificate chains when they are presented?

protected X509UsernameRetriever
x509UsernameRetriever

The object that will extract user names from X509 client certificates.

protected String
x509UsernameRetrieverClassName

The name of the class to use for retrieving user names from X509 certificates.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addPropertyChangeListener(PropertyChangeListener
The listener to add
listener
)

Implements org.apache.catalina.Realm.addPropertyChangeListener.

Add a property change listener to this component.

public Principal
authenticate(String
Username of the Principal to look up
username
)

Implements org.apache.catalina.Realm.authenticate.

Try to authenticate with the specified username.

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

Implements org.apache.catalina.Realm.authenticate.

Try to authenticate using the specified username and credentials.

public Principal
authenticate(String
Username of the Principal to look up
username
,
String
Digest which has been submitted by the client
clientDigest
,
String
Unique (or supposedly unique) token which has been used for this request
nonce
,
String
the nonce counter
nc
,
String
the client chosen nonce
cnonce
,
String
the "quality of protection" (nc and cnonce will only be used, if qop is not null).
qop
,
String
Realm name
realm
,
String
Second digest calculated as digest(Method + ":" + uri)
digestA2
)

Implements org.apache.catalina.Realm.authenticate.

Deprecated

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 2617 (which is a superset of RFC 2069).

public Principal
authenticate(String
Username of the Principal to look up
username
,
String
Digest which has been submitted by the client
clientDigest
,
String
Unique (or supposedly unique) token which has been used for this request
nonce
,
String
the nonce counter
nc
,
String
the client chosen nonce
cnonce
,
String
the "quality of protection" (nc and cnonce will only be used, if qop is not null).
qop
,
String
Realm name
realm
,
String
Second digest calculated as digest(Method + ":" + uri)
digestA2
,
String
The message digest algorithm to use
algorithm
)

Overrides default org.apache.catalina.Realm.authenticate.

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 7616.

public Principal
authenticate(X509Certificate[]
Array of client certificates, with the first one in the array being the certificate of the client itself.
certs
)

Implements org.apache.catalina.Realm.authenticate.

Try to authenticate using a chain of X509Certificates.

public Principal
authenticate(GSSContext
The gssContext processed by the Authenticator.
gssContext
,
boolean
Should the realm attempt to store the delegated credentials in the returned Principal?
storeCred
)

Implements org.apache.catalina.Realm.authenticate.

Try to authenticate using a GSSContext.

public Principal
authenticate(GSSName
The GSSName of the principal to look up
gssName
,
GSSCredential
The GSSCredential of the principal, may be null
gssCredential
)

Implements org.apache.catalina.Realm.authenticate.

Try to authenticate using a GSSName.

public void
backgroundProcess()

Implements org.apache.catalina.Realm.backgroundProcess.

Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container.

private static X509UsernameRetriever
public SecurityConstraint[]
findSecurityConstraints(Request
Request we are processing
request
,
Context
Context the Request is mapped to
context
)

Implements org.apache.catalina.Realm.findSecurityConstraints.

Find the SecurityConstraints configured to guard the request URI for this request.

public String

Returns:

A string representation of the current all roles mode
getAllRolesMode
()

Return the all roles mode.

public Container
getContainer()

Implements org.apache.catalina.Contained.getContainer.

Get the Container with which this instance is associated.

public CredentialHandler
protected String

Returns:

the digest for the specified user
getDigest
(String
The user name
username
,
String
The realm name
realmName
)
Deprecated Unused. Use getDigest(String, String, String). Will be removed in Tomcat 11.

Return the digest associated with given principal's user name.

protected String

Returns:

the digest for the specified user
getDigest
(String
The user name
username
,
String
The realm name
realmName
,
String
The name of the message digest algorithm to use
algorithm
)

Return the digest associated with given principal's user name.

private Charset
private String
public String
getDomainInternal()

Implements abstract org.apache.catalina.util.LifecycleMBeanBase.getDomainInternal.

Method implemented by sub-classes to identify the domain in which MBeans should be registered.

public String
getObjectNameKeyProperties()

Implements abstract org.apache.catalina.util.LifecycleMBeanBase.getObjectNameKeyProperties.

Allow sub-classes to specify the key properties component of the ObjectName that will be used to register this component.

protected abstract String

Returns:

the password associated with the given principal's user name.
getPassword
(String
The user name
username
)

Get the password for the specified user.

protected Principal

Returns:

the Principal associated with the given certificate.
getPrincipal
(X509Certificate
The user certificate
usercert
)

Get the principal associated with the specified certificate.

protected abstract Principal

Returns:

the Principal associated with the given user name.
getPrincipal
(String
The user name
username
)

Get the principal associated with the specified user.

protected Principal

Returns:

the principal associated with the given user name.
getPrincipal
(GSSName
The GSS name
gssName
,
GSSCredential
the GSS credential of the principal
gssCredential
)

Get the principal associated with the specified GSSName.

public String
protected String
protected Server

Returns:

the Server associated with the realm
getServer
()

Return the Server object that is the ultimate parent for the container with which this Realm is associated.

public int

Returns:

The HTTP status code used when the container needs to issue an HTTP redirect to meet the requirements of a configured transport guarantee.
getTransportGuaranteeRedirectStatus
()

public String

Returns:

the comma separated names of user attributes to additionally query from realm
getUserAttributes
()

public boolean

Returns:

The value of the validate certificate chains flag
getValidate
()

Return the "validate certificate chains" flag.

public String

Returns:

The name of the class that will be used to extract user names from X509 client certificates.
getX509UsernameRetrieverClassName
()

Gets the name of the class that will be used to extract user names from X509 client certificates.

protected boolean
public boolean
hasResourcePermission(Request
Request we are processing
request
,
Response
Response we are creating
response
,
SecurityConstraint[]
Security constraint we are enforcing
constraints
,
Context
The Context to which client of this class is attached.
context
)

Implements org.apache.catalina.Realm.hasResourcePermission.

Perform access control based on the specified authorization constraint.

public boolean
hasRole(Wrapper
wrapper context for evaluating role
wrapper
,
Principal
Principal for whom the role is to be checked
principal
,
String
Security role to be checked
role
)

Implements org.apache.catalina.Realm.hasRole.

Check if the specified Principal has the specified security role, within the context of this Realm.

protected boolean

Returns:

true if the specified Principal has the specified security role, within the context of this Realm; otherwise return false.
hasRoleInternal
(Principal
Principal for whom the role is to be checked
principal
,
String
Security role to be checked
role
)

Check if the specified Principal has the specified security role, within the context of this Realm.

public boolean
hasUserDataPermission(Request
Request we are processing
request
,
Response
Response we are creating
response
,
SecurityConstraint[]
Security constraint being checked
constraints
)

Implements org.apache.catalina.Realm.hasUserDataPermission.

Enforce any user data constraint required by the security constraint guarding this request URI.

protected void
initInternal()

Overrides org.apache.catalina.util.LifecycleMBeanBase.initInternal.

Sub-classes wishing to perform additional initialization should override this method, ensuring that super.initInternal() is the first call in the overriding method.

public boolean
public static void
main(String[]
The parameters passed on the command line
args
)

Generate a stored credential string for the given password and associated parameters.

protected List<String>

Returns:

a list containing the parsed attribute names or null, if no attributes have been specified
parseUserAttributes
(String
comma separated names of attributes to parse
userAttributes
)

Parse the specified delimiter separated attribute names and return a list of that names or null, if no attributes have been specified.

public void
removePropertyChangeListener(PropertyChangeListener
The listener to remove
listener
)

Implements org.apache.catalina.Realm.removePropertyChangeListener.

Remove a property change listener from this component.

private SecurityConstraint[]
resultsToArray(ArrayList<SecurityConstraint> results)

Convert an ArrayList to a SecurityConstraint [].

public void
setAllRolesMode(String
A string representation of the new all roles mode
allRolesMode
)

Set the all roles mode.

public void
setContainer(Container
The Container instance with which this instance is to be associated, or null to disassociate this instance from any Container
container
)

Implements org.apache.catalina.Contained.setContainer.

Set the Container with which this instance is associated.

public void
setCredentialHandler(CredentialHandler credentialHandler)

Implements org.apache.catalina.Realm.setCredentialHandler.

Set the CredentialHandler to be used by this Realm.

public void
setRealmPath(String theRealmPath)

public void
setStripRealmForGss(boolean stripRealmForGss)

public void
setTransportGuaranteeRedirectStatus(int
The status to use. This value is not validated
transportGuaranteeRedirectStatus
)

Set the HTTP status code used when the container needs to issue an HTTP redirect to meet the requirements of a configured transport guarantee.

public void
setUserAttributes(String
the comma separated names of user attributes
userAttributes
)

Set the comma separated names of user attributes to additionally query from the realm.

public void
setValidate(boolean
The new validate certificate chains flag
validate
)

Set the "validate certificate chains" flag.

public void
setX509UsernameRetrieverClassName(String
The name of the class that will be used to extract user names from X509 client certificates.
className
)

Sets the name of the class that will be used to extract user names from X509 client certificates.

protected void
startInternal()

Implements abstract org.apache.catalina.util.LifecycleBase.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().

protected void
stopInternal()

Implements abstract org.apache.catalina.util.LifecycleBase.stopInternal.

Gracefully terminate the active use of the public methods of this component and implement the requirements of org.apache.catalina.util.LifecycleBase#stopInternal().

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private static void
Inherited from org.apache.catalina.util.LifecycleMBeanBase:
destroyInternalgetDomaingetObjectNamepostDeregisterpostRegisterpreDeregisterpreRegisterregistersetDomainunregisterunregister