Uploaded image for project: 'Shiro'
  1. Shiro
  2. SHIRO-546

DefaultWebSessionManager onStart might produce nullPointer Exception

    XMLWordPrintableJSON

Details

    • Patch, Important

    Description

      DefaultWebSessionManager#onStart() when you get the HttpServletRequest it might be null a throw a null pointer exception so it might need a little validation

      from

         @Override
          protected void onStart(Session session, SessionContext context) {
              super.onStart(session, context);
      
              if (!WebUtils.isHttp(context)) {
                  log.debug("SessionContext argument is not HTTP compatible or does not have an HTTP request/response " +
                          "pair. No session ID cookie will be set.");
                  return;
      
              }
              HttpServletRequest request = WebUtils.getHttpRequest(context);
              HttpServletResponse response = WebUtils.getHttpResponse(context);
      
              if (isSessionIdCookieEnabled()) {
                  Serializable sessionId = session.getId();
                  storeSessionId(sessionId, request, response);
              } else {
                  log.debug("Session ID cookie is disabled.  No cookie has been set for new session with id {}", session.getId());
              }
      
              request.removeAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE);
              request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_IS_NEW, Boolean.TRUE);
          }

      to

          @Override
          protected void onStart(Session session, SessionContext context) {
              super.onStart(session, context);
      
              if (!WebUtils.isHttp(context)) {
                  log.debug("SessionContext argument is not HTTP compatible or does not have an HTTP request/response " +
                          "pair. No session ID cookie will be set.");
                  return;
      
              }
              HttpServletRequest request = WebUtils.getHttpRequest(context);
              HttpServletResponse response = WebUtils.getHttpResponse(context);
      
              if (isSessionIdCookieEnabled()) {
                  Serializable sessionId = session.getId();
                  storeSessionId(sessionId, request, response);
              } else {
                  log.debug("Session ID cookie is disabled.  No cookie has been set for new session with id {}", session.getId());
              }
      
              if (request != null) {
                  request.removeAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE);
                  request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_IS_NEW, Boolean.TRUE);
              }
              
          }

      Attachments

        Activity

          People

            Unassigned Unassigned
            AIsaac Ariel Isaac
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 25m
                25m
                Remaining:
                Remaining Estimate - 25m
                25m
                Logged:
                Time Spent - Not Specified
                Not Specified