mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
. Fix for AWC-635 (TemplateContentServlet not working with TICKET url argument)
. Fix to image resolver for TemplateContentServlet . Minor improvement to CommandServlet interfaces as per wiki docs . Minor fix to date field format in RSS2.0 template (thanks Mike!) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2685 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<copyright>Copyright (c) 2005 Alfresco Software, Inc. All rights reserved.</copyright>
|
||||
<#assign hostname="http://localhost:8080/alfresco">
|
||||
<#assign spaceref="${hostname}/navigate/browse/${space.nodeRef.storeRef.protocol}/${space.nodeRef.storeRef.identifier}/${space.nodeRef.id}">
|
||||
<#assign datetimeformat="EEE, dd MMM yyyy hh:mm:ss zzz">
|
||||
<#assign datetimeformat="EEE, dd MMM yyyy HH:mm:ss zzz">
|
||||
<link>${spaceref}</link>
|
||||
<description>Recent Changes to '${space.name}'</description>
|
||||
<language>en-us</language>
|
||||
|
@@ -231,14 +231,58 @@ public final class AuthenticationHelper
|
||||
// setup the authentication context
|
||||
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
|
||||
AuthenticationService auth = (AuthenticationService)wc.getBean(AUTHENTICATION_SERVICE);
|
||||
UserTransaction tx = null;
|
||||
try
|
||||
{
|
||||
auth.validate(ticket);
|
||||
|
||||
HttpSession session = httpRequest.getSession();
|
||||
User user = (User)session.getAttribute(AuthenticationHelper.AUTHENTICATION_USER);
|
||||
if (user == null)
|
||||
{
|
||||
// need to create the User instance if not already available
|
||||
String currentUsername = auth.getCurrentUserName();
|
||||
|
||||
ServiceRegistry services = BaseServlet.getServiceRegistry(context);
|
||||
tx = services.getTransactionService().getUserTransaction();
|
||||
tx.begin();
|
||||
|
||||
NodeService nodeService = services.getNodeService();
|
||||
PersonService personService = (PersonService)wc.getBean(PERSON_SERVICE);
|
||||
NodeRef personRef = personService.getPerson(currentUsername);
|
||||
user = new User(currentUsername, auth.getCurrentTicket(), personRef);
|
||||
NodeRef homeRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER);
|
||||
|
||||
// check that the home space node exists - else Login cannot proceed
|
||||
if (nodeService.exists(homeRef) == false)
|
||||
{
|
||||
throw new InvalidNodeRefException(homeRef);
|
||||
}
|
||||
user.setHomeSpaceId(homeRef.getId());
|
||||
|
||||
tx.commit();
|
||||
tx = null; // clear this so we know not to rollback
|
||||
|
||||
// store the User object in the Session - the authentication servlet will then proceed
|
||||
session.setAttribute(AuthenticationHelper.AUTHENTICATION_USER, user);
|
||||
}
|
||||
}
|
||||
catch (AuthenticationException authErr)
|
||||
{
|
||||
return AuthenticationStatus.Failure;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
// Some other kind of serious failure
|
||||
AuthenticationService unprotAuthService = (AuthenticationService)wc.getBean(UNPROTECTED_AUTH_SERVICE);
|
||||
unprotAuthService.invalidateTicket(unprotAuthService.getCurrentTicket());
|
||||
unprotAuthService.clearCurrentSecurityContext();
|
||||
return AuthenticationStatus.Failure;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
|
||||
// Set the current locale
|
||||
I18NUtil.setLocale(Application.getLanguage(httpRequest.getSession()));
|
||||
|
@@ -114,7 +114,7 @@ public class CommandServlet extends BaseServlet
|
||||
|
||||
// validate that the processor has everything it needs to run the command
|
||||
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
||||
if (processor.validateArguments(serviceRegistry, args) == false)
|
||||
if (processor.validateArguments(serviceRegistry, command, args) == false)
|
||||
{
|
||||
redirectToLoginPage(req, res, getServletContext());
|
||||
return;
|
||||
|
@@ -25,7 +25,6 @@ import java.util.StringTokenizer;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -35,11 +34,13 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.repo.component.template.DefaultModelHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -164,7 +165,7 @@ public class TemplateContentServlet extends BaseServlet
|
||||
}
|
||||
|
||||
// create the model - put the supplied noderef in as space/document as appropriate
|
||||
Object model = getModel(serviceRegistry, req.getSession(), nodeRef);
|
||||
Object model = getModel(serviceRegistry, req, res, nodeRef);
|
||||
|
||||
// process the template against the node content directly to the response output stream
|
||||
// assuming the repo is capable of streaming in chunks, this should allow large files
|
||||
@@ -218,19 +219,28 @@ public class TemplateContentServlet extends BaseServlet
|
||||
*
|
||||
* @return an object model ready for executing template against
|
||||
*/
|
||||
private Object getModel(ServiceRegistry services, HttpSession session, NodeRef nodeRef)
|
||||
private Object getModel(ServiceRegistry services, HttpServletRequest req, HttpServletResponse res, NodeRef nodeRef)
|
||||
{
|
||||
// build FreeMarker default model and merge
|
||||
Map root = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(session));
|
||||
Map root = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(req.getSession()));
|
||||
|
||||
// put the current NodeRef in as "space" and "document"
|
||||
TemplateNode node = new TemplateNode(nodeRef, services, DefaultModelHelper.imageResolver);
|
||||
TemplateNode node = new TemplateNode(nodeRef, services, this.imageResolver);
|
||||
root.put("space", node);
|
||||
root.put("document", node);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/** Template Image resolver helper */
|
||||
private TemplateImageResolver imageResolver = new TemplateImageResolver()
|
||||
{
|
||||
public String resolveImagePathForName(String filename, boolean small)
|
||||
{
|
||||
return Utils.getFileTypeImage(getServletContext(), filename, small);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to generate a URL to process a template against a node.
|
||||
* <p>
|
||||
|
@@ -37,9 +37,9 @@ public abstract class BaseNodeCommandProcessor implements CommandProcessor
|
||||
protected NodeRef targetRef;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.app.servlet.command.CommandProcessor#validateArguments(org.alfresco.service.ServiceRegistry, java.lang.String[])
|
||||
* @see org.alfresco.web.app.servlet.command.CommandProcessor#validateArguments(org.alfresco.service.ServiceRegistry, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
public boolean validateArguments(ServiceRegistry serviceRegistry, String[] args)
|
||||
public boolean validateArguments(ServiceRegistry serviceRegistry, String command, String[] args)
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
|
@@ -42,11 +42,13 @@ public interface CommandProcessor
|
||||
* convert the supplied arguments to the objects it expects, and also check any permissions
|
||||
* that are required by the current user to execute the command.
|
||||
*
|
||||
* @param serviceRegistry ServiceRegistry instance
|
||||
* @param command Name of the command the arguments are for
|
||||
* @param args String[] of the remaining URL arguments to the command servlet.
|
||||
*
|
||||
* @return true if the command can be executed by the current user given the supplied args.
|
||||
*/
|
||||
public boolean validateArguments(ServiceRegistry serviceRegistry, String[] args);
|
||||
public boolean validateArguments(ServiceRegistry serviceRegistry, String command, String[] args);
|
||||
|
||||
/**
|
||||
* Process the supplied command name. It is the responsibility of the Command Processor
|
||||
|
@@ -40,6 +40,7 @@ import javax.faces.el.EvaluationException;
|
||||
import javax.faces.el.MethodBinding;
|
||||
import javax.faces.event.AbortProcessingException;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -1111,6 +1112,39 @@ public final class Utils
|
||||
* @return the image path for the specified node type or the default icon if not found
|
||||
*/
|
||||
public static String getFileTypeImage(String name, boolean small)
|
||||
{
|
||||
return getFileTypeImage(FacesContext.getCurrentInstance(), null, name, small);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the image path to the filetype icon for the specified file name string
|
||||
*
|
||||
* @param fc FacesContext
|
||||
* @param name File name to build filetype icon path for
|
||||
* @param small True for the small 16x16 icon or false for the large 32x32
|
||||
*
|
||||
* @return the image path for the specified node type or the default icon if not found
|
||||
*/
|
||||
public static String getFileTypeImage(FacesContext fc, String name, boolean small)
|
||||
{
|
||||
return getFileTypeImage(fc, null, name, small);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the image path to the filetype icon for the specified file name string
|
||||
*
|
||||
* @param sc ServletContext
|
||||
* @param name File name to build filetype icon path for
|
||||
* @param small True for the small 16x16 icon or false for the large 32x32
|
||||
*
|
||||
* @return the image path for the specified node type or the default icon if not found
|
||||
*/
|
||||
public static String getFileTypeImage(ServletContext sc, String name, boolean small)
|
||||
{
|
||||
return getFileTypeImage(null, sc, name, small);
|
||||
}
|
||||
|
||||
private static String getFileTypeImage(FacesContext fc, ServletContext sc, String name, boolean small)
|
||||
{
|
||||
String image = (small ? DEFAULT_FILE_IMAGE16 : DEFAULT_FILE_IMAGE32);
|
||||
|
||||
@@ -1130,7 +1164,8 @@ public final class Utils
|
||||
image = (small ? IMAGE_PREFIX16 : IMAGE_PREFIX32) + ext + IMAGE_POSTFIX;
|
||||
|
||||
// does this image exist on the web-server?
|
||||
if (FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(image) != null)
|
||||
if ((fc != null && fc.getExternalContext().getResourceAsStream(image) != null) ||
|
||||
(sc != null && sc.getResourceAsStream(image) != null))
|
||||
{
|
||||
// found the image for this extension - save it for later
|
||||
s_fileExtensionMap.put(key, image);
|
||||
|
Reference in New Issue
Block a user