|
Author: adrianc
Date: Mon Jan 11 19:35:34 2010 New Revision: 898027 URL: http://svn.apache.org/viewvc?rev=898027&view=rev Log: Fixed OfbizSecurityTransform.java, added Freemarker templates to the execution path. Modified: ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java Modified: ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java?rev=898027&r1=898026&r2=898027&view=diff ============================================================================== --- ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java (original) +++ ofbiz/branches/executioncontext20091231/framework/api/src/org/ofbiz/api/authorization/OfbizSecurityTransform.java Mon Jan 11 19:35:34 2010 @@ -19,7 +19,6 @@ package org.ofbiz.api.authorization; import java.io.IOException; -import java.security.AccessControlException; import java.security.Permission; import java.util.Map; @@ -27,13 +26,12 @@ import org.ofbiz.base.util.Debug; import freemarker.core.Environment; -import freemarker.ext.beans.BeanModel; +import freemarker.ext.beans.StringModel; import freemarker.template.SimpleScalar; -import freemarker.template.Template; import freemarker.template.TemplateDirectiveBody; +import freemarker.template.TemplateDirectiveModel; import freemarker.template.TemplateException; import freemarker.template.TemplateModel; -import freemarker.template.TemplateDirectiveModel; /** * OfbizSecurityTransform - Security-aware Freemarker transform. @@ -47,36 +45,47 @@ if (body == null) { return; } - SimpleScalar obj = (SimpleScalar) params.get("artifactId"); - if (obj == null) { + String artifactId = toString(params.get("artifactId")); + if (artifactId == null) { Debug.logError("artifactId parameter not found, unable to execute transform", module); return; } - String artifactId = obj.getAsString(); - obj = (SimpleScalar) params.get("permission"); - if (obj == null) { + String permStr = toString(params.get("permission")); + if (permStr == null) { Debug.logError("permission parameter not found, unable to execute transform", module); return; } - String permStr = obj.getAsString(); Permission permission = BasicPermissions.ConversionMap.get(permStr.toUpperCase()); if (permission == null) { Debug.logError("Unknown permission \"" + permStr + "\", unable to execute transform", module); return; } - BeanModel contextBean = (BeanModel)env.getVariable("executionContext"); - if (contextBean == null) { - Debug.logError("ExecutionContext not found, unable to execute transform", module); - return; - } - Template template = env.getTemplate(); - String location = template.getName(); - ThreadContext.pushExecutionArtifact(location, artifactId); - AccessController accessController = ThreadContext.getAccessController(); try { - accessController.checkPermission(permission); + ThreadContext.pushExecutionArtifact(module, artifactId); + ThreadContext.getAccessController().checkPermission(permission); body.render(env.getOut()); - } catch (AccessControlException e) {} - ThreadContext.popExecutionArtifact(); + } catch (Exception e) { + } finally { + ThreadContext.popExecutionArtifact(); + } + } + + protected static String toString(Object freeMarkerObject) { + String result = null; + if (freeMarkerObject != null) { + try { + StringModel modelObj = (StringModel) freeMarkerObject; + result = modelObj.getAsString(); + } catch (Exception e) { + try { + SimpleScalar scalarObj = (SimpleScalar) freeMarkerObject; + result = scalarObj.getAsString(); + } catch (Exception e2) {} + } + if (result != null) { + result = result.replace("/", ""); + } + } + return result; } } Modified: ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java?rev=898027&r1=898026&r2=898027&view=diff ============================================================================== --- ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java (original) +++ ofbiz/branches/executioncontext20091231/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java Mon Jan 11 19:35:34 2010 @@ -19,13 +19,13 @@ package org.ofbiz.widget.screen; import java.io.IOException; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; import java.util.Map; import javolution.util.FastMap; +import org.ofbiz.api.context.ThreadContext; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.StringUtil; @@ -44,7 +44,6 @@ import freemarker.ext.beans.StringModel; import freemarker.template.Configuration; import freemarker.template.Template; -import freemarker.template.TemplateException; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; @@ -188,41 +187,37 @@ */ if (location.endsWith(".ftl")) { - try { - Map<String, ? extends Object> parameters = UtilGenerics.checkMap(context.get("parameters")); - boolean insertWidgetBoundaryComments = ModelWidget.widgetBoundaryCommentsEnabled(parameters); - if (insertWidgetBoundaryComments) { + Map<String, ? extends Object> parameters = UtilGenerics.checkMap(context.get("parameters")); + Template template = null; + boolean insertWidgetBoundaryComments = ModelWidget.widgetBoundaryCommentsEnabled(parameters); + if (insertWidgetBoundaryComments) { + try { writer.append(HtmlWidgetRenderer.formatBoundaryComment("Begin", "Template", location)); + if (location.endsWith(".fo.ftl")) { // FOP can't render correctly escaped characters + template = FreeMarkerWorker.getTemplate(location); + } else { + template = FreeMarkerWorker.getTemplate(location, specialTemplateCache, specialConfig); + } + } catch (Exception e) { + String errMsg = "Error rendering included template at location [" + location + "]: "; + Debug.logError(e, errMsg, module); + writeError(writer, errMsg + e.toString()); + return; } - - //FreeMarkerWorker.renderTemplateAtLocation(location, context, writer); - Template template = null; - if (location.endsWith(".fo.ftl")) { // FOP can't render correctly escaped characters - template = FreeMarkerWorker.getTemplate(location); - } else { - template = FreeMarkerWorker.getTemplate(location, specialTemplateCache, specialConfig); - } + } + try { + String artifactName = template.getName().replace("component://", "").replace(".ftl", ""); + ThreadContext.pushExecutionArtifact(location, artifactName); FreeMarkerWorker.renderTemplate(template, context, writer); - if (insertWidgetBoundaryComments) { writer.append(HtmlWidgetRenderer.formatBoundaryComment("End", "Template", location)); } - } catch (IllegalArgumentException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - writeError(writer, errMsg); - } catch (MalformedURLException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - writeError(writer, errMsg); - } catch (TemplateException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); - Debug.logError(e, errMsg, module); - writeError(writer, errMsg); - } catch (IOException e) { - String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString(); + } catch (Exception e) { + String errMsg = "Error rendering included template at location [" + location + "]: "; Debug.logError(e, errMsg, module); - writeError(writer, errMsg); + writeError(writer, errMsg + e.toString()); + } finally { + ThreadContext.popExecutionArtifact(); } } else { throw new IllegalArgumentException("Rendering not yet supported for the template at location: " + location); |
| Free forum by Nabble | Edit this page |
