Package net.caprazzi.minima.framework

Examples of net.caprazzi.minima.framework.RequestInfo


      FilterChain chain) throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
   
    RequestInfo info = RequestInfo.fromRequest(req);
   
    boolean hasSession = (req.getSession(false) != null);
   
    boolean allowEdit = !requireSessionToEdit || hasSession;
    boolean allowView = allowEdit || (!requireSessionToView || hasSession);
   
    request.setAttribute("minima.readonly", !allowEdit);
   
    // redirect /index to /login if login required
    if (info.isGet("{ctx}/index") && !allowView) {
      resp.sendRedirect(req.getContextPath() + "/login");
      return;
    }

    // redirect /login to /index if login not required
    if (info.isGet("{ctx}/login") && allowEdit && allowView) {
      resp.sendRedirect(req.getContextPath() + "/index");
      return;
    }
   
    // let pass requests to /login if login is required
    if (info.isPath("{ctx}/login") && (!allowView || !allowEdit)) {
      chain.doFilter(request, response);
      return;
    }
   
    // only show logout if there is a session
    if (info.isGet("{ctx}/logout") && !hasSession) {
      resp.sendRedirect(req.getContextPath() + "/index");
      return;
    }
   
    // stop all other reads if view is not allowed
    if (info.isRead() && !allowView) {
      resp.sendError(403);
      return;
    }
   
    // stop all other writes if view is not required
    if (info.isWrite() && !allowEdit) {
      resp.sendError(403);
      return;
    }
   
    chain.doFilter(request, response);
View Full Code Here


  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
   
    RequestInfo info = RequestInfo.fromRequest(req);
       
    if (info.isPath(req.getContextPath() + "/app/libs")) {
      handleLibsRequest(req, resp);
      return;
    }
   
    if (info.isPath(req.getContextPath() + "/app/main")) {
      handleMainRequest(req, resp);
      return;
    }
   
    if (info.isPath(req.getContextPath() + "/app/css")) {
      handleCssRequest(req, resp);
      return;
    }
   
    String path = req.getRequestURI().substring(req.getContextPath().length());
View Full Code Here

 
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
   
    RequestInfo info = RequestInfo.fromRequest(req);
    if (!info.isPath(req.getContextPath() + "/login")) {
      resp.sendError(404);
      return;
    }
   
    String password = req.getParameter("password");
View Full Code Here

 
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
   
    RequestInfo info = RequestInfo.fromRequest(req);
    if (info.isPath(req.getContextPath() + "/logout")) {
      if (req.getSession(false) != null) {
        req.getSession().invalidate();
       
      }     
      resp.sendRedirect(req.getContextPath() + "/index");
View Full Code Here

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
   
    RequestInfo info = RequestInfo.fromRequest(req);
    String contextPath = req.getContextPath();
   
    if (info.isPath(contextPath + "/")) {
      resp.sendRedirect(contextPath + "/index");
      return;
    }
   
    if (!info.isPath(contextPath +  "/index")) {
      resp.sendError(404);
      return;
    }
   
    Boolean readonly = req.getParameter("readonly") != null
View Full Code Here

 
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
   
    RequestInfo info = RequestInfo.fromRequest(req);
    if (info.isPath(webroot + "/data/stories")) {
      sendBoard(resp);
      return;
    }
    sendError(resp, 404, "not found");
  }
View Full Code Here

    if (req.getAttribute("minima.readonly").equals(true)) {
      sendError(resp, 403, "not authorised");
      return;
    }
   
    RequestInfo info = RequestInfo.fromRequest(req);
    String senderTag = req.getHeader("X-CLIENT-TAG");
   
    if (info.isPath(webroot + "/data/stories/_/_")) {
      String id = info.get(-2);
      int revision = Integer.parseInt(info.get(-1));   
      SlabsDoc note = Note.fromJson(req.getInputStream());
      save(senderTag, id, revision, note, resp);
      return;
    }
   
    if (info.isPath(webroot + "/data/lists/_/_")) {
      String id = info.get(-2);
      int revision = Integer.parseInt(info.get(-1));
      List list = List.fromJson(req.getInputStream());
      save(senderTag, id, revision, list, resp);
      return;
    }
   
View Full Code Here

TOP

Related Classes of net.caprazzi.minima.framework.RequestInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.