public abstract class RealmBase extends Object implements Lifecycle, Realm
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
checkIfRequestIsSecure
Flag indicating whether a check to see if the request is secure is required before adding Pragma and Cache-Control
headers when proxy caching has been disabled
|
protected Container |
container
The Container with which this Realm is associated.
|
protected ObjectName |
controller |
protected int |
debug
The debugging detail level for this component.
|
protected String |
digest
Digest algorithm used in storing passwords in a non-plaintext format.
|
protected String |
digestEncoding
The encoding charset for the digest.
|
protected static String |
info
Descriptive information about this Realm implementation.
|
protected LifecycleSupport |
lifecycle
The lifecycle event support for this component.
|
protected static Logger |
log |
protected MessageDigest |
md
The MessageDigest object for digesting user credentials (passwords).
|
protected static MD5Encoder |
md5Encoder
The MD5 helper object for this class.
|
protected static MessageDigest |
md5Helper
MD5 message digest provider.
|
protected static ResourceBundle |
rb |
protected boolean |
started
Has this component been started?
|
protected PropertyChangeSupport |
support
The property change support for this component.
|
protected boolean |
validate
Should we validate client certificate chains when they are presented?
|
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENTAUTHENTICATE_NEEDED, AUTHENTICATE_NOT_NEEDED, AUTHENTICATED_NOT_AUTHORIZED| Constructor and Description |
|---|
RealmBase() |
| Modifier and Type | Method and Description |
|---|---|
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Add a property change listener to this component.
|
Principal |
authenticate(javax.servlet.http.HttpServletRequest hreq)
Does digest authentication and returns the Principal associated with the username in the HTTP header.
|
Principal |
authenticate(String username,
char[] credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return
null. |
Principal |
authenticate(String username,
char[] clientDigest,
String nOnce,
String nc,
String cnonce,
String qop,
String realm,
char[] md5a2)
Return the Principal associated with the specified username, which matches the digest calculated using the given
parameters using the method described in RFC 2069; otherwise return
null. |
Principal |
authenticate(X509Certificate[] certificates)
Return the Principal associated with the specified chain of X509 client certificates.
|
void |
backgroundProcess()
Execute a periodic task, such as reloading, etc.
|
void |
destroy() |
protected char[] |
digest(char[] credentials)
Digest the password using the specified algorithm and convert the result to a corresponding hexadecimal string.
|
protected void |
disableProxyCaching(HttpRequest request,
HttpResponse response,
boolean disableProxyCaching,
boolean securePagesWithPragma) |
List<LifecycleListener> |
findLifecycleListeners()
Gets the (possibly empty) list of lifecycle listeners associated with this Realm.
|
SecurityConstraint[] |
findSecurityConstraints(HttpRequest request,
Context context)
Return the SecurityConstraints configured to guard the request URI for this request, or
null if there is
no such constraint. |
SecurityConstraint[] |
findSecurityConstraints(String uri,
String method,
Context context)
Gets the security constraints configured by the given context for the given request URI and method.
|
String |
getAlternateAuthType(HttpRequest req)
Return an alternate auth type from the request if available.
|
Principal |
getAlternatePrincipal(HttpRequest req)
Return an alternate principal from the request if available.
|
Container |
getContainer()
Return the Container with which this Realm has been associated.
|
ObjectName |
getController() |
int |
getDebug()
Return the debugging detail level for this component.
|
String |
getDigest()
Return the digest algorithm used for storing credentials.
|
protected char[] |
getDigest(String username,
String realmName)
Return the digest associated with given principal's user name.
|
String |
getDigestEncoding()
Returns the digest encoding charset.
|
String |
getInfo()
Return descriptive information about this Realm implementation and the corresponding version number, in the format
<description>/<version>. |
protected abstract String |
getName()
Return a short name for this Realm implementation, for use in log messages.
|
protected abstract char[] |
getPassword(String username)
Return the password associated with the given principal's user name.
|
protected abstract Principal |
getPrincipal(String username)
Return the Principal associated with the given user name.
|
String |
getRealmName()
Returns the name of the associated realm.
|
boolean |
getValidate()
Return the "validate certificate chains" flag.
|
protected boolean |
hasMessageDigest() |
boolean |
hasResourcePermission(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints,
Context context)
Perform access control based on the specified authorization constraint.
|
boolean |
hasRole(HttpRequest request,
HttpResponse response,
Principal principal,
String role)
Return
true if the specified Principal has the specified security role, within the context of this
Realm; otherwise return false. |
boolean |
hasRole(Principal principal,
String role)
Return
true if the specified Principal has the specified security role, within the context of this
Realm; otherwise return false. |
boolean |
hasUserDataPermission(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints)
Enforce any user data constraint required by the security constraint guarding this request URI.
|
boolean |
hasUserDataPermission(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints,
String uri,
String method)
Checks if the given request URI and method are the target of any user-data-constraint with a transport-guarantee of
CONFIDENTIAL, and whether any such constraint is already satisfied.
|
boolean |
invokeAuthenticateDelegate(HttpRequest request,
HttpResponse response,
Context context,
Authenticator authenticator,
boolean calledFromAuthenticate)
Authenticates the user making this request, based on the specified login configuration.
|
boolean |
invokePostAuthenticateDelegate(HttpRequest request,
HttpResponse response,
Context context)
Post authentication for given request and response.
|
boolean |
isSecurityExtensionEnabled(javax.servlet.ServletContext servletContext)
Returns whether the specified ServletContext indicates that security extension is enabled.
|
protected void |
log(String message)
Log a message on the Logger associated with our Container (if any)
|
protected void |
log(String message,
Throwable t)
Log a message on the Logger associated with our Container (if any)
|
void |
logout(HttpRequest hreq)
Logs out.
|
int |
preAuthenticateCheck(HttpRequest request,
HttpResponse response,
SecurityConstraint[] constraints,
boolean disableProxyCaching,
boolean securePagesWithPragma,
boolean ssoEnabled)
Checks whether or not authentication is needed.
|
void |
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Remove a property change listener from this component.
|
void |
setContainer(Container container)
Set the Container with which this Realm has been associated.
|
void |
setController(ObjectName controller) |
void |
setDebug(int debug)
Set the debugging detail level for this component.
|
void |
setDigest(String digest)
Set the digest algorithm used for storing credentials.
|
void |
setDigestEncoding(String charset)
Sets the digest encoding charset.
|
void |
setRealmName(String name,
String authMethod)
Set the name of the associated realm.
|
void |
setValidate(boolean validate)
Set the "validate certificate chains" flag.
|
void |
start()
Prepare for the beginning of active use of the public methods of this component.
|
void |
stop()
Gracefully terminate the active use of the public methods of this component.
|
protected static final Logger log
protected static final ResourceBundle rb
protected int debug
protected Container container
protected boolean checkIfRequestIsSecure
protected String digest
null if no digesting should be performed.protected String digestEncoding
protected static final String info
protected LifecycleSupport lifecycle
protected volatile MessageDigest md
protected static final MD5Encoder md5Encoder
protected static volatile MessageDigest md5Helper
protected boolean started
protected PropertyChangeSupport support
protected boolean validate
protected ObjectName controller
public Container getContainer()
getContainer in interface Realmpublic int getDebug()
public void setDebug(int debug)
debug - The new debugging detail levelpublic void setContainer(Container container)
setContainer in interface Realmcontainer - The associated Containerpublic String getDigest()
public void setDigest(String digest)
digest - The new digest algorithmpublic String getDigestEncoding()
public void setDigestEncoding(String charset)
charset - The charset (null for platform default)public String getInfo()
<description>/<version>.public boolean getValidate()
public void setValidate(boolean validate)
validate - The new validate certificate chains flagpublic void addPropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener in interface Realmlistener - The listener to addpublic Principal authenticate(String username, char[] credentials)
null.authenticate in interface Realmusername - Username of the Principal to look upcredentials - Password or other credentials to use in authenticating this usernamepublic Principal authenticate(String username, char[] clientDigest, String nOnce, String nc, String cnonce, String qop, String realm, char[] md5a2)
null.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 requestrealm - Realm namemd5a2 - Second MD5 digest used to calculate the digest : MD5(Method + ":" + uri)public Principal authenticate(X509Certificate[] certificates)
null.authenticate in interface Realmcertificates - Array of client certificates, with the first one in the array being the certificate of the client
itself.public void backgroundProcess()
public SecurityConstraint[] findSecurityConstraints(HttpRequest request, Context context)
null if there is
no such constraint.findSecurityConstraints in interface Realmrequest - Request we are processingcontext - Context the Request is mapped topublic SecurityConstraint[] findSecurityConstraints(String uri, String method, Context context)
findSecurityConstraints in interface Realmuri - the request URI (minus the context Path)method - the request methodcontext - the contextpublic boolean hasResourcePermission(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints, Context context) throws IOException
true if this constraint
is satisfied and processing should continue, or false otherwise.hasResourcePermission 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.IOException - if an input/output error occurspublic boolean hasRole(HttpRequest request, HttpResponse response, Principal principal, String role)
true if the specified Principal has the specified security role, within the context of this
Realm; otherwise return false. This method can be overridden by Realm implementations. The default
implementation is to forward to hasRole(Principal principal, String role).public int preAuthenticateCheck(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints, boolean disableProxyCaching, boolean securePagesWithPragma, boolean ssoEnabled) throws IOException
preAuthenticateCheck in interface Realmrequest - Request we are processingresponse - Response we are creatingconstraints - Security constraint we are enforcingdisableProxyCaching - whether or not to disable proxy caching for protected resources.securePagesWithPragma - true if we add headers which are incompatible with downloading office documents in IE
under SSL but which fix a caching problem in Mozilla.ssoEnabled - true if sso is enabledIOException - if an input/output error occurspublic boolean invokeAuthenticateDelegate(HttpRequest request, HttpResponse response, Context context, Authenticator authenticator, boolean calledFromAuthenticate) throws IOException
true if
any specified requirements have been satisfied, or false if we have created a response challenge
already.invokeAuthenticateDelegate in interface Realmrequest - Request we are processingresponse - Response we are creatingcontext - The Context to which client of this class is attached.authenticator - the current authenticator.calledFromAuthenticate - true if the call originates from HttpServletRequest.authenticateIOException - if an input/output error occurspublic boolean invokePostAuthenticateDelegate(HttpRequest request, HttpResponse response, Context context) throws IOException
invokePostAuthenticateDelegate in interface Realmrequest - Request we are processingresponse - Response we are creatingcontext - The Context to which client of this class is attached.IOException - if an input/output error occurspublic boolean hasRole(Principal principal, String role)
true if the specified Principal has the specified security role, within the context of this
Realm; otherwise return false. This method 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.public boolean hasUserDataPermission(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints) throws IOException
hasUserDataPermission 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 alreadyIOException - if an input/output error occurspublic boolean hasUserDataPermission(HttpRequest request, HttpResponse response, SecurityConstraint[] constraints, String uri, String method) throws IOException
hasUserDataPermission in interface Realmrequest - the request that may be redirectedresponse - the response that may be redirectedconstraints - the security constraints to check againsturi - the request URI (minus the context path) to checkmethod - the request method to checkIOExceptionpublic void removePropertyChangeListener(PropertyChangeListener listener)
removePropertyChangeListener in interface Realmlistener - The listener to removepublic void addLifecycleListener(LifecycleListener listener)
addLifecycleListener in interface Lifecyclelistener - The listener to addpublic List<LifecycleListener> findLifecycleListeners()
findLifecycleListeners in interface Lifecyclepublic void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener in interface Lifecyclelistener - The listener to removepublic void start()
throws LifecycleException
start in interface LifecycleLifecycleException - if this component detects a fatal error that prevents this component from being usedpublic void stop()
throws LifecycleException
stop in interface LifecycleLifecycleException - if this component detects a fatal error that needs to be reportedpublic void destroy()
public void logout(HttpRequest hreq)
Realmpublic boolean isSecurityExtensionEnabled(javax.servlet.ServletContext servletContext)
RealmisSecurityExtensionEnabled in interface RealmservletContext - the ServletContextprotected char[] digest(char[] credentials)
credentials - Password or other credentials to use in authenticating this usernameprotected boolean hasMessageDigest()
protected char[] getDigest(String username, String realmName)
protected abstract String getName()
protected abstract char[] getPassword(String username)
protected abstract Principal getPrincipal(String username)
protected void log(String message)
message - Message to be loggedprotected void log(String message, Throwable t)
message - Message to be loggedt - Associated exceptionprotected void disableProxyCaching(HttpRequest request, HttpResponse response, boolean disableProxyCaching, boolean securePagesWithPragma)
public ObjectName getController()
public void setController(ObjectName controller)
public Principal getAlternatePrincipal(HttpRequest req)
getAlternatePrincipal in interface Realmreq - The request object.public String getAlternateAuthType(HttpRequest req)
getAlternateAuthType in interface Realmreq - The request object.public void setRealmName(String name, String authMethod)
setRealmName in interface Realmname - the name of the realm.public String getRealmName()
getRealmName in interface Realmpublic Principal authenticate(javax.servlet.http.HttpServletRequest hreq)
Realmauthenticate in interface Realmhreq - HTTP servlet request.Copyright © 2019. All rights reserved.