Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
BZ-1021830 - Unexpected Error (CSRF token missing) when clicking go b…
Browse files Browse the repository at this point in the history
…ack in Import Dashboards panel
  • Loading branch information
dgutierr committed Oct 23, 2013
1 parent 282a2bf commit a6ad297
Show file tree
Hide file tree
Showing 33 changed files with 206 additions and 204 deletions.
Expand Up @@ -76,10 +76,12 @@ public String toString(Object element, Locale l) {
ResourceBundle i18n = ResourceBundle.getBundle("org.jboss.dashboard.displayer.messages", l);

if (element instanceof DataProvider) {
return i18n.getString("element.dataprovider") + "=" + ((DataProvider) element).getCode();
DataProvider dp = (DataProvider) element;
return dp.getCode() + ", " + dp.getDescription(l);
}
if (element instanceof KPI) {
return i18n.getString("element.kpi") + "=" + ((KPI) element).getCode();
KPI kpi = (KPI) element;
return kpi.getCode() + ", " + kpi.getDescription(l);
}
return element.toString();
}
Expand Down
Expand Up @@ -181,7 +181,7 @@ public boolean hasError(String fieldName) {
public void actionVoid(CommandRequest request) {
}

static class HandlerTrace extends CodeBlockTrace {
public static class HandlerTrace extends CodeBlockTrace {

protected String bean;
protected String action;
Expand All @@ -201,7 +201,7 @@ public CodeBlockType getType() {
}

public String getDescription() {
return bean + "." + action + "()";
return bean + (StringUtils.isBlank(action) ? "" : "." + action + "()");
}

public Map<String,Object> getContext() {
Expand All @@ -212,7 +212,9 @@ protected Map<String,Object> buildContext() {
Map<String,Object> ctx = new LinkedHashMap<String,Object>();
ctx.put("Bean name", bean);
ctx.put("Bean scope", scope);
ctx.put("Bean action", action);
if (!StringUtils.isBlank(action)) {
ctx.put("Bean action", action);
}

ThreadProfile threadProfile = Profiler.lookup().getCurrentThreadProfile();
if (threadProfile != null) threadProfile.addContextProperties(ctx);
Expand Down
@@ -0,0 +1,109 @@
/**
* Copyright (C) 2012 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.dashboard.ui.taglib;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.jboss.dashboard.error.ErrorManager;
import org.jboss.dashboard.error.ErrorReport;
import org.jboss.dashboard.factory.Factory;
import org.jboss.dashboard.profiler.CodeBlockTrace;
import org.jboss.dashboard.profiler.CodeBlockType;
import org.jboss.dashboard.profiler.CoreCodeBlockTypes;
import org.jboss.dashboard.ui.components.ErrorReportHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseTag extends BodyTagSupport {

/** Logger */
private static transient Logger log = LoggerFactory.getLogger(BaseTag.class.getName());

/** The JSP to render if an error occurs. */
protected String errorPage = "/error.jsp";

public String getErrorPage() {
return errorPage;
}

public void setErrorPage(String errorPage) {
this.errorPage = errorPage;
}

public void jspInclude(String page) {
CodeBlockTrace trace = new JSPIncludeTrace(page).begin();
try {
pageContext.include(page);
} catch (Throwable t) {
handleError(t);
} finally {
trace.end();
}
}

protected void handleError(Throwable t) {
ErrorReport errorReport = ErrorManager.lookup().notifyError(t, true);
CodeBlockTrace trace = new JSPIncludeTrace(errorPage).begin();
try {
// Display the error page.
ErrorReportHandler errorHandler = (ErrorReportHandler) Factory.lookup("org.jboss.dashboard.error.JSPIncludeErrorHandler");
errorHandler.setErrorReport(errorReport);
errorHandler.setCloseEnabled(false);
pageContext.getRequest().setAttribute("errorHandlerName", "org.jboss.dashboard.error.JSPIncludeErrorHandler");
pageContext.include(errorPage);
} catch (Throwable t1) {
log.error("JSP error processing failed.", t1);
try {
// If the error JSP rendering fails then print a simple error message.
String errorStr = errorReport.printErrorMessage() + "\n\n" + errorReport.printContext(0);
pageContext.getOut().println("<span class=\"skn-error\"><pre>" + errorStr + "</pre></span>");
} catch (Throwable t2) {
log.error("Cannot print a JSP error message.", t2);
}
} finally {
trace.end();
}
}

/**
* The JSPInclude tag profiling trace.
*/
public static class JSPIncludeTrace extends CodeBlockTrace {

protected String jsp;

public JSPIncludeTrace(String jsp) {
super(jsp);
this.jsp = jsp;
}

public CodeBlockType getType() {
return CoreCodeBlockTypes.JSP_PAGE;
}

public String getDescription() {
return jsp;
}

public Map<String,Object> getContext() {
Map<String,Object> m = new HashMap<String, Object>();
m.put("JSP", jsp);
return m;
}
}
}
Expand Up @@ -24,12 +24,7 @@
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.security.Permission;

public class CheckPermissionTag extends BodyTagSupport {

/**
* Logger
*/
private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CheckPermissionTag.class.getName());
public class CheckPermissionTag extends BaseTag {

/**
* The permission to check
Expand Down
Expand Up @@ -29,8 +29,10 @@
import org.jboss.dashboard.ui.components.URLMarkupGenerator;
import org.jboss.dashboard.factory.Factory;

public class ContextTag extends BodyTagSupport {
public class ContextTag extends BaseTag {

private static transient org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ContextTag.class.getName());

public static final String INCLUDE_HOST = "org.jboss.dashboard.ui.taglib.ContextTag/includeHost";

private String uri;
Expand Down
Expand Up @@ -70,7 +70,7 @@
* @deprecated This class enforces use of JAVA blocks inside JSP's. Use of formatters avoids this incorrect pattern.
*/

public class DefineObjectsTag extends TagSupport {
public class DefineObjectsTag extends BaseTag {

/**
* Logger
Expand Down
Expand Up @@ -38,20 +38,20 @@
* <p/>
* The following required attribute is defined for this tag:
* <li>
* name (Type: String, required) the name of the String that should be encoded
* name (Type: String, required): the name of the String that should be encoded
* into the namespace of the panel. <br>
* </li>
* <p/>
* An example of a JSP using the encode tag could be:
* <p/>
* <CODE>
* <A HREF=�javascript:<panel:encode name=doFoo()�/>�/>Foo</A>
* &lt;a onclick='&lt;panel:encode name=&quot;doFoo()&quot;/&gt;'&gt;Foo&lt;/a&gt;
* </CODE>
* <p/>
* The example references a JavaScript function with the name doFoo, which is encoded
* The example references a JavaScript function with the name <code>doFoo</code>, which is encoded
* to ensure uniqueness on the workspace page.
*/
public class EncodeTag extends TagSupport {
public class EncodeTag extends BaseTag {

/**
* Logger
Expand Down
Expand Up @@ -29,8 +29,7 @@
/**
*
*/
public class EnvelopeContentTag extends TagSupport {
private static transient org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(EnvelopeContentTag.class.getName());
public class EnvelopeContentTag extends BaseTag {

public static class TEI extends TagExtraInfo {
public VariableInfo[] getVariableInfo(TagData tagData) {
Expand All @@ -43,12 +42,12 @@ public int doStartTag() throws JspException {
try {
new HibernateTxFragment() {
protected void txFragment(Session session) throws Throwable {
pageContext.include("/templates/content.jsp");
jspInclude("/templates/content.jsp");
EnvelopesManager envelopesManager = UIServices.lookup().getEnvelopesManager();
if (envelopesManager.getFinalBodyIncludePages() != null) {
for (int i = 0; i < envelopesManager.getFinalBodyIncludePages().length; i++) {
String page = envelopesManager.getFinalBodyIncludePages()[i];
pageContext.include(page);
jspInclude(page);
}
}
}}.execute();
Expand Down
Expand Up @@ -26,8 +26,7 @@
/**
*
*/
public class EnvelopeFooterTag extends TagSupport {
private static transient org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(EnvelopeFooterTag.class.getName());
public class EnvelopeFooterTag extends BaseTag {

public static final String ENVELOPE_TOKEN = "envelopeFootToken";

Expand All @@ -39,15 +38,8 @@ public VariableInfo[] getVariableInfo(TagData tagData) {
}

public int doStartTag() throws JspException {
try {
pageContext.getRequest().setAttribute(ENVELOPE_TOKEN, Boolean.TRUE);
this.pageContext.include("/templates/footer.jsp");
} catch (IOException e) {
log.error("Error: ", e);
} catch (ServletException e) {
log.error("Error: ", e);
}
pageContext.getRequest().setAttribute(ENVELOPE_TOKEN, Boolean.TRUE);
jspInclude("/templates/footer.jsp");
return SKIP_BODY;
}

}
Expand Up @@ -34,7 +34,8 @@
/**
*
*/
public class EnvelopeHeadTag extends TagSupport {
public class EnvelopeHeadTag extends BaseTag {

private boolean allowScripts = true;
private boolean allowPages = true;
private boolean allowEnvelopes = true;
Expand Down Expand Up @@ -71,24 +72,12 @@ public void doWork() {
if (envelopesManager.getBeforeHeaderIncludePages() != null)
for (int i = 0; i < envelopesManager.getBeforeHeaderIncludePages().length; i++) {
String page = envelopesManager.getBeforeHeaderIncludePages()[i];
try {
pageContext.include(page);
} catch (ServletException e) {
log.error("Error including " + page + " : ", e);
} catch (IOException e) {
log.error("Error including " + page + " : ", e);
}
jspInclude(page);
}
}

try {
if (allowScripts) {
pageContext.include(envelopesManager.getScriptsIncludePage());
}
} catch (ServletException e) {
log.error("Error including " + envelopesManager.getScriptsIncludePage() + " : ", e);
} catch (IOException e) {
log.error("Error including " + envelopesManager.getScriptsIncludePage() + " : ", e);
if (allowScripts) {
jspInclude(envelopesManager.getScriptsIncludePage());
}

List headers;
Expand All @@ -97,13 +86,7 @@ public void doWork() {
if (headers != null)
for (int i = 0; i < headers.size(); i++) {
String page = (String) headers.get(i);
try {
pageContext.include(page);
} catch (ServletException e) {
log.error("Error including " + page + " : ", e);
} catch (IOException e) {
log.error("Error including " + page + " : ", e);
}
jspInclude(page);
}
}
}
Expand Down
Expand Up @@ -29,7 +29,7 @@
/**
* Custom Tag which is used to provide URLs to invoke panels actions
*/
public class HiddenLinkTag extends javax.servlet.jsp.tagext.TagSupport {
public class HiddenLinkTag extends BaseTag {

/**
* Logger
Expand Down

0 comments on commit a6ad297

Please sign in to comment.