mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-1995: Removed remaining direct dependencies on portlet API from Alfresco Explorer classes
- Moved into AlfrescoFacesPortlet - portlet.jar was removed from alfresco.war for Liferay compatibility git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19155 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,17 +26,12 @@ import java.util.Properties;
|
|||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.portlet.PortletContext;
|
|
||||||
import javax.portlet.PortletSession;
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.springframework.extensions.config.Config;
|
|
||||||
import org.springframework.extensions.config.ConfigService;
|
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
|
||||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
import org.alfresco.web.app.servlet.AuthenticationHelper;
|
import org.alfresco.web.app.servlet.AuthenticationHelper;
|
||||||
@@ -53,6 +48,10 @@ import org.alfresco.web.bean.wizard.WizardManager;
|
|||||||
import org.alfresco.web.config.ClientConfigElement;
|
import org.alfresco.web.config.ClientConfigElement;
|
||||||
import org.alfresco.web.config.LanguagesConfigElement;
|
import org.alfresco.web.config.LanguagesConfigElement;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.extensions.config.Config;
|
||||||
|
import org.springframework.extensions.config.ConfigService;
|
||||||
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
import org.springframework.web.jsf.FacesContextUtils;
|
import org.springframework.web.jsf.FacesContextUtils;
|
||||||
@@ -240,29 +239,6 @@ public class Application
|
|||||||
return getErrorPage(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
|
return getErrorPage(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the configured error page for the application
|
|
||||||
*
|
|
||||||
* @param portletContext The portlet context
|
|
||||||
* @return The error page
|
|
||||||
*/
|
|
||||||
public static String getErrorPage(PortletContext portletContext)
|
|
||||||
{
|
|
||||||
return getErrorPage((WebApplicationContext)portletContext.getAttribute(
|
|
||||||
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the configured login page for the application
|
|
||||||
*
|
|
||||||
* @param facesContext The faces context
|
|
||||||
* @return The configured login page or null if the configuration is missing
|
|
||||||
*/
|
|
||||||
public static String getLoginPage(FacesContext facesContext)
|
|
||||||
{
|
|
||||||
return getLoginPage(FacesContextUtils.getRequiredWebApplicationContext(facesContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the configured login page for the application
|
* Retrieves the configured login page for the application
|
||||||
*
|
*
|
||||||
@@ -274,18 +250,6 @@ public class Application
|
|||||||
return getLoginPage(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
|
return getLoginPage(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the configured login page for the application
|
|
||||||
*
|
|
||||||
* @param portletContext The portlet context
|
|
||||||
* @return The login page
|
|
||||||
*/
|
|
||||||
public static String getLoginPage(PortletContext portletContext)
|
|
||||||
{
|
|
||||||
return getLoginPage((WebApplicationContext)portletContext.getAttribute(
|
|
||||||
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the User object representing the currently logged in user
|
* @return Returns the User object representing the currently logged in user
|
||||||
*/
|
*/
|
||||||
@@ -728,19 +692,7 @@ public class Application
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// else get from web-client config - the first item in the configured list of languages
|
// else get from web-client config - the first item in the configured list of languages
|
||||||
Config config = Application.getConfigService(session.getServletContext()).getConfig("Languages");
|
locale = getLanguage(WebApplicationContextUtils.getRequiredWebApplicationContext(session.getServletContext()));
|
||||||
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
|
|
||||||
LanguagesConfigElement.CONFIG_ELEMENT_ID);
|
|
||||||
List<String> languages = langConfig.getLanguages();
|
|
||||||
if (languages != null && languages.size() != 0)
|
|
||||||
{
|
|
||||||
locale = I18NUtil.parseLocale(languages.get(0));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// failing that, use the server default locale
|
|
||||||
locale = Locale.getDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// save in user session
|
// save in user session
|
||||||
session.setAttribute(LOCALE, locale);
|
session.setAttribute(LOCALE, locale);
|
||||||
@@ -749,37 +701,28 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the language Locale for the current user PortletSession.
|
* Return the configured language Locale for the application context
|
||||||
*
|
|
||||||
* @param session PortletSession for the current user
|
|
||||||
*
|
*
|
||||||
|
* @param ctx
|
||||||
|
* the application context
|
||||||
* @return Current language Locale set or the VM default if none set - never null
|
* @return Current language Locale set or the VM default if none set - never null
|
||||||
*/
|
*/
|
||||||
public static Locale getLanguage(PortletSession session)
|
public static Locale getLanguage(ApplicationContext ctx)
|
||||||
{
|
|
||||||
Locale locale = (Locale)session.getAttribute(LOCALE);
|
|
||||||
if (locale == null)
|
|
||||||
{
|
{
|
||||||
// get from web-client config - the first item in the configured list of languages
|
// get from web-client config - the first item in the configured list of languages
|
||||||
WebApplicationContext ctx = (WebApplicationContext)session.getPortletContext().getAttribute(
|
Config config = ((ConfigService) ctx.getBean(Application.BEAN_CONFIG_SERVICE)).getConfig("Languages");
|
||||||
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
LanguagesConfigElement langConfig = (LanguagesConfigElement) config
|
||||||
Config config = ((ConfigService)ctx.getBean(Application.BEAN_CONFIG_SERVICE)).getConfig("Languages");
|
.getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
|
||||||
LanguagesConfigElement langConfig = (LanguagesConfigElement)config.getConfigElement(
|
|
||||||
LanguagesConfigElement.CONFIG_ELEMENT_ID);
|
|
||||||
List<String> languages = langConfig.getLanguages();
|
List<String> languages = langConfig.getLanguages();
|
||||||
if (languages != null && languages.size() != 0)
|
if (languages != null && languages.size() != 0)
|
||||||
{
|
{
|
||||||
locale = I18NUtil.parseLocale(languages.get(0));
|
return I18NUtil.parseLocale(languages.get(0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// failing that, use the server default locale
|
// failing that, use the server default locale
|
||||||
locale = Locale.getDefault();
|
return Locale.getDefault();
|
||||||
}
|
}
|
||||||
// save in user session
|
|
||||||
session.setAttribute(LOCALE, locale);
|
|
||||||
}
|
|
||||||
return locale;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1213,7 +1156,7 @@ public class Application
|
|||||||
* @param context The Spring context
|
* @param context The Spring context
|
||||||
* @return The configured error page or null if the configuration is missing
|
* @return The configured error page or null if the configuration is missing
|
||||||
*/
|
*/
|
||||||
private static String getErrorPage(WebApplicationContext context)
|
public static String getErrorPage(ApplicationContext context)
|
||||||
{
|
{
|
||||||
String errorPage = null;
|
String errorPage = null;
|
||||||
|
|
||||||
@@ -1235,7 +1178,7 @@ public class Application
|
|||||||
* @param context The Spring contexr
|
* @param context The Spring contexr
|
||||||
* @return The configured login page or null if the configuration is missing
|
* @return The configured login page or null if the configuration is missing
|
||||||
*/
|
*/
|
||||||
private static String getLoginPage(WebApplicationContext context)
|
public static String getLoginPage(ApplicationContext context)
|
||||||
{
|
{
|
||||||
String loginPage = null;
|
String loginPage = null;
|
||||||
|
|
||||||
|
@@ -22,6 +22,8 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.faces.application.ViewHandler;
|
import javax.faces.application.ViewHandler;
|
||||||
import javax.faces.component.UIViewRoot;
|
import javax.faces.component.UIViewRoot;
|
||||||
@@ -29,21 +31,21 @@ import javax.faces.context.FacesContext;
|
|||||||
import javax.portlet.ActionRequest;
|
import javax.portlet.ActionRequest;
|
||||||
import javax.portlet.ActionResponse;
|
import javax.portlet.ActionResponse;
|
||||||
import javax.portlet.PortletException;
|
import javax.portlet.PortletException;
|
||||||
|
import javax.portlet.PortletRequest;
|
||||||
import javax.portlet.PortletRequestDispatcher;
|
import javax.portlet.PortletRequestDispatcher;
|
||||||
import javax.portlet.PortletSession;
|
import javax.portlet.PortletSession;
|
||||||
|
import javax.portlet.PortletURL;
|
||||||
import javax.portlet.RenderRequest;
|
import javax.portlet.RenderRequest;
|
||||||
import javax.portlet.RenderResponse;
|
import javax.portlet.RenderResponse;
|
||||||
import javax.portlet.UnavailableException;
|
import javax.portlet.UnavailableException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
|
||||||
import org.springframework.extensions.config.ConfigService;
|
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
|
||||||
import org.alfresco.repo.SessionUser;
|
import org.alfresco.repo.SessionUser;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.alfresco.web.app.Application;
|
import org.alfresco.web.app.Application;
|
||||||
import org.alfresco.web.app.servlet.AuthenticationHelper;
|
import org.alfresco.web.app.servlet.AuthenticationHelper;
|
||||||
import org.alfresco.web.app.servlet.AuthenticationStatus;
|
|
||||||
import org.alfresco.web.app.servlet.FacesHelper;
|
import org.alfresco.web.app.servlet.FacesHelper;
|
||||||
import org.alfresco.web.bean.ErrorBean;
|
import org.alfresco.web.bean.ErrorBean;
|
||||||
import org.alfresco.web.bean.FileUploadBean;
|
import org.alfresco.web.bean.FileUploadBean;
|
||||||
@@ -58,6 +60,9 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.myfaces.portlet.MyFacesGenericPortlet;
|
import org.apache.myfaces.portlet.MyFacesGenericPortlet;
|
||||||
import org.apache.myfaces.portlet.PortletUtil;
|
import org.apache.myfaces.portlet.PortletUtil;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.extensions.config.ConfigService;
|
||||||
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,10 +74,10 @@ import org.springframework.web.context.WebApplicationContext;
|
|||||||
*/
|
*/
|
||||||
public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
||||||
{
|
{
|
||||||
|
private static final String ATTRIBUTE_LOCALE = "locale";
|
||||||
private static final String PREF_ALF_USERNAME = "_alfUserName";
|
private static final String PREF_ALF_USERNAME = "_alfUserName";
|
||||||
private static final String SESSION_LAST_VIEW_ID = "_alfLastViewId";
|
private static final String SESSION_LAST_VIEW_ID = "_alfLastViewId";
|
||||||
|
|
||||||
private static final String ERROR_PAGE_PARAM = "error-page";
|
|
||||||
private static final String ERROR_OCCURRED = "error-occurred";
|
private static final String ERROR_OCCURRED = "error-occurred";
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(AlfrescoFacesPortlet.class);
|
private static Log logger = LogFactory.getLog(AlfrescoFacesPortlet.class);
|
||||||
@@ -90,7 +95,7 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
|||||||
Application.setInPortalServer(true);
|
Application.setInPortalServer(true);
|
||||||
|
|
||||||
// Set the current locale
|
// Set the current locale
|
||||||
I18NUtil.setLocale(Application.getLanguage(request.getPortletSession()));
|
I18NUtil.setLocale(getLanguage(request.getPortletSession()));
|
||||||
|
|
||||||
boolean isMultipart = PortletFileUpload.isMultipartContent(request);
|
boolean isMultipart = PortletFileUpload.isMultipartContent(request);
|
||||||
|
|
||||||
@@ -239,11 +244,11 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
|||||||
Application.setInPortalServer(true);
|
Application.setInPortalServer(true);
|
||||||
|
|
||||||
// Set the current locale
|
// Set the current locale
|
||||||
I18NUtil.setLocale(Application.getLanguage(request.getPortletSession()));
|
I18NUtil.setLocale(getLanguage(request.getPortletSession()));
|
||||||
|
|
||||||
if (request.getParameter(ERROR_OCCURRED) != null)
|
if (request.getParameter(ERROR_OCCURRED) != null)
|
||||||
{
|
{
|
||||||
String errorPage = Application.getErrorPage(getPortletContext());
|
String errorPage = getErrorPage();
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("An error has occurred, redirecting to error page: " + errorPage);
|
logger.debug("An error has occurred, redirecting to error page: " + errorPage);
|
||||||
@@ -268,7 +273,7 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
|||||||
User user = sessionUser instanceof User ? (User)sessionUser : null;
|
User user = sessionUser instanceof User ? (User)sessionUser : null;
|
||||||
if (user == null && (viewId == null || viewId.equals(getLoginPage()) == false))
|
if (user == null && (viewId == null || viewId.equals(getLoginPage()) == false))
|
||||||
{
|
{
|
||||||
if (AuthenticationHelper.portalGuestAuthenticate(ctx, session, auth) == AuthenticationStatus.Guest)
|
if (portalGuestAuthenticate(ctx, session, auth) != null)
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("Guest access successful.");
|
logger.debug("Guest access successful.");
|
||||||
@@ -392,6 +397,65 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
|||||||
response.setRenderParameter(ERROR_OCCURRED, "true");
|
response.setRenderParameter(ERROR_OCCURRED, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the error bean from a request
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @return the error bean
|
||||||
|
*/
|
||||||
|
public static ErrorBean getErrorBean(ServletRequest request)
|
||||||
|
{
|
||||||
|
PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
|
||||||
|
if (portletReq != null)
|
||||||
|
{
|
||||||
|
PortletSession session = portletReq.getPortletSession();
|
||||||
|
return (ErrorBean)session.getAttribute(ErrorBean.ERROR_BEAN_NAME);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a render URL from the given request and parameters
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @param parameters
|
||||||
|
* the parameters
|
||||||
|
* @return the render url
|
||||||
|
*/
|
||||||
|
public static String getRenderURL(ServletRequest request, Map<String, String[]> parameters)
|
||||||
|
{
|
||||||
|
RenderResponse renderResp = (RenderResponse) request.getAttribute("javax.portlet.response");
|
||||||
|
if (renderResp == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException("RenderResponse object is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
PortletURL url = renderResp.createRenderURL();
|
||||||
|
url.setParameters(parameters);
|
||||||
|
return url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an action url from the given request.
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* the request
|
||||||
|
* @return the action url
|
||||||
|
*/
|
||||||
|
public static String getActionURL(ServletRequest request)
|
||||||
|
{
|
||||||
|
RenderResponse renderResp = (RenderResponse) request.getAttribute("javax.portlet.response");
|
||||||
|
if (renderResp == null)
|
||||||
|
{
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"RenderResponse object is null. The web application is not executing within a portal server!");
|
||||||
|
}
|
||||||
|
return renderResp.createActionURL().toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles errors that occur during a render request
|
* Handles errors that occur during a render request
|
||||||
*/
|
*/
|
||||||
@@ -445,6 +509,51 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For no previous authentication or forced Guest - attempt Guest access
|
||||||
|
*
|
||||||
|
* @param ctx WebApplicationContext
|
||||||
|
* @param auth AuthenticationService
|
||||||
|
*/
|
||||||
|
private static User portalGuestAuthenticate(WebApplicationContext ctx, PortletSession session, AuthenticationService auth)
|
||||||
|
{
|
||||||
|
User user = AuthenticationHelper.portalGuestAuthenticate(ctx, session.getId(), auth);
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
// store the User object in the Session - the authentication servlet will then proceed
|
||||||
|
session.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user);
|
||||||
|
|
||||||
|
// Set the current locale
|
||||||
|
I18NUtil.setLocale(getLanguage(session));
|
||||||
|
|
||||||
|
// remove the session invalidated flag
|
||||||
|
session.removeAttribute(AuthenticationHelper.SESSION_INVALIDATED);
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the language Locale for the current user Session.
|
||||||
|
*
|
||||||
|
* @param session PortletSession for the current user
|
||||||
|
*
|
||||||
|
* @return Current language Locale set or the VM default if none set - never null
|
||||||
|
*/
|
||||||
|
private static Locale getLanguage(PortletSession session)
|
||||||
|
{
|
||||||
|
Locale locale = (Locale)session.getAttribute(ATTRIBUTE_LOCALE);
|
||||||
|
if (locale == null)
|
||||||
|
{
|
||||||
|
locale = Application.getLanguage((ApplicationContext)session.getPortletContext().getAttribute(
|
||||||
|
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
||||||
|
|
||||||
|
// save in user session
|
||||||
|
session.setAttribute(ATTRIBUTE_LOCALE, locale);
|
||||||
|
}
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Retrieves the configured login page
|
* @return Retrieves the configured login page
|
||||||
*/
|
*/
|
||||||
@@ -452,7 +561,8 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
|||||||
{
|
{
|
||||||
if (this.loginPage == null)
|
if (this.loginPage == null)
|
||||||
{
|
{
|
||||||
this.loginPage = Application.getLoginPage(getPortletContext());
|
this.loginPage = Application.getLoginPage((ApplicationContext)getPortletContext().getAttribute(
|
||||||
|
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.loginPage;
|
return this.loginPage;
|
||||||
@@ -465,7 +575,8 @@ public class AlfrescoFacesPortlet extends MyFacesGenericPortlet
|
|||||||
{
|
{
|
||||||
if (this.errorPage == null)
|
if (this.errorPage == null)
|
||||||
{
|
{
|
||||||
this.errorPage = Application.getErrorPage(getPortletContext());
|
this.errorPage = Application.getErrorPage((ApplicationContext)getPortletContext().getAttribute(
|
||||||
|
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.errorPage;
|
return this.errorPage;
|
||||||
|
@@ -23,7 +23,6 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.portlet.PortletSession;
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -391,28 +390,18 @@ public final class AuthenticationHelper
|
|||||||
/**
|
/**
|
||||||
* For no previous authentication or forced Guest - attempt Guest access
|
* For no previous authentication or forced Guest - attempt Guest access
|
||||||
*
|
*
|
||||||
* @param ctx WebApplicationContext
|
* @param ctx
|
||||||
* @param auth AuthenticationService
|
* WebApplicationContext
|
||||||
|
* @param auth
|
||||||
|
* AuthenticationService
|
||||||
*/
|
*/
|
||||||
public static AuthenticationStatus portalGuestAuthenticate(WebApplicationContext ctx, PortletSession session, AuthenticationService auth)
|
public static User portalGuestAuthenticate(WebApplicationContext ctx, String sessionId, AuthenticationService auth)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auth.authenticateAsGuest();
|
auth.authenticateAsGuest();
|
||||||
|
|
||||||
User user = createUser(ctx, AuthenticationUtil.getGuestUserName(), auth.getCurrentTicket(session.getId()));
|
return createUser(ctx, AuthenticationUtil.getGuestUserName(), auth.getCurrentTicket(sessionId));
|
||||||
|
|
||||||
// store the User object in the Session - the authentication servlet will then proceed
|
|
||||||
session.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user);
|
|
||||||
|
|
||||||
// Set the current locale
|
|
||||||
I18NUtil.setLocale(Application.getLanguage(session));
|
|
||||||
|
|
||||||
// remove the session invalidated flag
|
|
||||||
session.removeAttribute(AuthenticationHelper.SESSION_INVALIDATED);
|
|
||||||
|
|
||||||
// it is the responsibilty of the caller to handle the Guest return status
|
|
||||||
return AuthenticationStatus.Guest;
|
|
||||||
}
|
}
|
||||||
catch (AuthenticationException guestError)
|
catch (AuthenticationException guestError)
|
||||||
{
|
{
|
||||||
@@ -421,8 +410,7 @@ public final class AuthenticationHelper
|
|||||||
catch (AccessDeniedException accessError)
|
catch (AccessDeniedException accessError)
|
||||||
{
|
{
|
||||||
// Guest is unable to access either properties on Person
|
// Guest is unable to access either properties on Person
|
||||||
AuthenticationService unprotAuthService = (AuthenticationService)ctx.getBean(UNPROTECTED_AUTH_SERVICE);
|
AuthenticationService unprotAuthService = (AuthenticationService) ctx.getBean(UNPROTECTED_AUTH_SERVICE);
|
||||||
String sessionId = session.getId();
|
|
||||||
unprotAuthService.invalidateTicket(unprotAuthService.getCurrentTicket(sessionId), sessionId);
|
unprotAuthService.invalidateTicket(unprotAuthService.getCurrentTicket(sessionId), sessionId);
|
||||||
unprotAuthService.clearCurrentSecurityContext();
|
unprotAuthService.clearCurrentSecurityContext();
|
||||||
logger.warn("Unable to login as Guest: " + accessError.getMessage());
|
logger.warn("Unable to login as Guest: " + accessError.getMessage());
|
||||||
@@ -430,14 +418,12 @@ public final class AuthenticationHelper
|
|||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
// Some other kind of serious failure to report
|
// Some other kind of serious failure to report
|
||||||
AuthenticationService unprotAuthService = (AuthenticationService)ctx.getBean(UNPROTECTED_AUTH_SERVICE);
|
AuthenticationService unprotAuthService = (AuthenticationService) ctx.getBean(UNPROTECTED_AUTH_SERVICE);
|
||||||
String sessionId = session.getId();
|
|
||||||
unprotAuthService.invalidateTicket(unprotAuthService.getCurrentTicket(sessionId), sessionId);
|
unprotAuthService.invalidateTicket(unprotAuthService.getCurrentTicket(sessionId), sessionId);
|
||||||
unprotAuthService.clearCurrentSecurityContext();
|
unprotAuthService.clearCurrentSecurityContext();
|
||||||
throw new AlfrescoRuntimeException("Failed to authenticate as Guest user.", e);
|
throw new AlfrescoRuntimeException("Failed to authenticate as Guest user.", e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
return AuthenticationStatus.Failure;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -20,17 +20,15 @@ package org.alfresco.web.ui.repo.tag;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import javax.portlet.PortletSession;
|
|
||||||
import javax.portlet.PortletURL;
|
|
||||||
import javax.portlet.RenderRequest;
|
|
||||||
import javax.portlet.RenderResponse;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
import javax.servlet.jsp.tagext.TagSupport;
|
import javax.servlet.jsp.tagext.TagSupport;
|
||||||
|
|
||||||
import org.alfresco.web.app.Application;
|
import org.alfresco.web.app.Application;
|
||||||
|
import org.alfresco.web.app.portlet.AlfrescoFacesPortlet;
|
||||||
import org.alfresco.web.app.servlet.ExternalAccessServlet;
|
import org.alfresco.web.app.servlet.ExternalAccessServlet;
|
||||||
import org.alfresco.web.bean.ErrorBean;
|
import org.alfresco.web.bean.ErrorBean;
|
||||||
|
|
||||||
@@ -113,12 +111,9 @@ public class SystemErrorTag extends TagSupport
|
|||||||
// get the error details from the bean, this may be in a portlet
|
// get the error details from the bean, this may be in a portlet
|
||||||
// session or a normal servlet session.
|
// session or a normal servlet session.
|
||||||
ErrorBean errorBean = null;
|
ErrorBean errorBean = null;
|
||||||
RenderRequest renderReq = (RenderRequest)pageContext.getRequest().
|
if (Application.inPortalServer())
|
||||||
getAttribute("javax.portlet.request");
|
|
||||||
if (renderReq != null)
|
|
||||||
{
|
{
|
||||||
PortletSession session = renderReq.getPortletSession();
|
errorBean = AlfrescoFacesPortlet.getErrorBean(pageContext.getRequest());
|
||||||
errorBean = (ErrorBean)session.getAttribute(ErrorBean.ERROR_BEAN_NAME);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -222,17 +217,13 @@ public class SystemErrorTag extends TagSupport
|
|||||||
|
|
||||||
if (Application.inPortalServer())
|
if (Application.inPortalServer())
|
||||||
{
|
{
|
||||||
RenderResponse renderResp = (RenderResponse)pageContext.getRequest().getAttribute(
|
|
||||||
"javax.portlet.response");
|
|
||||||
if (renderResp == null)
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("RenderResponse object is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
PortletURL url = renderResp.createRenderURL();
|
|
||||||
// NOTE: we don't have to specify the page for the portlet, just the VIEW_ID parameter
|
// NOTE: we don't have to specify the page for the portlet, just the VIEW_ID parameter
|
||||||
// being present will cause the current JSF view to be re-displayed
|
// being present will cause the current JSF view to be re-displayed
|
||||||
url.setParameter("org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID", "current-view");
|
String url = AlfrescoFacesPortlet.getRenderURL(pageContext.getRequest(), Collections.singletonMap(
|
||||||
|
"org.apache.myfaces.portlet.MyFacesGenericPortlet.VIEW_ID", new String[]
|
||||||
|
{
|
||||||
|
"current-view"
|
||||||
|
}));
|
||||||
out.write(url.toString());
|
out.write(url.toString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -21,12 +21,12 @@ package org.alfresco.web.ui.repo.tag;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
import javax.portlet.RenderResponse;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.jsp.JspException;
|
import javax.servlet.jsp.JspException;
|
||||||
import javax.servlet.jsp.tagext.TagSupport;
|
import javax.servlet.jsp.tagext.TagSupport;
|
||||||
|
|
||||||
import org.alfresco.web.app.Application;
|
import org.alfresco.web.app.Application;
|
||||||
|
import org.alfresco.web.app.portlet.AlfrescoFacesPortlet;
|
||||||
import org.alfresco.web.app.servlet.BaseServlet;
|
import org.alfresco.web.app.servlet.BaseServlet;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -56,14 +56,7 @@ public class UploadFormTag extends TagSupport
|
|||||||
|
|
||||||
if (Application.inPortalServer())
|
if (Application.inPortalServer())
|
||||||
{
|
{
|
||||||
RenderResponse renderResp = (RenderResponse)pageContext.getRequest().
|
out.write(AlfrescoFacesPortlet.getActionURL(pageContext.getRequest()));
|
||||||
getAttribute("javax.portlet.response");
|
|
||||||
if (renderResp == null)
|
|
||||||
{
|
|
||||||
throw new IllegalStateException("RenderResponse object is null. The web application is not executing within a portal server!");
|
|
||||||
}
|
|
||||||
|
|
||||||
out.write(renderResp.createActionURL().toString());
|
|
||||||
out.write("'>");
|
out.write("'>");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user