mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
18088: ETHREEOH-3787: Addition of liferay-display.xml to define category for demo portlet 18053: Build fix: Re-enable log ins to Alfresco web app when not running in a portlet container - Removed direct dependencies between FacesHelper and portlet API 18037: Merged DEV/DAVEW/SURFPORTLET to V3.2 17669: Changes to enable surf rendering from a portlet - New DispatcherPortlet forwards portlet requests to the DispatcherServlet as servlet requests. - A new filter 'lazily' creates users' dashboard pages to avoid the need to have to redirect from site-index.jsp - Build against JSR 286 portlet 2.0 API jar - Exclude portlet API jar from war to avoid ClassCastExceptions - Lazily init portlet authenticators to avoid ClassNotFoundExceptions when not running in a portlet container - Fix web.xml schema validation problems - UserFactory session keys given unique prefix to avoid class with Liferay shared session attributes - Liferay deployment descriptor to enable user principal name resolution - Fixed subsystem problem that prevented the override of a property with the empty string in alfresco-global.properties. Stopped 'unprotected' external auth from working. 18019: ETHREEOH-3770: LDAP sync now supports attribute range retrieval to get around limits imposed by Active Directory on multi-valued attributes - Meant that groups with more than 1000 members were getting truncated in Active Directory - Now switched on in ldap-ad and off in ldap subsystem - Also switched off result set paging in ldap subsystem by default for wider compatibility with non-AD systems 17759: Merged DEV/BELARUS/V3.2-2009_11_24 to V3.2 17755: ETHREEOH-3739: build 283: Upgrades from 3.1.1 and 3.1.2 fail on JBoss 5.1 - The getFile method was created for ImapFoldersPatch to retrieve acp file for ACPImportPackageHandler. - This method tries to load ACP file from file location and if it is unsuccessful then creates temporary file from resource input stream. - In other words we apply aproach from ImporterBootstrap. 17600: ETHREEOH-1002: Avoid using HTTP 1.1 chunked transfer encoding to send heartbeat data because some proxy servers can't cope with it! - Unit test can now parse chunked and un-chunked HTTP requests 17597: Further optimizations to authority caching - Don't invalidate entire user authority lookup cache when user added to or removed from an authority 17588: Fix up authority caching - Need to include tenant domain in cache key - Also reinstated cache of user recursive group memberships for performance purposes 17559: ETHREEOH-3440: Authority search performance improvements - AuthorityDAO now uses Lucene (again) to do wildcard style authority searches by name, type and zone - Retrieval by exact name, type and zone still performed by DB methods - DB methods now optimized to avoid having to load group child nodes to determine group membership - Authority cache now stores authority node refs by name to reduce authority resolution queries - ScriptGroup avoids hammering repository with multiple searches to determine group membership 17545: ETHREEOH-3371: Fixed group searches to search within the default zone and thus hide 'invisible' WCM and Share groups. 17527: ETHREEOH-3375: Use static inner class for cache key to avoid non serializable exceptions 17523: ETHREEOH-3337: Fix NPEs in RepoServerMgmt operations - Transactional cache can have entries with non-null keys and null values 17521: ETHREEOH-3158: Proper handling of user validation failures in Kerberos Authentication filters. 17490: Fix failing HeartBeatTest - Prevent possibility of both test and non-test public keys being used at the same time 17481: Fix build for Jan - Removed JDK 1.6 String.isEmpty() references 17472: Follow-on for ETHREEOH-2648 - tighten guest login, eg. if no guest configured (in auth chain) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18108 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
340 lines
11 KiB
Java
340 lines
11 KiB
Java
/*
|
|
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* As a special exception to the terms and conditions of version 2.0 of
|
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
|
* FLOSS exception. You should have recieved a copy of the text describing
|
|
* the FLOSS exception, and it is also available here:
|
|
* http://www.alfresco.com/legal/licensing"
|
|
*/
|
|
package org.alfresco.web.app.servlet;
|
|
|
|
import javax.faces.FactoryFinder;
|
|
import javax.faces.component.UIComponent;
|
|
import javax.faces.component.UIViewRoot;
|
|
import javax.faces.context.FacesContext;
|
|
import javax.faces.context.FacesContextFactory;
|
|
import javax.faces.el.EvaluationException;
|
|
import javax.faces.el.ValueBinding;
|
|
import javax.faces.lifecycle.Lifecycle;
|
|
import javax.faces.lifecycle.LifecycleFactory;
|
|
import javax.servlet.ServletContext;
|
|
import javax.servlet.ServletRequest;
|
|
import javax.servlet.ServletResponse;
|
|
|
|
import org.alfresco.error.AlfrescoRuntimeException;
|
|
import org.alfresco.web.bean.generator.IComponentGenerator;
|
|
import org.alfresco.web.ui.repo.RepoConstants;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* @author Kevin Roast
|
|
*/
|
|
public final class FacesHelper
|
|
{
|
|
private static Log logger = LogFactory.getLog(FacesHelper.class);
|
|
|
|
/**
|
|
* Mask for hex encoding
|
|
*/
|
|
private static final int MASK = (1 << 4) - 1;
|
|
|
|
/**
|
|
* Digits used for hex string encoding
|
|
*/
|
|
private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
|
|
|
/**
|
|
* Private constructor
|
|
*/
|
|
private FacesHelper()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Return a valid FacesContext for the specific context, request and response.
|
|
* The FacesContext can be constructor for Servlet use.
|
|
*
|
|
* @param context ServletContext
|
|
* @param request ServletRequest
|
|
* @param response ServletReponse
|
|
*
|
|
* @return FacesContext
|
|
*/
|
|
public static FacesContext getFacesContext(ServletRequest request, ServletResponse response, ServletContext context)
|
|
{
|
|
return getFacesContextImpl(request, response, context, null);
|
|
}
|
|
|
|
/**
|
|
* Return a valid FacesContext for the specific context, request and response.
|
|
* The FacesContext can be constructor for Servlet use.
|
|
*
|
|
* @param context ServletContext
|
|
* @param request ServletRequest
|
|
* @param response ServletReponse
|
|
*
|
|
* @return FacesContext
|
|
*/
|
|
public static FacesContext getFacesContext(ServletRequest request, ServletResponse response, ServletContext context, String viewRoot)
|
|
{
|
|
return getFacesContextImpl(request, response, context, viewRoot);
|
|
}
|
|
|
|
/**
|
|
* Return a valid FacesContext for the specific context, request and response.
|
|
* The FacesContext can be constructor for Servlet use.
|
|
*
|
|
* @param context PortletContext
|
|
* @param request PortletRequest
|
|
* @param response PortletResponse
|
|
*
|
|
* @return FacesContext
|
|
*/
|
|
public static FacesContext getFacesContext(Object request, Object response, Object context)
|
|
{
|
|
return getFacesContextImpl(request, response, context, null);
|
|
}
|
|
|
|
/**
|
|
* Return a valid FacesContext for the specific context, request and response.
|
|
* The FacesContext can be constructor for Servlet and Portlet use.
|
|
*
|
|
* @param context ServletContext or PortletContext
|
|
* @param request ServletRequest or PortletRequest
|
|
* @param response ServletReponse or PortletResponse
|
|
*
|
|
* @return FacesContext
|
|
*/
|
|
private static FacesContext getFacesContextImpl(Object request, Object response, Object context, String viewRoot)
|
|
{
|
|
FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
|
|
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
|
|
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
|
|
|
|
// Doesn't set this instance as the current instance of FacesContext.getCurrentInstance
|
|
FacesContext facesContext = contextFactory.getFacesContext(context, request, response, lifecycle);
|
|
|
|
// Set using our inner class
|
|
InnerFacesContext.setFacesContextAsCurrent(facesContext);
|
|
|
|
// set a new viewRoot, otherwise context.getViewRoot returns null
|
|
if (viewRoot == null)
|
|
{
|
|
viewRoot = "/jsp/browse/browse.jsp";
|
|
}
|
|
|
|
UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, viewRoot);
|
|
facesContext.setViewRoot(view);
|
|
|
|
return facesContext;
|
|
}
|
|
|
|
/**
|
|
* Return a JSF managed bean reference.
|
|
*
|
|
* @param fc FacesContext
|
|
* @param name Name of the managed bean to return
|
|
*
|
|
* @return the managed bean or null if not found
|
|
*/
|
|
public static Object getManagedBean(FacesContext fc, String name)
|
|
{
|
|
Object obj = null;
|
|
|
|
try
|
|
{
|
|
ValueBinding vb = fc.getApplication().createValueBinding("#{" + name + "}");
|
|
obj = vb.getValue(fc);
|
|
}
|
|
catch (EvaluationException ee)
|
|
{
|
|
// catch exception to resolve ADB-158/ACT-7343
|
|
// not much we can do here, just make sure return is null
|
|
obj = null;
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
/**
|
|
* Sets up the id for the given component, if the id is null a unique one
|
|
* is generated using the standard Faces algorithm. If an id is present it
|
|
* is checked for illegal characters.
|
|
*
|
|
* @param context FacesContext
|
|
* @param component The component to set the id for
|
|
* @param id The id to set
|
|
*/
|
|
public static void setupComponentId(FacesContext context, UIComponent component, String id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
id = context.getViewRoot().createUniqueId();
|
|
}
|
|
else
|
|
{
|
|
// make sure we do not have illegal characters in the id
|
|
id = makeLegalId(id);
|
|
}
|
|
|
|
component.setId(id);
|
|
}
|
|
|
|
/**
|
|
* Makes the given id a legal JSF component id by replacing illegal characters
|
|
* with ISO9075 encoding - which itself a subset of valid HTML ID characters.
|
|
*
|
|
* @param id The id to make legal
|
|
*
|
|
* @return the legalised id
|
|
*/
|
|
public static String makeLegalId(String id)
|
|
{
|
|
return (id != null ? validFacesId(id) : null);
|
|
}
|
|
|
|
/**
|
|
* Retrieves the named component generator implementation.
|
|
* If the named generator is not found the TextFieldGenerator is looked up
|
|
* as a default, if this is also not found an AlfrescoRuntimeException is thrown.
|
|
*
|
|
* @param context FacesContext
|
|
* @param generatorName The name of the component generator to retrieve
|
|
* @return The component generator instance
|
|
*/
|
|
public static IComponentGenerator getComponentGenerator(FacesContext context, String generatorName)
|
|
{
|
|
IComponentGenerator generator = lookupComponentGenerator(context, generatorName);
|
|
|
|
if (generator == null)
|
|
{
|
|
// create a text field if we can't find a component generator (a warning should have already been
|
|
// displayed on the appserver console)
|
|
|
|
logger.warn("Attempting to find default component generator '" + RepoConstants.GENERATOR_TEXT_FIELD + "'");
|
|
generator = lookupComponentGenerator(context, RepoConstants.GENERATOR_TEXT_FIELD);
|
|
}
|
|
|
|
// if we still don't have a component generator we should abort as vital configuration is missing
|
|
if (generator == null)
|
|
{
|
|
throw new AlfrescoRuntimeException("Failed to find a component generator, please ensure the '" +
|
|
RepoConstants.GENERATOR_TEXT_FIELD + "' bean is present in your configuration");
|
|
}
|
|
|
|
return generator;
|
|
}
|
|
|
|
private static IComponentGenerator lookupComponentGenerator(FacesContext context, String generatorName)
|
|
{
|
|
IComponentGenerator generator = null;
|
|
|
|
Object obj = FacesHelper.getManagedBean(context, generatorName);
|
|
if (obj != null)
|
|
{
|
|
if (obj instanceof IComponentGenerator)
|
|
{
|
|
generator = (IComponentGenerator)obj;
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("Found component generator for '" + generatorName + "': " + generator);
|
|
}
|
|
else
|
|
{
|
|
logger.warn("Bean '" + generatorName + "' does not implement IComponentGenerator");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
logger.warn("Failed to find component generator with name of '" + generatorName + "'");
|
|
}
|
|
|
|
return generator;
|
|
}
|
|
|
|
/**
|
|
* We need an inner class to be able to call FacesContext.setCurrentInstance
|
|
* since it's a protected method
|
|
*/
|
|
private abstract static class InnerFacesContext extends FacesContext
|
|
{
|
|
protected static void setFacesContextAsCurrent(FacesContext facesContext)
|
|
{
|
|
FacesContext.setCurrentInstance(facesContext);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Helper to ensure only valid and acceptable characters are output as Faces component IDs.
|
|
* Based on ISO9075 encoding - which itself a subset of valid HTML ID characters.
|
|
*/
|
|
private static String validFacesId(String id)
|
|
{
|
|
int len = id.length();
|
|
StringBuilder buf = new StringBuilder(len + (len>>1));
|
|
for (int i = 0; i<len; i++)
|
|
{
|
|
char c = id.charAt(i);
|
|
int ci = (int)c;
|
|
if (i == 0)
|
|
{
|
|
if ((ci >= 65 && ci <= 90) || // A-Z
|
|
(ci >= 97 && ci <= 122)) // a-z
|
|
{
|
|
buf.append(c);
|
|
}
|
|
else
|
|
{
|
|
encode(c, buf);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((ci >= 65 && ci <= 90) || // A-Z
|
|
(ci >= 97 && ci <= 122) || // a-z
|
|
(ci >= 48 && ci <= 57) || // 0-9
|
|
ci == 45 || ci == 95) // - and _
|
|
{
|
|
buf.append(c);
|
|
}
|
|
else
|
|
{
|
|
encode(c, buf);
|
|
}
|
|
}
|
|
}
|
|
return buf.toString();
|
|
}
|
|
|
|
private static void encode(char c, StringBuilder builder)
|
|
{
|
|
char[] buf = new char[] { 'x', '0', '0', '0', '0', '_' };
|
|
int charPos = 5;
|
|
do
|
|
{
|
|
buf[--charPos] = DIGITS[c & MASK];
|
|
c >>>= 4;
|
|
}
|
|
while (c != 0);
|
|
builder.append(buf);
|
|
}
|
|
}
|