public abstract class RealmBase extends LifecycleMBeanBase implements Realm
| Modifier and Type | Class and Description |
|---|---|
protected static class |
RealmBase.AllRolesMode |
Lifecycle.SingleUse| Modifier and Type | Field 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
|
protected java.lang.String |
realmPath |
protected static StringManager |
sm
The string manager for this package.
|
protected boolean |
stripRealmForGss
When processing users authenticated via the GSS-API, should any "@...
|
protected java.beans.PropertyChangeSupport |
support
The property change support for this component.
|
protected static java.lang.String |
USER_ATTRIBUTES_DELIMITER
The character used for delimiting user attribute names.
|
protected static java.lang.String |
USER_ATTRIBUTES_WILDCARD
The character used as wildcard in user attribute lists.
|
protected java.lang.String |
userAttributes
The comma separated names of user attributes to additionally query from the realm.
|
protected java.util.List<java.lang.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 java.lang.String |
x509UsernameRetrieverClassName
The name of the class to use for retrieving user names from X509 certificates.
|
mserverAFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT| Constructor and Description |
|---|
RealmBase() |
| Modifier and Type | Method and Description |
|---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component.
|
java.security.Principal |
authenticate(org.ietf.jgss.GSSContext gssContext,
boolean storeCred)
Try to authenticate using a
GSSContext. |
java.security.Principal |
authenticate(org.ietf.jgss.GSSName gssName,
org.ietf.jgss.GSSCredential gssCredential)
Try to authenticate using a
GSSName. |
java.security.Principal |
authenticate(java.lang.String username)
Try to authenticate with the specified username.
|
java.security.Principal |
authenticate(java.lang.String username,
java.lang.String credentials)
Try to authenticate using the specified username and
credentials.
|
java.security.Principal |
authenticate(java.lang.String username,
java.lang.String clientDigest,
java.lang.String nonce,
java.lang.String nc,
java.lang.String cnonce,
java.lang.String qop,
java.lang.String realm,
java.lang.String digestA2)
Deprecated.
|
java.security.Principal |
authenticate(java.lang.String username,
java.lang.String clientDigest,
java.lang.String nonce,
java.lang.String nc,
java.lang.String cnonce,
java.lang.String qop,
java.lang.String realm,
java.lang.String digestA2,
java.lang.String algorithm)
Try to authenticate with the specified username, which
matches the digest calculated using the given parameters using the
method described in RFC 7616.
|
java.security.Principal |
authenticate(java.security.cert.X509Certificate[] certs)
Try to authenticate using a chain of
X509Certificates. |
void |
backgroundProcess()
Execute a periodic task, such as reloading, etc.
|
SecurityConstraint[] |
findSecurityConstraints(Request request,
Context context)
Find the SecurityConstraints configured to guard the request URI for
this request.
|
java.lang.String |
getAllRolesMode()
Return the all roles mode.
|
Container |
getContainer()
Get the
Container with which this instance is associated. |
CredentialHandler |
getCredentialHandler() |
protected java.lang.String |
getDigest(java.lang.String username,
java.lang.String realmName)
Deprecated.
Unused. Use
getDigest(String, String, String). Will be removed in Tomcat 11. |
protected java.lang.String |
getDigest(java.lang.String username,
java.lang.String realmName,
java.lang.String algorithm)
Return the digest associated with given principal's user name.
|
java.lang.String |
getDomainInternal()
Method implemented by sub-classes to identify the domain in which MBeans
should be registered.
|
java.lang.String |
getObjectNameKeyProperties()
Allow sub-classes to specify the key properties component of the
ObjectName that will be used to register this component. |
protected abstract java.lang.String |
getPassword(java.lang.String username)
Get the password for the specified user.
|
protected java.security.Principal |
getPrincipal(org.ietf.jgss.GSSName gssName,
org.ietf.jgss.GSSCredential gssCredential)
Get the principal associated with the specified
GSSName. |
protected abstract java.security.Principal |
getPrincipal(java.lang.String username)
Get the principal associated with the specified user.
|
protected java.security.Principal |
getPrincipal(java.lang.String username,
org.ietf.jgss.GSSCredential gssCredential)
Deprecated.
This will be removed in Tomcat 10 onwards. Use
getPrincipal(GSSName, GSSCredential) instead. |
protected java.security.Principal |
getPrincipal(java.security.cert.X509Certificate usercert)
Get the principal associated with the specified certificate.
|
java.lang.String |
getRealmPath() |
protected java.lang.String |
getRealmSuffix() |
java.lang.String[] |
getRoles(java.security.Principal principal)
Return roles associated with given principal
|
protected Server |
getServer()
Return the Server object that is the ultimate parent for the container with which this Realm is associated.
|
int |
getTransportGuaranteeRedirectStatus() |
java.lang.String |
getUserAttributes() |
boolean |
getValidate()
Return the "validate certificate chains" flag.
|
java.lang.String |
getX509UsernameRetrieverClassName()
Gets the name of the class that will be used to extract user names from X509 client certificates.
|
protected boolean |
hasMessageDigest(java.lang.String algorithm) |
boolean |
hasResourcePermission(Request request,
Response response,
SecurityConstraint[] constraints,
Context context)
Perform access control based on the specified authorization constraint.
|
boolean |
hasRole(Wrapper wrapper,
java.security.Principal principal,
java.lang.String role)
Check if the specified Principal has the specified
security role, within the context of this Realm.
|
protected boolean |
hasRoleInternal(java.security.Principal principal,
java.lang.String role)
Check if the specified Principal has the specified security role, within the context of this Realm.
|
boolean |
hasUserDataPermission(Request request,
Response response,
SecurityConstraint[] constraints)
Enforce any user data constraint required by the security constraint
guarding this request URI.
|
protected void |
initInternal()
Sub-classes wishing to perform additional initialization should override
this method, ensuring that super.initInternal() is the first call in the
overriding method.
|
boolean |
isStripRealmForGss() |
static void |
main(java.lang.String[] args)
Generate a stored credential string for the given password and associated parameters.
|
protected java.util.List<java.lang.String> |
parseUserAttributes(java.lang.String userAttributes)
Parse the specified delimiter separated attribute names and return a list of that names or
null, if
no attributes have been specified. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component.
|
void |
setAllRolesMode(java.lang.String allRolesMode)
Set the all roles mode.
|
void |
setContainer(Container container)
Set the
Container with which this instance is associated. |
void |
setCredentialHandler(CredentialHandler credentialHandler)
Set the CredentialHandler to be used by this Realm.
|
void |
setRealmPath(java.lang.String theRealmPath) |
void |
setStripRealmForGss(boolean stripRealmForGss) |
void |
setTransportGuaranteeRedirectStatus(int 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.
|
void |
setUserAttributes(java.lang.String userAttributes)
Set the comma separated names of user attributes to additionally query from the realm.
|
void |
setValidate(boolean validate)
Set the "validate certificate chains" flag.
|
void |
setX509UsernameRetrieverClassName(java.lang.String className)
Sets the name of the class that will be used to extract user names from X509 client certificates.
|
protected void |
startInternal()
Prepare for the beginning of active use of the public methods of this component and implement the requirements of
LifecycleBase.startInternal(). |
protected void |
stopInternal()
Gracefully terminate the active use of the public methods of this component and implement the requirements of
LifecycleBase.stopInternal(). |
java.lang.String |
toString() |
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisteraddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisAvailableprotected static final java.lang.String USER_ATTRIBUTES_DELIMITER
Applies to some of the Realm implementations only.
protected static final java.lang.String USER_ATTRIBUTES_WILDCARD
Applies to some of the Realm implementations only.
protected Container container
protected Log containerLog
protected static final StringManager sm
protected final java.beans.PropertyChangeSupport support
protected boolean validate
protected java.lang.String x509UsernameRetrieverClassName
protected X509UsernameRetriever x509UsernameRetriever
protected RealmBase.AllRolesMode allRolesMode
protected boolean stripRealmForGss
protected java.lang.String userAttributes
protected java.util.List<java.lang.String> userAttributesList
protected java.lang.String realmPath
public int getTransportGuaranteeRedirectStatus()
public void setTransportGuaranteeRedirectStatus(int transportGuaranteeRedirectStatus)
transportGuaranteeRedirectStatus - The status to use. This value is not validatedpublic CredentialHandler getCredentialHandler()
getCredentialHandler in interface Realmpublic void setCredentialHandler(CredentialHandler credentialHandler)
RealmsetCredentialHandler in interface RealmcredentialHandler - the CredentialHandler to usepublic Container getContainer()
ContainedContainer with which this instance is associated.getContainer in interface Containednull if not associated with a Containerpublic void setContainer(Container container)
ContainedContainer with which this instance is associated.setContainer in interface Containedcontainer - The Container instance with which this instance is to
be associated, or null to disassociate this instance
from any Containerpublic java.lang.String getAllRolesMode()
public void setAllRolesMode(java.lang.String allRolesMode)
allRolesMode - A string representation of the new all roles modepublic boolean getValidate()
public void setValidate(boolean validate)
validate - The new validate certificate chains flagpublic java.lang.String getX509UsernameRetrieverClassName()
public void setX509UsernameRetrieverClassName(java.lang.String className)
className - The name of the class that will be used to extract user names from X509 client certificates.X509UsernameRetrieverpublic boolean isStripRealmForGss()
public void setStripRealmForGss(boolean stripRealmForGss)
public java.lang.String getUserAttributes()
public void setUserAttributes(java.lang.String userAttributes)
If set to the wildcard character, or, if the wildcard character is part of the comma separated list, all
available attributes - except the password attribute (as specified by userCredCol) - are
queried. The wildcard character is defined by constant USER_ATTRIBUTES_WILDCARD. It defaults to
the asterisk (*) character.
userAttributes - the comma separated names of user attributespublic void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
RealmaddPropertyChangeListener in interface Realmlistener - The listener to addpublic java.security.Principal authenticate(java.lang.String username)
Realmauthenticate in interface Realmusername - Username of the Principal to look upnull if none is associated.public java.security.Principal authenticate(java.lang.String username,
java.lang.String credentials)
Realmauthenticate in interface Realmusername - Username of the Principal to look upcredentials - Password or other credentials to use in
authenticating this usernamenull if there is none@Deprecated
public java.security.Principal authenticate(java.lang.String username,
java.lang.String clientDigest,
java.lang.String nonce,
java.lang.String nc,
java.lang.String cnonce,
java.lang.String qop,
java.lang.String realm,
java.lang.String digestA2)
Realmauthenticate in interface Realmusername - Username of the Principal to look upclientDigest - Digest which has been submitted by the clientnonce - Unique (or supposedly unique) token which has been used
for this requestnc - the nonce countercnonce - the client chosen nonceqop - the "quality of protection" (nc and cnonce
will only be used, if qop is not null).realm - Realm namedigestA2 - Second digest calculated as digest(Method + ":" + uri)null if there is none.public java.security.Principal authenticate(java.lang.String username,
java.lang.String clientDigest,
java.lang.String nonce,
java.lang.String nc,
java.lang.String cnonce,
java.lang.String qop,
java.lang.String realm,
java.lang.String digestA2,
java.lang.String algorithm)
Realm
The default implementation calls Realm.authenticate(String, String,
String, String, String, String, String, String) for backwards
compatibility which effectively forces the use of MD5 regardless of the
algorithm specified in the call to this method.
Implementations are expected to override the default implementation and take account of the algorithm parameter.
authenticate in interface Realmusername - Username of the Principal to look upclientDigest - Digest which has been submitted by the clientnonce - Unique (or supposedly unique) token which has been used
for this requestnc - the nonce countercnonce - the client chosen nonceqop - the "quality of protection" (nc and cnonce
will only be used, if qop is not null).realm - Realm namedigestA2 - Second digest calculated as digest(Method + ":" + uri)algorithm - The message digest algorithm to usenull if there is none.public java.security.Principal authenticate(java.security.cert.X509Certificate[] certs)
RealmX509Certificates.authenticate in interface Realmcerts - Array of client certificates, with the first one in
the array being the certificate of the client itself.null if there is nonepublic java.security.Principal authenticate(org.ietf.jgss.GSSContext gssContext,
boolean storeCred)
RealmGSSContext.authenticate in interface RealmgssContext - The gssContext processed by the Authenticator.storeCred - Should the realm attempt to store the delegated
credentials in the returned Principal?null if there is nonepublic java.security.Principal authenticate(org.ietf.jgss.GSSName gssName,
org.ietf.jgss.GSSCredential gssCredential)
RealmGSSName.
Note that this default method will be turned into an abstract one in
Tomcat 10.authenticate in interface RealmgssName - The GSSName of the principal to look upgssCredential - The GSSCredential of the principal, may be
nullnull if there is nonepublic void backgroundProcess()
The default implementation is NO-OP.
backgroundProcess in interface Realmpublic SecurityConstraint[] findSecurityConstraints(Request request, Context context)
RealmfindSecurityConstraints in interface Realmrequest - Request we are processingcontext - Context the Request is mapped toSecurityConstraint, or null if
there is nonepublic boolean hasResourcePermission(Request request, Response response, SecurityConstraint[] constraints, Context context) throws java.io.IOException
RealmhasResourcePermission in interface Realmrequest - Request we are processingresponse - Response we are creatingconstraints - Security constraint we are enforcingcontext - The Context to which client of this class is attached.true if this constraint is satisfied and processing
should continue, or false otherwisejava.io.IOException - if an input/output error occurspublic boolean hasRole(Wrapper wrapper, java.security.Principal principal, java.lang.String role)
This method or hasRoleInternal(Principal, String) can be overridden by Realm implementations, but the
default is adequate when an instance of GenericPrincipal is used to represent authenticated
Principals from this Realm.
hasRole in interface Realmwrapper - wrapper context for evaluating roleprincipal - Principal for whom the role is to be checkedrole - Security role to be checkedtrue if the specified Principal has the specified
security role, within the context of this Realm; otherwise return
false.protected java.util.List<java.lang.String> parseUserAttributes(java.lang.String userAttributes)
null, if
no attributes have been specified.
If a wildcard character is found, return a list consisting of a single wildcard character only.
userAttributes - comma separated names of attributes to parsenull, if no attributes have been specifiedprotected boolean hasRoleInternal(java.security.Principal principal,
java.lang.String role)
hasRoleInternal(Principal, String) can be overridden by Realm implementations, but the default is
adequate when an instance of GenericPrincipal is used to represent authenticated Principals from
this Realm.principal - Principal for whom the role is to be checkedrole - Security role to be checkedtrue if the specified Principal has the specified security role, within the context of this
Realm; otherwise return false.public boolean hasUserDataPermission(Request request, Response response, SecurityConstraint[] constraints) throws java.io.IOException
RealmhasUserDataPermission in interface Realmrequest - Request we are processingresponse - Response we are creatingconstraints - Security constraint being checkedtrue if this constraint
was not violated and processing should continue, or false
if we have created a response already.java.io.IOException - if an input/output error occurspublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
RealmremovePropertyChangeListener in interface Realmlistener - The listener to removeprotected void initInternal()
throws LifecycleException
LifecycleMBeanBaseinitInternal in class LifecycleMBeanBaseLifecycleException - If the initialisation failsprotected void startInternal()
throws LifecycleException
LifecycleBase.startInternal().startInternal in class LifecycleBaseLifecycleException - if this component detects a fatal error that prevents this component from being
usedprotected void stopInternal()
throws LifecycleException
LifecycleBase.stopInternal().stopInternal in class LifecycleBaseLifecycleException - if this component detects a fatal error that needs to be reportedpublic java.lang.String toString()
toString in class java.lang.Objectprotected boolean hasMessageDigest(java.lang.String algorithm)
@Deprecated
protected java.lang.String getDigest(java.lang.String username,
java.lang.String realmName)
getDigest(String, String, String). Will be removed in Tomcat 11.username - The user namerealmName - The realm nameprotected java.lang.String getDigest(java.lang.String username,
java.lang.String realmName,
java.lang.String algorithm)
username - The user namerealmName - The realm namealgorithm - The name of the message digest algorithm to useprotected abstract java.lang.String getPassword(java.lang.String username)
username - The user nameprotected java.security.Principal getPrincipal(java.security.cert.X509Certificate usercert)
usercert - The user certificateprotected abstract java.security.Principal getPrincipal(java.lang.String username)
username - The user name@Deprecated
protected java.security.Principal getPrincipal(java.lang.String username,
org.ietf.jgss.GSSCredential gssCredential)
getPrincipal(GSSName, GSSCredential) instead.username - The user namegssCredential - the GSS credential of the principalprotected java.security.Principal getPrincipal(org.ietf.jgss.GSSName gssName,
org.ietf.jgss.GSSCredential gssCredential)
GSSName.gssName - The GSS namegssCredential - the GSS credential of the principalprotected Server getServer()
null is returned.public static void main(java.lang.String[] args)
The following parameters are supported:
Charset.defaultCharset()) will be used.This generation process currently supports the following CredentialHandlers, the correct one being selected based on the algorithm specified:
args - The parameters passed on the command linepublic java.lang.String getObjectNameKeyProperties()
LifecycleMBeanBaseObjectName that will be used to register this component.getObjectNameKeyProperties in class LifecycleMBeanBaseObjectNamepublic java.lang.String getDomainInternal()
LifecycleMBeanBasegetDomainInternal in class LifecycleMBeanBasepublic java.lang.String getRealmPath()
public void setRealmPath(java.lang.String theRealmPath)
protected java.lang.String getRealmSuffix()
Copyright © 2000-2024 Apache Software Foundation.
Apache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo are either registered trademarks or trademarks of the Apache Software Foundation.