@Override
  public String render(RenderContext rc) {
    log.debug("render");
    Resource resource = rc.getTargetPage();
    Request request = (Request) rc.getAttribute("request");
    if (request == null)
      throw new RuntimeException("expected to find request in RenderContext attribute");

    PermissionsAuthoriser permissionsAuthoriser =
        RequestContext.getCurrent().get(PermissionsAuthoriser.class);
    if (permissionsAuthoriser == null)
      throw new IllegalStateException("Not found in configuration: " + PermissionsAuthoriser.class);

    Boolean b =
        permissionsAuthoriser.authorise(
            resource, request, request.getMethod(), request.getAuthorization());
    log.debug("result: " + b);
    if (b == null) return null;
    else return b.toString();
  }
示例#2
0
 protected String doProcess(RenderContext rc, Map<String, String> parameters) {
   log.debug("run script: " + script);
   RenderContext rcTarget = rc.getTarget();
   Map map = new HashMap();
   map.put("targetPage", rcTarget.page);
   map.put("params", parameters);
   map.put("rc", rc);
   map.put("request", RequestParams.current());
   map.put("services", new Services());
   Object o = org.mvel.MVEL.eval(script, map);
   commit();
   if (o == null) {
     return null;
   } else if (o instanceof String) {
     String url = (String) o;
     return url;
   } else if (o instanceof CommonTemplated) {
     CommonTemplated ct = (CommonTemplated) o;
     return ct.getHref();
   } else {
     log.warn("unhandled return type: " + o.getClass());
     return rcTarget.page.getHref();
   }
 }