Exemplo n.º 1
0
  @Override
  public void intercept(ActionInvocation ai) {
    HttpServletResponse response = ai.getController().getResponse();
    String ossMainUrl = PropertyUtil.urls.getProperty("meurl");
    String szyLoginUrl = PropertyUtil.urls.getProperty("loginurl");
    HttpSession session = ai.getController().getSession();
    String json = ai.getController().getPara("loginUser");

    if (json != null) {
      try {
        Account account = Account.parse(json);
        session.setAttribute("loginUser", account);

        //                MySessionContext.AddSession(json,session);

        flushCache(response);
        // ai.getController().redirect(ossMainUrl);
        // return;
      } catch (Exception e) {
        flushCache(response);
        // ai.getController().redirect(ossMainUrl);
        // return;
      }
    } else {
      if (session.getAttribute("loginUser") == null) {
        String url = szyLoginUrl + "?url=" + ossMainUrl;
        flushCache(response);
        ai.getController().redirect(url);
        return;
      }
    }
    ai.invoke();
  }
Exemplo n.º 2
0
 public void intercept(ActionInvocation ai) {
   Controller cl = ai.getController();
   Object user = cl.getSessionAttr(Constants.SESSION_MEMBER);
   if (user == null) {
     cl.render("/front/test_member_login.jsp");
   } else {
     ai.invoke();
   }
 }
  @Override
  public void intercept(ActionInvocation ai) {
    ai.invoke();

    Controller c = ai.getController();
    HttpSession hs = c.getSession(false);
    if (hs != null) {
      c.setAttr("session", new HttpSessionHashModel(hs, ObjectWrapper.DEFAULT_WRAPPER));
    }
  }
 @Override
 public void intercept(ActionInvocation ai) {
   if (ai.getController().getSessionAttr("manage") != null) {
     ai.invoke();
   } else {
     try {
       ai.getController().getResponse().sendRedirect("../index");
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 5
0
 @Override
 public void intercept(ActionInvocation ai) {
   Controller controller = ai.getController();
   try {
     User user = (User) controller.getSession().getAttribute("loginUser");
     if (user == null) {
       controller.renderJson(JsonHelp.buildFailed());
     }
     controller.renderJson(JsonHelp.buildSuccess(JsonKit.toJson(user)));
     System.out.println(user.getStr("email"));
   } catch (Exception e) {
     e.printStackTrace();
     controller.renderJson(JsonHelp.buildFailed());
   }
   ai.invoke();
 }
Exemplo n.º 6
0
  /**
   * 该拦截器取得当前ActionPath,从Cache中检查是否有传送给当前Action的Flash对象Map 若有,则遍历Map,并将所有key,value注入到当前的request请求中。
   */
  public void intercept(ActionInvocation ai) {
    Controller c = ai.getController();
    HttpSession session = c.getSession(false);
    if (null == session) {
      return;
    }

    // String curAction = ai.getViewPath()+ai.getMethodName();
    String curAction = c.getRequest().getServletPath();
    ConcurrentHashMap<String, Object> flashMap = c.getFlashManager().getFlash(session, curAction);
    if (flashMap != null) {
      for (Entry<String, Object> flashEntry : flashMap.entrySet()) {
        c.setAttr(flashEntry.getKey(), flashEntry.getValue());
      }
    }
    ai.invoke();
  }
  @Override
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    int id = controller.getParaToInt("id", 0);
    if (id == 0) {
      controller.renderJson("msg", "id is blank");
      return;
    }

    User targetUser = UserService.getById(id);
    if (targetUser == null) {
      controller.renderJson("msg", "no such user");
      return;
    }

    controller.setAttr("targetUser", targetUser);

    ai.invoke();
  }
 @Override
 public void intercept(ActionInvocation ai) {
   String actionKey = ai.getActionKey();
   String uri = actionKey.substring(actionKey.lastIndexOf("/") + 1, actionKey.length());
   Controller controller = ai.getController();
   if (IGNORE_URLS.contains(uri) || !uri.contains("admin")) {
     ai.invoke();
   } else {
     Admin admin = (Admin) controller.getSession().getAttribute("_ADMIN_USER");
     if (null != admin) {
       Method method = ai.getMethod();
       if (method.isAnnotationPresent(Record.class)) {
         Record record = method.getAnnotation(Record.class);
         logger.info(
             "==== Admin transaction here! --operation "
                 + record.value()
                 + " --target "
                 + record.target().getSimpleName());
         AdminTransaction transaction = new AdminTransaction();
         StringBuilder operation = new StringBuilder(record.value().toString() + " ");
         if (OperationType.ADD == record.value()) {
           operation.append(record.target().getSimpleName().toLowerCase());
         }
         transaction
             .set("adminId", admin.get("adminId"))
             .set("operation", operation.toString())
             .set("target", record.target().getSimpleName())
             .set(
                 "message",
                 record.value().getMessage() + " (" + record.target().getSimpleName() + ")")
             .set("createdTime", new Date())
             .save();
       }
       ai.invoke();
     } else {
       controller.redirect("/admin/login");
     }
   }
 }
Exemplo n.º 9
0
  /**
   * add edit 无需处理
   *
   * <p>GET /user ---> index GET /user/id ---> show POST /user ---> save PUT /user/id ---> update
   * DELECT /user/id ---> delete
   */
  public void intercept(ActionInvocation ai) {
    // 阻止 JFinal 原有规则 action 请求
    Controller controller = ai.getController();
    Boolean isRestfulForward = controller.getAttr(isRestfulForwardKey);
    String methodName = ai.getMethodName();
    if (set.contains(methodName) && isRestfulForward == null) {
      ai.getController().renderError(404);
      return;
    }

    if (isRestfulForward != null && isRestfulForward) {
      ai.invoke();
      return;
    }

    String controllerKey = ai.getControllerKey();
    String method = controller.getRequest().getMethod().toUpperCase();
    String urlPara = controller.getPara();
    if ("GET".equals(method)) {
      if (urlPara != null && !"edit".equals(methodName)) {
        controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
        controller.forwardAction(controllerKey + "/show/" + urlPara);
        return;
      }
    } else if ("POST".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/save");
      return;
    } else if ("PUT".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/update/" + urlPara);
      return;
    } else if ("DELETE".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/delete/" + urlPara);
      return;
    }

    ai.invoke();
  }