Forced Guest access for client URLs

Several fixes for Guest access in the web-client

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2179 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-01-23 18:49:23 +00:00
parent c5b8fba77b
commit 83151b0d33
10 changed files with 113 additions and 46 deletions

View File

@@ -65,7 +65,7 @@ public class AuthenticationFilter implements Filter
if (httpReq.getRequestURI().endsWith(getLoginPage()) == false) if (httpReq.getRequestURI().endsWith(getLoginPage()) == false)
{ {
AuthenticationStatus status = AuthenticationStatus status =
AuthenticationHelper.authenticate(this.context, httpReq, (HttpServletResponse)res); AuthenticationHelper.authenticate(this.context, httpReq, (HttpServletResponse)res, false);
if (status == AuthenticationStatus.Success || status == AuthenticationStatus.Guest) if (status == AuthenticationStatus.Success || status == AuthenticationStatus.Guest)
{ {

View File

@@ -29,13 +29,13 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil; import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationException; import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.app.Application; import org.alfresco.web.app.Application;
import org.alfresco.web.app.portlet.AlfrescoFacesPortlet; import org.alfresco.web.app.portlet.AlfrescoFacesPortlet;
import org.alfresco.web.bean.LoginBean; import org.alfresco.web.bean.LoginBean;
@@ -55,7 +55,6 @@ public final class AuthenticationHelper
public static final String SESSION_INVALIDATED = "_alfSessionInvalid"; public static final String SESSION_INVALIDATED = "_alfSessionInvalid";
public static final String LOGIN_BEAN = "LoginBean"; public static final String LOGIN_BEAN = "LoginBean";
private static final String AUTHENTICATION_SERVICE = "authenticationService";
private static final String COOKIE_ALFUSER = "alfUser"; private static final String COOKIE_ALFUSER = "alfUser";
/** /**
@@ -67,7 +66,7 @@ public final class AuthenticationHelper
* @return AuthenticationStatus result. * @return AuthenticationStatus result.
*/ */
public static AuthenticationStatus authenticate( public static AuthenticationStatus authenticate(
ServletContext context, HttpServletRequest httpRequest, HttpServletResponse httpResponse) ServletContext context, HttpServletRequest httpRequest, HttpServletResponse httpResponse, boolean guest)
throws IOException throws IOException
{ {
HttpSession session = httpRequest.getSession(); HttpSession session = httpRequest.getSession();
@@ -86,29 +85,29 @@ public final class AuthenticationHelper
} }
// setup the authentication context // setup the authentication context
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
AuthenticationService auth = (AuthenticationService)ctx.getBean(AUTHENTICATION_SERVICE); AuthenticationService auth = (AuthenticationService)wc.getBean(ServletHelper.AUTHENTICATION_SERVICE);
if (user == null) if (user == null || guest)
{ {
if (session.getAttribute(AuthenticationHelper.SESSION_INVALIDATED) == null) if (session.getAttribute(AuthenticationHelper.SESSION_INVALIDATED) == null)
{ {
Cookie authCookie = getAuthCookie(httpRequest); Cookie authCookie = getAuthCookie(httpRequest);
if (authCookie == null) if (authCookie == null || guest)
{ {
// TODO: "forced" guest access on URLs! // no previous authentication or forced Guest - attempt Guest access
// no previous authentication - attempt Guest access first
UserTransaction tx = null; UserTransaction tx = null;
try try
{ {
auth.authenticateAsGuest(); auth.authenticateAsGuest();
// if we get here then Guest access was allowed and successful // if we get here then Guest access was allowed and successful
tx = ((TransactionService)ctx.getBean("TransactionService")).getUserTransaction(); ServiceRegistry services = ServletHelper.getServiceRegistry(context);
tx = services.getTransactionService().getUserTransaction();
tx.begin(); tx.begin();
PersonService personService = (PersonService)ctx.getBean("personService"); NodeService nodeService = services.getNodeService();
NodeService nodeService = (NodeService)ctx.getBean("nodeService"); PersonService personService = (PersonService)wc.getBean(ServletHelper.PERSON_SERVICE);
NodeRef guestRef = personService.getPerson(PermissionService.GUEST); NodeRef guestRef = personService.getPerson(PermissionService.GUEST);
user = new User(PermissionService.GUEST, auth.getCurrentTicket(), guestRef); user = new User(PermissionService.GUEST, auth.getCurrentTicket(), guestRef);
NodeRef guestHomeRef = (NodeRef)nodeService.getProperty(guestRef, ContentModel.PROP_HOMEFOLDER); NodeRef guestHomeRef = (NodeRef)nodeService.getProperty(guestRef, ContentModel.PROP_HOMEFOLDER);
@@ -128,11 +127,8 @@ public final class AuthenticationHelper
// Set the current locale // Set the current locale
I18NUtil.setLocale(Application.getLanguage(httpRequest.getSession())); I18NUtil.setLocale(Application.getLanguage(httpRequest.getSession()));
// it is the responsibilty of the caller to handle the Guest return status
return AuthenticationStatus.Guest; return AuthenticationStatus.Guest;
// TODO: What now? Any redirects can be performed directly from the appropriate
// servlet entry points, as we are now authenticated and don't
// need to go through the Login screen to gain authentication.
} }
catch (AuthenticationException guestError) catch (AuthenticationException guestError)
{ {
@@ -188,8 +184,8 @@ public final class AuthenticationHelper
throws IOException throws IOException
{ {
// setup the authentication context // setup the authentication context
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context); WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
AuthenticationService auth = (AuthenticationService)ctx.getBean(AUTHENTICATION_SERVICE); AuthenticationService auth = (AuthenticationService)wc.getBean(ServletHelper.AUTHENTICATION_SERVICE);
try try
{ {
auth.validate(ticket); auth.validate(ticket);

View File

@@ -45,8 +45,6 @@ import org.alfresco.web.bean.LoginBean;
import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/** /**
* Servlet responsible for streaming node content from the repo directly to the response stream. * Servlet responsible for streaming node content from the repo directly to the response stream.
@@ -87,7 +85,6 @@ public class DownloadContentServlet extends HttpServlet
private static final String ARG_PROPERTY = "property"; private static final String ARG_PROPERTY = "property";
private static final String ARG_ATTACH = "attach"; private static final String ARG_ATTACH = "attach";
private static final String ARG_TICKET = "ticket";
/** /**
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
@@ -109,16 +106,22 @@ public class DownloadContentServlet extends HttpServlet
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Processing URL: " + uri + (req.getQueryString() != null ? ("?" + req.getQueryString()) : "")); logger.debug("Processing URL: " + uri + (req.getQueryString() != null ? ("?" + req.getQueryString()) : ""));
// see if a ticket has been supplied // see if a ticket or guest parameter has been supplied
AuthenticationStatus status; AuthenticationStatus status;
String ticket = req.getParameter(ARG_TICKET); String ticket = req.getParameter(ServletHelper.ARG_TICKET);
if (ticket == null || ticket.length() == 0) if (ticket != null && ticket.length() != 0)
{ {
status = AuthenticationHelper.authenticate(getServletContext(), req, res); status = AuthenticationHelper.authenticate(getServletContext(), req, res, ticket);
} }
else else
{ {
status = AuthenticationHelper.authenticate(getServletContext(), req, res, ticket); boolean forceGuest = false;
String guest = req.getParameter(ServletHelper.ARG_GUEST);
if (guest != null)
{
forceGuest = Boolean.parseBoolean(guest);
}
status = AuthenticationHelper.authenticate(getServletContext(), req, res, forceGuest);
} }
if (status == AuthenticationStatus.Failure) if (status == AuthenticationStatus.Failure)
{ {
@@ -177,8 +180,7 @@ public class DownloadContentServlet extends HttpServlet
} }
// get the services we need to retrieve the content // get the services we need to retrieve the content
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); ServiceRegistry serviceRegistry = ServletHelper.getServiceRegistry(getServletContext());
ServiceRegistry serviceRegistry = (ServiceRegistry)context.getBean(ServiceRegistry.SERVICE_REGISTRY);
ContentService contentService = serviceRegistry.getContentService(); ContentService contentService = serviceRegistry.getContentService();
// get the content reader // get the content reader

View File

@@ -56,7 +56,13 @@ public class ExternalAccessServlet extends HttpServlet
protected void service(HttpServletRequest req, HttpServletResponse res) protected void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException throws ServletException, IOException
{ {
AuthenticationStatus status = AuthenticationHelper.authenticate(getServletContext(), req, res); boolean forceGuest = false;
String guest = req.getParameter(ServletHelper.ARG_GUEST);
if (guest != null)
{
forceGuest = Boolean.parseBoolean(guest);
}
AuthenticationStatus status = AuthenticationHelper.authenticate(getServletContext(), req, res, forceGuest);
// The URL contains multiple parts // The URL contains multiple parts
// /alfresco/navigate/<outcome> // /alfresco/navigate/<outcome>

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.app.servlet;
import javax.servlet.ServletContext;
import org.alfresco.service.ServiceRegistry;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
* Useful constant values and common methods for Alfresco servlets.
*
* @author Kevin Roast
*/
public final class ServletHelper
{
/** an existing Ticket can be passed to most servlet for non-session based authentication */
public static final String ARG_TICKET = "ticket";
/** forcing guess access is available on most servlets */
public static final String ARG_GUEST = "guest";
/** public service bean IDs **/
public static final String AUTHENTICATION_SERVICE = "authenticationService";
public static final String PERSON_SERVICE = "personService";
/**
* Return the ServiceRegistry helper instance
*
* @param sc ServletContext
*
* @return ServiceRegistry
*/
public static ServiceRegistry getServiceRegistry(ServletContext sc)
{
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
return (ServiceRegistry)wc.getBean(ServiceRegistry.SERVICE_REGISTRY);
}
/**
* Private constructor
*/
private ServletHelper()
{
}
}

View File

@@ -43,8 +43,6 @@ import org.alfresco.web.bean.LoginBean;
import org.alfresco.web.ui.repo.component.template.DefaultModelHelper; import org.alfresco.web.ui.repo.component.template.DefaultModelHelper;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/** /**
* Servlet responsible for streaming content from a template processed against a node directly * Servlet responsible for streaming content from a template processed against a node directly
@@ -79,7 +77,6 @@ public class TemplateContentServlet extends HttpServlet
private static final String MSG_ERROR_CONTENT_MISSING = "error_content_missing"; private static final String MSG_ERROR_CONTENT_MISSING = "error_content_missing";
private static final String ARG_TICKET = "ticket";
private static final String ARG_MIMETYPE = "mimetype"; private static final String ARG_MIMETYPE = "mimetype";
/** /**
@@ -97,14 +94,20 @@ public class TemplateContentServlet extends HttpServlet
// see if a ticket has been supplied // see if a ticket has been supplied
AuthenticationStatus status; AuthenticationStatus status;
String ticket = req.getParameter(ARG_TICKET); String ticket = req.getParameter(ServletHelper.ARG_TICKET);
if (ticket == null || ticket.length() == 0) if (ticket != null && ticket.length() != 0)
{ {
status = AuthenticationHelper.authenticate(getServletContext(), req, res); status = AuthenticationHelper.authenticate(getServletContext(), req, res, ticket);
} }
else else
{ {
status = AuthenticationHelper.authenticate(getServletContext(), req, res, ticket); boolean forceGuest = false;
String guest = req.getParameter(ServletHelper.ARG_GUEST);
if (guest != null)
{
forceGuest = Boolean.parseBoolean(guest);
}
status = AuthenticationHelper.authenticate(getServletContext(), req, res, forceGuest);
} }
if (status == AuthenticationStatus.Failure) if (status == AuthenticationStatus.Failure)
{ {
@@ -130,7 +133,7 @@ public class TemplateContentServlet extends HttpServlet
// get NodeRef to the template if supplied // get NodeRef to the template if supplied
NodeRef templateRef = null; NodeRef templateRef = null;
if (tokenCount == 8) if (tokenCount >= 8)
{ {
storeRef = new StoreRef(t.nextToken(), t.nextToken()); storeRef = new StoreRef(t.nextToken(), t.nextToken());
templateRef = new NodeRef(storeRef, t.nextToken()); templateRef = new NodeRef(storeRef, t.nextToken());
@@ -144,8 +147,7 @@ public class TemplateContentServlet extends HttpServlet
res.setContentType(mimetype); res.setContentType(mimetype);
// get the services we need to retrieve the content // get the services we need to retrieve the content
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); ServiceRegistry serviceRegistry = ServletHelper.getServiceRegistry(getServletContext());
ServiceRegistry serviceRegistry = (ServiceRegistry)context.getBean(ServiceRegistry.SERVICE_REGISTRY);
NodeService nodeService = serviceRegistry.getNodeService(); NodeService nodeService = serviceRegistry.getNodeService();
TemplateService templateService = serviceRegistry.getTemplateService(); TemplateService templateService = serviceRegistry.getTemplateService();

View File

@@ -59,7 +59,7 @@ public class UploadFileServlet extends HttpServlet
try try
{ {
AuthenticationHelper.authenticate(getServletContext(), request, response); AuthenticationHelper.authenticate(getServletContext(), request, response, false);
if (isMultipart == false) if (isMultipart == false)
{ {

View File

@@ -84,8 +84,6 @@ import org.alfresco.web.ui.repo.component.UISearchCustomProperties;
*/ */
public class AdvancedSearchBean public class AdvancedSearchBean
{ {
private static final String OUTCOME_BROWSE = "browse";
/** /**
* Default constructor * Default constructor
*/ */
@@ -1336,12 +1334,11 @@ public class AdvancedSearchBean
Application.getGlossaryFolderName(fc) + "/" + Application.getGlossaryFolderName(fc) + "/" +
Application.getSavedSearchesFolderName(fc); Application.getSavedSearchesFolderName(fc);
NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
List<NodeRef> results = null; List<NodeRef> results = null;
try try
{ {
results = searchService.selectNodes( results = searchService.selectNodes(
rootNodeRef, nodeService.getRootNode(Repository.getStoreRef()),
xpath, xpath,
null, null,
namespaceService, namespaceService,
@@ -1461,6 +1458,8 @@ public class AdvancedSearchBean
private static final String MSG_ERROR_RESTORE_SEARCH = "error_restore_search"; private static final String MSG_ERROR_RESTORE_SEARCH = "error_restore_search";
private static final String MSG_SELECT_SAVED_SEARCH = "select_saved_search"; private static final String MSG_SELECT_SAVED_SEARCH = "select_saved_search";
private static final String OUTCOME_BROWSE = "browse";
private static final String PANEL_CUSTOM = "custom-panel"; private static final String PANEL_CUSTOM = "custom-panel";
private static final String PANEL_ATTRS = "attrs-panel"; private static final String PANEL_ATTRS = "attrs-panel";
private static final String PANEL_CATEGORIES = "categories-panel"; private static final String PANEL_CATEGORIES = "categories-panel";

View File

@@ -288,6 +288,7 @@ public abstract class UserMembersBean
if (permission.getAccessStatus() == AccessStatus.ALLOWED && if (permission.getAccessStatus() == AccessStatus.ALLOWED &&
(permission.getAuthorityType() == AuthorityType.USER || (permission.getAuthorityType() == AuthorityType.USER ||
permission.getAuthorityType() == AuthorityType.GROUP || permission.getAuthorityType() == AuthorityType.GROUP ||
permission.getAuthorityType() == AuthorityType.GUEST ||
permission.getAuthorityType() == AuthorityType.EVERYONE)) permission.getAuthorityType() == AuthorityType.EVERYONE))
{ {
String authority = permission.getAuthority(); String authority = permission.getAuthority();

View File

@@ -457,7 +457,7 @@ public abstract class InviteUsersWizard extends AbstractWizardBean
// build a display label showing the user and their role for the space // build a display label showing the user and their role for the space
AuthorityType authType = AuthorityType.getAuthorityType(authority); AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType.equals(AuthorityType.USER)) if (authType.equals(AuthorityType.USER) || authType.equals(AuthorityType.GUEST))
{ {
if (this.personService.personExists(authority) == true) if (this.personService.personExists(authority) == true)
{ {