org.alfresco.web.app.servlet
Class BaseServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.alfresco.web.app.servlet.BaseServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
AjaxServlet, BaseDownloadContentServlet, BaseTemplateContentServlet, CommandServlet, DownloadRawContentServlet, ExternalAccessServlet, UploadContentServlet, UploadFileServlet

public abstract class BaseServlet
extends javax.servlet.http.HttpServlet

Base servlet class containing useful constant values and common methods for Alfresco servlets.

See Also:
Serialized Form

Nested Class Summary
static class BaseServlet.PathRefInfo
          Simple structure class for returning both a NodeRef and Filename String
 
Field Summary
static java.lang.String FACES_SERVLET
           
static java.lang.String KEY_ROOT_PATH
           
static java.lang.String KEY_STORE
           
 
Constructor Summary
BaseServlet()
           
 
Method Summary
 boolean checkAccess(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, org.alfresco.service.cmr.repository.NodeRef nodeRef, java.lang.String permission, boolean allowLogIn)
          Check the user has the given permission on the given node.
static org.alfresco.service.ServiceRegistry getServiceRegistry(javax.servlet.ServletContext sc)
          Return the ServiceRegistry helper instance
static void redirectToLoginPage(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, javax.servlet.ServletContext sc)
          Redirect to the Login page - saving the current URL which can be redirected back later once the user has successfully completed the authentication process.
static BaseServlet.PathRefInfo resolveNamePath(javax.servlet.ServletContext sc, java.lang.String path)
          Resolve a name based into a NodeRef and Filename string
static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.faces.context.FacesContext context, java.lang.String[] args)
          Resolves the given path elements to a NodeRef in the current repository
static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.faces.context.FacesContext context, java.lang.String[] args, boolean decode)
          Resolves the given path elements to a NodeRef in the current repository
static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.servlet.ServletContext context, java.lang.String[] args)
          Resolves the given path elements to a NodeRef in the current repository
static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.servlet.ServletContext context, java.lang.String[] args, boolean decode)
          Resolves the given path elements to a NodeRef in the current repository
 AuthenticationStatus servletAuthenticate(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Perform an authentication for the servlet request URI.
 AuthenticationStatus servletAuthenticate(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, boolean redirectToLoginPage)
          Perform an authentication for the servlet request URI.
static void setNoCacheHeaders(javax.servlet.http.HttpServletResponse res)
          Apply the headers required to disallow caching of the response in the browser
static boolean validRedirectJSP(java.lang.String jsp)
          Returns true if the specified JSP file is valid for a redirect after login.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FACES_SERVLET

public static final java.lang.String FACES_SERVLET
See Also:
Constant Field Values

KEY_STORE

public static final java.lang.String KEY_STORE
See Also:
Constant Field Values

KEY_ROOT_PATH

public static final java.lang.String KEY_ROOT_PATH
See Also:
Constant Field Values
Constructor Detail

BaseServlet

public BaseServlet()
Method Detail

getServiceRegistry

public static org.alfresco.service.ServiceRegistry getServiceRegistry(javax.servlet.ServletContext sc)
Return the ServiceRegistry helper instance

Parameters:
sc - ServletContext
Returns:
ServiceRegistry

servletAuthenticate

public AuthenticationStatus servletAuthenticate(javax.servlet.http.HttpServletRequest req,
                                                javax.servlet.http.HttpServletResponse res)
                                         throws java.io.IOException
Perform an authentication for the servlet request URI. Processing any "ticket" or "guest" URL arguments.

Returns:
AuthenticationStatus
Throws:
java.io.IOException

servletAuthenticate

public AuthenticationStatus servletAuthenticate(javax.servlet.http.HttpServletRequest req,
                                                javax.servlet.http.HttpServletResponse res,
                                                boolean redirectToLoginPage)
                                         throws java.io.IOException
Perform an authentication for the servlet request URI. Processing any "ticket" or "guest" URL arguments.

Returns:
AuthenticationStatus
Throws:
java.io.IOException

checkAccess

public boolean checkAccess(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse res,
                           org.alfresco.service.cmr.repository.NodeRef nodeRef,
                           java.lang.String permission,
                           boolean allowLogIn)
                    throws java.io.IOException,
                           javax.servlet.ServletException
Check the user has the given permission on the given node. If they do not either force a log on if this is a guest user or forward to an error page.

Parameters:
req - the request
res - the response
nodeRef - the node in question
allowLogIn - Indicates whether guest users without access to the node should be redirected to the log in page. If false, a status 403 forbidden page is displayed instead.
Returns:
true, if the user has access
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
javax.servlet.ServletException - On other errors

redirectToLoginPage

public static void redirectToLoginPage(javax.servlet.http.HttpServletRequest req,
                                       javax.servlet.http.HttpServletResponse res,
                                       javax.servlet.ServletContext sc)
                                throws java.io.IOException
Redirect to the Login page - saving the current URL which can be redirected back later once the user has successfully completed the authentication process.

Throws:
java.io.IOException

setNoCacheHeaders

public static void setNoCacheHeaders(javax.servlet.http.HttpServletResponse res)
Apply the headers required to disallow caching of the response in the browser


validRedirectJSP

public static boolean validRedirectJSP(java.lang.String jsp)
Returns true if the specified JSP file is valid for a redirect after login. Only a specific sub-set of the available JSPs are valid to jump directly too after a clean login attempt - e.g. those that do not require JSF bean context setup. This is a limitation of the JSP architecture. The ExternalAccessServlet provides a mechanism to setup the JSF bean context directly for some specific cases.

Parameters:
jsp - Filename of JSP to check, for example "/jsp/browse/browse.jsp"
Returns:
true if the JSP is in the list of valid direct URLs, false otherwise

resolveWebDAVPath

public static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.faces.context.FacesContext context,
                                                                            java.lang.String[] args)
Resolves the given path elements to a NodeRef in the current repository

Parameters:
context - Faces context
args - The elements of the path to lookup

resolveWebDAVPath

public static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.faces.context.FacesContext context,
                                                                            java.lang.String[] args,
                                                                            boolean decode)
Resolves the given path elements to a NodeRef in the current repository

Parameters:
context - Faces context
args - The elements of the path to lookup
decode - True to decode the arg from UTF-8 format, false for no decoding

resolveWebDAVPath

public static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.servlet.ServletContext context,
                                                                            java.lang.String[] args)
Resolves the given path elements to a NodeRef in the current repository

Parameters:
context - ServletContext context
args - The elements of the path to lookup

resolveWebDAVPath

public static org.alfresco.service.cmr.repository.NodeRef resolveWebDAVPath(javax.servlet.ServletContext context,
                                                                            java.lang.String[] args,
                                                                            boolean decode)
Resolves the given path elements to a NodeRef in the current repository

Parameters:
context - ServletContext context
args - The elements of the path to lookup
decode - True to decode the arg from UTF-8 format, false for no decoding

resolveNamePath

public static final BaseServlet.PathRefInfo resolveNamePath(javax.servlet.ServletContext sc,
                                                            java.lang.String path)
Resolve a name based into a NodeRef and Filename string

Parameters:
sc - ServletContext
path - 'cm:name' based path using the '/' character as a separator
Returns:
PathRefInfo structure containing the resolved NodeRef and filename
Throws:
java.lang.IllegalArgumentException


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.