public abstract class AuthenticatorBase extends ValveBase implements Authenticator
<security-constraint>
elements in the web application deployment descriptor. This functionality is implemented as a Valve so that it can be
ommitted in environments that do not require these features. Individual implementations of each supported
authentication method can subclass this base class as required.
USAGE CONSTRAINT: When this class is utilized, the Context to which it is attached (or a parent Container in a hierarchy) must have an associated Realm that can be used for authenticating users and enumerating the roles to which they have been assigned.
USAGE CONSTRAINT: This Valve is only useful when processing HTTP requests. Requests of any other type will simply be passed through.
Modifier and Type | Field and Description |
---|---|
protected boolean |
alwaysUseSession
Should a session always be used once a user is authenticated? This may offer some performance benefits since the
session can then be used to cache the authenticated Principal, hence removing the need to authenticate the user via
the Realm on every request.
|
protected static String |
AUTH_HEADER_NAME
Authentication header
|
protected boolean |
cache
Should we cache authenticated Principals if the request is part of an HTTP session?
|
protected boolean |
changeSessionIdOnAuthentication
Should the session ID, if any, be changed upon a successful authentication to prevent a session fixation attack?
|
protected Context |
context
The Context to which this Valve is attached.
|
protected boolean |
disableProxyCaching
Flag to determine if we disable proxy caching, or leave the issue up to the webapp developer.
|
protected String |
entropy
A String initialization parameter used to increase the entropy of the initialization of our random number generator.
|
protected static String |
info
Descriptive information about this implementation.
|
protected SecureRandom |
random
A random number generator to use when generating session identifiers.
|
protected String |
randomClass
The Java class name of the random number generator class to be used when generating session identifiers.
|
protected static String |
REALM_NAME
Default authentication realm name.
|
protected boolean |
securePagesWithPragma
Flag to determine if we disable proxy caching with headers incompatible with IE
|
protected static int |
SESSION_ID_BYTES
The number of random bytes to include when generating a session identifier.
|
protected SingleSignOn |
sso
The SingleSignOn implementation in our request processing chain, if there is one.
|
container, controller, debug, domain, lifecycle, log, next, oname, rb, started
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
END_PIPELINE, INVOKE_NEXT
Constructor and Description |
---|
AuthenticatorBase() |
Modifier and Type | Method and Description |
---|---|
protected void |
associate(String ssoId,
long ssoVersion,
Session session)
Associate the specified single sign on identifier with the specified Session.
|
abstract boolean |
authenticate(HttpRequest request,
HttpResponse response,
LoginConfig config)
Authenticate the user making this request, based on the specified login configuration.
|
protected Principal |
doLogin(HttpRequest request,
String username,
char[] password)
Process the login request.
|
protected String |
generateSessionId()
Generate and return a new session identifier for the cookie that identifies an SSO principal.
|
boolean |
getAlwaysUseSession() |
protected abstract String |
getAuthMethod() |
boolean |
getCache()
Return the cache authenticated Principals flag.
|
Container |
getContainer()
Return the Container to which this Valve is attached.
|
int |
getDebug()
Return the debugging detail level for this component.
|
boolean |
getDisableProxyCaching()
Return the flag that states if we add headers to disable caching by proxies.
|
String |
getEntropy()
Return the entropy increaser value, or compute a semi-useful value if this String has not yet been set.
|
String |
getInfo()
Return descriptive information about this Valve implementation.
|
protected SecureRandom |
getRandom()
Return the random number generator instance we should use for generating session identifiers.
|
String |
getRandomClass()
Return the random number generator class name.
|
String |
getRealmName()
Returns the name of the associated realm.
|
protected Session |
getSession(HttpRequest request)
Return the internal Session that is associated with this HttpRequest, or
null if there is no such
Session. |
protected Session |
getSession(HttpRequest request,
boolean create)
Return the internal Session that is associated with this HttpRequest, possibly creating a new one if necessary, or
null if there is no such session and we did not create one. |
SingleSignOn |
getSingleSignOn() |
int |
invoke(Request request,
Response response)
Enforce the security restrictions in the web application deployment descriptor of our associated Context.
|
boolean |
isChangeSessionIdOnAuthentication()
Return the flag that states if we should change the session ID of an existing session upon successful authentication.
|
boolean |
isSecurePagesWithPragma()
Return the flag that states, if proxy caching is disabled, what headers we add to disable the caching.
|
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 |
login(String username,
char[] password,
HttpRequest request) |
void |
logout(HttpRequest request) |
void |
postInvoke(Request request,
Response response)
A post-request processing implementation that does nothing.
|
protected void |
register(HttpRequest request,
HttpResponse response,
Principal principal,
String authType,
String username,
char[] password)
Register an authenticated Principal and authentication type in our request, in the current session (if there is one),
and with our SingleSignOn valve, if there is one.
|
void |
setAlwaysUseSession(boolean alwaysUseSession) |
void |
setCache(boolean cache)
Set the cache authenticated Principals flag.
|
void |
setChangeSessionIdOnAuthentication(boolean changeSessionIdOnAuthentication)
Set the value of the flag that states if we should change the session ID of an existing session upon successful
authentication.
|
void |
setContainer(Container container)
Set the Container to which this Valve is attached.
|
void |
setDebug(int debug)
Set the debugging detail level for this component.
|
void |
setDisableProxyCaching(boolean nocache)
Set the value of the flag that states if we add headers to disable caching by proxies.
|
void |
setEntropy(String entropy)
Set the entropy increaser value.
|
void |
setRandomClass(String randomClass)
Set the random number generator class name.
|
void |
setRealmName(String name)
Set the name of the associated realm.
|
void |
setSecurePagesWithPragma(boolean securePagesWithPragma)
Set the value of the flag that states what headers we add to disable proxy caching.
|
void |
setSingleSignOn(SingleSignOn sso) |
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.
|
addLifecycleListener, backgroundProcess, createObjectName, event, findLifecycleListeners, getController, getDomain, getNext, getObjectName, getParentName, invoke, isStarted, removeLifecycleListener, setController, setNext, setObjectName
protected static final String info
protected static final int SESSION_ID_BYTES
protected static final String AUTH_HEADER_NAME
protected static final String REALM_NAME
protected boolean alwaysUseSession
protected boolean cache
protected boolean changeSessionIdOnAuthentication
protected Context context
protected String entropy
protected boolean disableProxyCaching
protected SecureRandom random
protected String randomClass
protected SingleSignOn sso
protected boolean securePagesWithPragma
public boolean getAlwaysUseSession()
public void setAlwaysUseSession(boolean alwaysUseSession)
public boolean getCache()
public void setCache(boolean cache)
cache
- The new cache flagpublic Container getContainer()
getContainer
in interface Contained
getContainer
in class ValveBase
public void setContainer(Container container)
setContainer
in interface Contained
setContainer
in class ValveBase
container
- The container to which we are attachedpublic int getDebug()
public void setDebug(int debug)
public String getEntropy()
public void setEntropy(String entropy)
entropy
- The new entropy increaser valuepublic String getInfo()
public String getRandomClass()
public void setRandomClass(String randomClass)
randomClass
- The new random number generator class namepublic boolean getDisableProxyCaching()
public void setDisableProxyCaching(boolean nocache)
nocache
- true
if we add headers to disable proxy caching, false
if we leave the
headers alone.public boolean isSecurePagesWithPragma()
public void setSecurePagesWithPragma(boolean securePagesWithPragma)
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.public boolean isChangeSessionIdOnAuthentication()
true
to change session ID upon successful authentication, false
to do not perform
the change.public void setChangeSessionIdOnAuthentication(boolean changeSessionIdOnAuthentication)
changeSessionIdOnAuthentication
- true
to change session ID upon successful authentication,
false
to do not perform the change.public SingleSignOn getSingleSignOn()
public void setSingleSignOn(SingleSignOn sso)
public int invoke(Request request, Response response) throws IOException, javax.servlet.ServletException
invoke
in interface GlassFishValve
invoke
in class ValveBase
request
- Request to be processedresponse
- Response to be processedINVOKE_NEXT
or END_PIPELINE
IOException
- if an input/output error occursjavax.servlet.ServletException
- if thrown by a processing elementpublic void postInvoke(Request request, Response response) throws IOException, javax.servlet.ServletException
postInvoke
in interface GlassFishValve
postInvoke
in class ValveBase
request
- The servlet request to be processedresponse
- The servlet response to be createdIOException
- if an input/output error occursjavax.servlet.ServletException
- if a servlet error occursprotected void associate(String ssoId, long ssoVersion, Session session)
ssoId
- Single sign on identifierssoVersion
- Single sign on versionsession
- Session to be associatedpublic abstract boolean authenticate(HttpRequest request, HttpResponse response, LoginConfig config) throws IOException
true
if
any specified constraint has been satisfied, or false
if we have created a response challenge already.request
- Request we are processingresponse
- Response we are creatingconfig
- Login configuration describing how authentication should be performedIOException
- if an input/output error occursprotected String generateSessionId()
protected SecureRandom getRandom()
protected Session getSession(HttpRequest request)
null
if there is no such
Session.request
- The HttpRequest we are processingprotected Session getSession(HttpRequest request, boolean create)
null
if there is no such session and we did not create one.request
- The HttpRequest we are processingcreate
- Should we create a session if needed?protected void log(String message)
message
- Message to be loggedprotected void log(String message, Throwable t)
message
- Message to be loggedt
- Associated exceptionprotected void register(HttpRequest request, HttpResponse response, Principal principal, String authType, String username, char[] password)
request
- The servlet request we are processingresponse
- The servlet response we are generatingprincipal
- The authenticated Principal to be registeredauthType
- The authentication type to be registeredusername
- Username used to authenticate (if any)password
- Password used to authenticate (if any)public void login(String username, char[] password, HttpRequest request) throws javax.servlet.ServletException
login
in interface Authenticator
javax.servlet.ServletException
protected abstract String getAuthMethod()
protected Principal doLogin(HttpRequest request, String username, char[] password) throws javax.servlet.ServletException
request
- Associated requestusername
- The userpassword
- The passwordjavax.servlet.ServletException
public void logout(HttpRequest request) throws javax.servlet.ServletException
logout
in interface Authenticator
javax.servlet.ServletException
public void start() throws LifecycleException
configure()
, and before any of the public methods of the component are utilized.start
in interface Lifecycle
start
in class ValveBase
LifecycleException
- if this component detects a fatal error that prevents this component from being usedpublic void stop() throws LifecycleException
stop
in interface Lifecycle
stop
in class ValveBase
LifecycleException
- if this component detects a fatal error that needs to be reportedpublic void setRealmName(String name)
name
- the name of the realm.public String getRealmName()
Copyright © 2021. All rights reserved.