public class DefaultServletService extends java.lang.Object implements ServletService
ServletService for a HTTP servlet application.
This class implements the following strategy for extracting a user from a HTTP request
If the the feature EXTERNAL_AUTH_ONLY_FEATURE is defined then
web-names will be used to resolve the current user for all URLs (even if not true then a explicit authentication servlet can
set session in this way, which is the normal mechanism if external and password authentication is needed). web-names can be taken from the REMOTE_USER or
user certificate DN if present.
If the parameter basic_auth.realm is defined then missing authentication will
trigger HTTP Basic auth with the specified realm (obviously the login factory needs to contain a PasswordAuthComposite for this to succeed.
Note that as this parameter can be set for specific servlets via serlvet init-parameters. This can be used to replace the custom login page entirely if set globally but should probably not be done unless this is the only authentication mechanism. On the other hand it is a good choice for servlets that take form posts and urls where the credentials should be remembered by the browser
Failing the above authentication failure will redirect to the login page.
| Modifier and Type | Field and Description |
|---|---|
static Feature |
ALLOW_EXTERNAL_AUTH_FEATURE
Feature to allow external auth logins if a webname is present.
|
static Feature |
ALLOW_INSECURE |
static java.lang.String |
ARG_TERRMINATOR |
static java.lang.String |
BASIC_AUTH_REALM_PARAM |
protected AppContext |
conn |
static Feature |
EXTERNAL_AUTH_ONLY_FEATURE
Feature to require external auth logins for all sessions.
|
static Feature |
EXTERNAL_AUTH_VIA_LOGIN_FEATURE |
static Feature |
NEED_CERTIFICATE_FEATURE |
static java.lang.String |
PARAMS_KEY_NAME |
static Feature |
REDIRECT_TO_LOGIN_FEATURE |
DEFAULT_PAYLOAD_PARAM| Constructor and Description |
|---|
DefaultServletService(AppContext conn,
ServletContext ctx,
ServletRequest req,
ServletResponse res) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(Cookie c) |
void |
addErrorProps(java.util.Map props)
Add additional information about the request to the properties of a debugging
error report email.
|
void |
cleanup()
AppContext is being closed. |
protected static java.lang.String |
decode(java.lang.String base64) |
java.lang.String |
defaultCharset()
Return the default charset we want to use.
|
java.lang.String |
encodePage()
request page when ServletAppContext was created.
|
java.lang.String |
encodeURL(java.lang.String url)
Add the context path to a url path
|
void |
forward(java.lang.String url)
Forward request to a different page.
|
java.util.LinkedList<java.lang.String> |
getArgs()
Get the ServletPath as a list of strings
A path element of "-" terminates the list.
|
java.lang.Iterable<java.lang.String> |
getAttributeNames() |
AppContext |
getContext() |
java.util.Map<java.lang.String,java.lang.Object> |
getParams()
Extract a Map of the request parameters from the request.
|
HttpServletRequest |
getRequest() |
java.lang.Object |
getRequestAttribute(java.lang.String name)
Retrieve an object from the current request.
|
HttpSession |
getSession() |
HttpSession |
getSession(boolean make_session) |
java.lang.Class<? super ServletService> |
getType()
Returns the type of service the class should be registered under.
|
java.lang.String |
getWebName()
get the authenticated name for the current user as provided by the
web-server/container authorisation layer.
|
boolean |
isComitted()
Has the response been comitted.
|
void |
logout(boolean remove_cookie)
invalidate the servlet session and optionally remove the session cookie.
|
java.util.Map<java.lang.String,java.lang.Object> |
makeParams(HttpServletRequest req)
create a Map of request parameters from scratch.
|
void |
message(java.lang.String message,
java.lang.Object... args) |
void |
noCache()
Identify the current request as containing sensative data that should not be cached.
|
<A extends AppUser> |
populateSession(SessionService<A> sess)
Populate a session automatically using information from the request.
|
void |
redirect(java.lang.String url)
Redirect request to a different page.
|
void |
redirect(java.net.URI url)
Redirect to an external URI
This is intended for external URLs so session is never encoded
|
<A extends AppUser> |
requestAuthentication(SessionService<A> sess)
Authentication is required for this request but credentials are not available.
|
<A extends AppUser> |
requestLogin(SessionService<A> sess,
java.lang.String page)
Go to the login page to request a login.
|
void |
setRequestAttribute(java.lang.String name,
java.lang.Object value)
Store an object in the current request
|
void |
setTimeout(int seconds)
Set an inactivity timeout if supported
|
boolean |
supportsMime(java.lang.String type)
Is the specified mime-type supported by the client.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetStreamParam, getTextParameterpublic static final java.lang.String BASIC_AUTH_REALM_PARAM
public static final Feature NEED_CERTIFICATE_FEATURE
public static final java.lang.String PARAMS_KEY_NAME
public static final java.lang.String ARG_TERRMINATOR
protected final AppContext conn
public static final Feature ALLOW_EXTERNAL_AUTH_FEATURE
public static final Feature EXTERNAL_AUTH_ONLY_FEATURE
public static final Feature EXTERNAL_AUTH_VIA_LOGIN_FEATURE
public static final Feature ALLOW_INSECURE
public static final Feature REDIRECT_TO_LOGIN_FEATURE
public DefaultServletService(AppContext conn, ServletContext ctx, ServletRequest req, ServletResponse res)
public java.lang.String defaultCharset()
ServletServicedefaultCharset in interface ServletServicepublic void cleanup()
AppContextCleanupAppContext is being closed.
Only use this for cleanup that can't be handled by
normal garbage collection or for state which is never returned by reference.cleanup in interface AppContextCleanuppublic java.lang.Class<? super ServletService> getType()
AppContextServicegetType in interface AppContextService<ServletService>public java.lang.String encodePage()
encodePage in interface ServletServicepublic java.lang.String encodeURL(java.lang.String url)
encodeURL in interface ServletServiceurl - public void forward(java.lang.String url)
throws ServletException,
java.io.IOException
forward in interface ServletServiceurl - String page to forward toServletExceptionjava.io.IOExceptionpublic void redirect(java.lang.String url)
throws java.io.IOException
ServletServiceredirect in interface ServletServiceurl - String page to forward to relative to the context pathjava.io.IOExceptionpublic void redirect(java.net.URI url)
throws java.io.IOException
ServletServiceredirect in interface ServletServicejava.io.IOExceptionpublic void message(java.lang.String message,
java.lang.Object... args)
throws java.io.IOException,
ServletException
java.io.IOExceptionServletExceptionpublic java.util.Map<java.lang.String,java.lang.Object> getParams()
getParams in interface ServletServicepublic java.util.LinkedList<java.lang.String> getArgs()
getArgs in interface ServletServicepublic java.lang.String getWebName()
getWebName in interface ServletServicepublic java.util.Map<java.lang.String,java.lang.Object> makeParams(HttpServletRequest req)
req - public HttpSession getSession()
public HttpSession getSession(boolean make_session)
public HttpServletRequest getRequest()
public boolean supportsMime(java.lang.String type)
type - public AppContext getContext()
getContext in interface Contexedpublic <A extends AppUser> void requestAuthentication(SessionService<A> sess) throws java.io.IOException, ServletException
ServletServiceServletService.populateSession(SessionService). These can be cahce din the request.
The SessionService is provided as a parameter to be queried for its capabilities.requestAuthentication in interface ServletServicesess - SessionServicejava.io.IOExceptionServletExceptionpublic <A extends AppUser> void requestLogin(SessionService<A> sess, java.lang.String page) throws java.io.IOException, ServletException
ServletServicerequestLogin in interface ServletServicesess - SessionServicepage - page to return tojava.io.IOExceptionServletExceptionpublic <A extends AppUser> void populateSession(SessionService<A> sess)
ServletServiceServletSessionService if a person is requested and
the current person is not stored in the session. It handles authentication mechanisms that don't
use a specific login url.
If the session is not populated here it may trigger a call to ServletService.requestAuthentication(SessionService) later.
Any authentication errors could be cached in the request and handled there.populateSession in interface ServletServicesess - SessionServicepublic void logout(boolean remove_cookie)
remove_cookie - should cookie be removedpublic void addCookie(Cookie c)
protected static java.lang.String decode(java.lang.String base64)
public boolean isComitted()
ServletServiceisComitted in interface ServletServicepublic void addErrorProps(java.util.Map props)
ServletServiceaddErrorProps in interface ServletServicepublic void noCache()
ServletServicenoCache in interface ServletServicepublic void setRequestAttribute(java.lang.String name,
java.lang.Object value)
ServletServicesetRequestAttribute in interface ServletServicepublic java.lang.Object getRequestAttribute(java.lang.String name)
ServletServicegetRequestAttribute in interface ServletServicepublic java.lang.Iterable<java.lang.String> getAttributeNames()
getAttributeNames in interface ServletServicepublic void setTimeout(int seconds)
ServletServicesetTimeout in interface ServletService