package jpaoletti.jpm.struts.tags;

import javax.servlet.jsp.JspException;
import jpaoletti.jpm.struts.PMStrutsContext;

/**
 *
 * @author jpaoletti
 */
public class CheckPermTag extends PMTags {

    private String perm;

    @Override
    public int doStartTag() throws JspException {
        final PMStrutsContext ctx = (PMStrutsContext) pageContext.getRequest().getAttribute("ctx");
        if ( ctx.getUser() != null && ctx.getUser().hasPermission(getPerm())) {
            return EVAL_BODY_AGAIN;
        } else {
            return SKIP_BODY;
        }
    }

    @Override
    public int doEndTag() {
        return EVAL_PAGE;
    }

    public String getPerm() {
        return perm;
    }

    public void setPerm(String perm) {
        this.perm = perm;
    }
}

@@ -392,17 +392,36 @@
     if (
- 
+%22%22.equals(perm) %7C%7C (
 ctx.getU
@@ -476,16 +476,17 @@
 Perm()))
+)
  %7B%0A     

empty perm is considered valid