Beispiel #1
0
  @Override
  public View match(ActionContext actionContext) {

    if (!enable) {
      return null;
    }
    String sessionID = SessionUtil.getSessionId(actionContext.getRequest());
    String path = actionContext.getRequest().getServletPath();

    log.info("Auth for PATH:[" + path + "]");
    System.out.println("excludePaths:" + Json.toJson(excludePaths));
    if (excludePaths.contains(path)) {
      log.info("[pass] path:[" + path + "]");
      return null;
    }

    if (sessionID == null || sessionID.trim().equals("")) {
      handleResponse(actionContext.getRequest(), actionContext.getResponse());
      return new VoidView();
    }
    for (String url : patternMap.keySet()) {
      Matcher matcher = patternMap.get(url).matcher(path);
      if (matcher.find()) {
        int auth = authMap.get(url);
        log.debug("Path:{" + url + "] auth:[" + auth + ']');
        Integer sessionAuth =
            (Integer) SessionUtil.getFromSession("role", actionContext.getRequest());
        if (sessionAuth == null || sessionAuth > auth) {
          handleResponse(actionContext.getRequest(), actionContext.getResponse());
          return new VoidView();
        } else {
          log.info("[pass] path:[" + path + "]");
          return null;
        }
      }
    }

    // not find matcher

    int auth = PropertiesReader.getPropertiesInt("doe.defaultrole");
    Integer sessionAuth = (Integer) SessionUtil.getFromSession("role", actionContext.getRequest());
    log.info("sessionAuth: " + sessionAuth);
    if (sessionAuth == null || (sessionAuth >= auth && !path.equals("/"))) {
      handleResponse(actionContext.getRequest(), actionContext.getResponse());
      return new VoidView();
    } else if (sessionAuth == auth && path.equals("/")) {
      try {
        actionContext
            .getResponse()
            .sendRedirect(actionContext.getRequest().getContextPath() + studentligin);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      return new VoidView();
    } else {
      log.info("[pass] path:[" + path + "]");
      return null;
    }
  }