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, wait
getStreamParam, getTextParameter
public 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()
ServletService
defaultCharset
in interface ServletService
public void cleanup()
AppContextCleanup
AppContext
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 AppContextCleanup
public java.lang.Class<? super ServletService> getType()
AppContextService
getType
in interface AppContextService<ServletService>
public java.lang.String encodePage()
encodePage
in interface ServletService
public java.lang.String encodeURL(java.lang.String url)
encodeURL
in interface ServletService
url
- public void forward(java.lang.String url) throws ServletException, java.io.IOException
forward
in interface ServletService
url
- String page to forward toServletException
java.io.IOException
public void redirect(java.lang.String url) throws java.io.IOException
ServletService
redirect
in interface ServletService
url
- String page to forward to relative to the context pathjava.io.IOException
public void redirect(java.net.URI url) throws java.io.IOException
ServletService
redirect
in interface ServletService
java.io.IOException
public void message(java.lang.String message, java.lang.Object... args) throws java.io.IOException, ServletException
java.io.IOException
ServletException
public java.util.Map<java.lang.String,java.lang.Object> getParams()
getParams
in interface ServletService
public java.util.LinkedList<java.lang.String> getArgs()
getArgs
in interface ServletService
public java.lang.String getWebName()
getWebName
in interface ServletService
public 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 Contexed
public <A extends AppUser> void requestAuthentication(SessionService<A> sess) throws java.io.IOException, ServletException
ServletService
ServletService.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 ServletService
sess
- SessionService
java.io.IOException
ServletException
public <A extends AppUser> void requestLogin(SessionService<A> sess, java.lang.String page) throws java.io.IOException, ServletException
ServletService
requestLogin
in interface ServletService
sess
- SessionService
page
- page to return tojava.io.IOException
ServletException
public <A extends AppUser> void populateSession(SessionService<A> sess)
ServletService
ServletSessionService
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 ServletService
sess
- SessionService
public 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()
ServletService
isComitted
in interface ServletService
public void addErrorProps(java.util.Map props)
ServletService
addErrorProps
in interface ServletService
public void noCache()
ServletService
noCache
in interface ServletService
public void setRequestAttribute(java.lang.String name, java.lang.Object value)
ServletService
setRequestAttribute
in interface ServletService
public java.lang.Object getRequestAttribute(java.lang.String name)
ServletService
getRequestAttribute
in interface ServletService
public java.lang.Iterable<java.lang.String> getAttributeNames()
getAttributeNames
in interface ServletService
public void setTimeout(int seconds)
ServletService
setTimeout
in interface ServletService