001
014
015 package com.liferay.portal.template;
016
017 import com.liferay.portal.kernel.template.Template;
018 import com.liferay.portal.kernel.template.TemplateException;
019 import com.liferay.portal.security.lang.PortalSecurityManagerThreadLocal;
020 import com.liferay.portal.security.pacl.PACLPolicy;
021 import com.liferay.portal.security.pacl.PACLPolicyManager;
022 import com.liferay.portal.util.ClassLoaderUtil;
023
024 import java.io.Writer;
025
026 import javax.servlet.http.HttpServletRequest;
027
028
031 public class PACLTemplateWrapper implements Template {
032
033 public static Template getTemplate(Template template) {
034 ClassLoader contextClassLoader =
035 ClassLoaderUtil.getContextClassLoader();
036 ClassLoader portalClassLoder = ClassLoaderUtil.getPortalClassLoader();
037
038 if (contextClassLoader == portalClassLoder) {
039 return template;
040 }
041
042 PACLPolicy paclPolicy = PACLPolicyManager.getPACLPolicy(
043 contextClassLoader);
044
045 return new PACLTemplateWrapper(template, paclPolicy);
046 }
047
048 public PACLTemplateWrapper(Template template, PACLPolicy policy) {
049 if (template == null) {
050 throw new IllegalArgumentException("Template is null");
051 }
052
053 _template = template;
054 _paclPolicy = policy;
055 }
056
057 public Object get(String key) {
058 return _template.get(key);
059 }
060
061 public void prepare(HttpServletRequest request) {
062 _template.prepare(request);
063 }
064
065 public boolean processTemplate(Writer writer) throws TemplateException {
066 PACLPolicy paclPolicy =
067 PortalSecurityManagerThreadLocal.getPACLPolicy();
068
069 try {
070 PortalSecurityManagerThreadLocal.setPACLPolicy(_paclPolicy);
071
072 return _template.processTemplate(writer);
073 }
074 finally {
075 PortalSecurityManagerThreadLocal.setPACLPolicy(paclPolicy);
076 }
077 }
078
079 public void put(String key, Object value) {
080 _template.put(key, value);
081 }
082
083 private PACLPolicy _paclPolicy;
084 private Template _template;
085
086 }