use of org.alfresco.web.app.servlet.AuthenticationStatus in project acs-community-packaging by Alfresco.
the class AjaxServlet method service.
/**
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
// set default character encoding for the response
response.setCharacterEncoding("utf-8");
response.setContentType("text/xml;charset=UTF-8");
long startTime = 0;
String uri = request.getRequestURI();
if (logger.isDebugEnabled()) {
final String queryString = request.getQueryString();
logger.debug("Processing URL: " + uri + ((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
}
// dump the request headers
if (headersLogger.isDebugEnabled()) {
final Enumeration<?> headers = request.getHeaderNames();
while (headers.hasMoreElements()) {
final String name = (String) headers.nextElement();
headersLogger.debug(name + ": " + request.getHeader(name));
}
}
try {
// Make sure the user is authenticated, if not throw an error to return the
// 500 Internal Server Error code back to the client
AuthenticationStatus status = servletAuthenticate(request, response, false);
if (status == AuthenticationStatus.Failure) {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied: User not authenticated");
return;
}
setNoCacheHeaders(response);
uri = uri.substring(request.getContextPath().length() + "/".length());
final String[] tokens = uri.split("/");
if (tokens.length < 3) {
throw new AlfrescoRuntimeException("Servlet URL did not contain all required args: " + uri);
}
// retrieve the command from the URL
final String commandName = tokens[1];
// retrieve the binding expression from the URL
final String expression = tokens[2];
// setup the faces context
final FacesContext facesContext = FacesHelper.getFacesContext(request, response, getServletContext());
// start a timer
if (perfLogger.isDebugEnabled())
startTime = System.currentTimeMillis();
// instantiate the relevant command
AjaxCommand command = null;
if (Command.invoke.toString().equals(commandName)) {
command = new InvokeCommand();
} else if (Command.get.toString().equals(commandName)) {
command = new GetCommand();
} else {
throw new AlfrescoRuntimeException("Unrecognised command received: " + commandName);
}
// execute the command
command.execute(facesContext, expression, request, response);
} catch (RuntimeException error) {
handleError(response, error);
} finally {
// measure the time taken
if (perfLogger.isDebugEnabled()) {
perfLogger.debug("Time to execute command: " + (System.currentTimeMillis() - startTime) + "ms");
}
ContextHolder.setContext(null);
}
}
use of org.alfresco.web.app.servlet.AuthenticationStatus in project acs-community-packaging by Alfresco.
the class AuthenticatorServlet method service.
/*
* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
ServletContext context = getServletContext();
boolean isGuest = (Boolean) req.getAttribute(ATTR_IS_GUEST);
RequiredAuthentication required = (RequiredAuthentication) req.getAttribute(ATTR_REQUIRED_AUTH);
AuthenticationStatus status;
if (isGuest && RequiredAuthentication.guest == required) {
if (logger.isDebugEnabled())
logger.debug("Authenticating as Guest");
status = AuthenticationHelper.authenticate(context, req, res, true);
} else {
if (logger.isDebugEnabled())
logger.debug("Authenticating session");
status = AuthenticationHelper.authenticate(context, req, res, false, false);
}
req.setAttribute(ATTR_AUTH_STATUS, status);
}
Aggregations