tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakarta Tomcat Newsgroup (@Basebeans.com) <jakarta-...@basebeans.com>
Subject Saving Userid under Form-based Security
Date Wed, 03 Apr 2002 16:40:02 GMT
Subject: Saving Userid under Form-based Security
From: "Dave Butler" <davebutlerREMOVE@hotmail.com>
 ===
For convenience, I wish to save the userid in a cookie when the form-based
login.jsp is processed. I have tried a few different approaches, without
success. My current effort is to use a Filter, which includes the following
methods:

(The environment is Tomcat 4.0.2 running on AIX 4.3.3. The browser is IE 6.0
under Windows 2000)

//--------------------------------------------------------------------------
---
   public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain chain)
                        throws IOException, ServletException {

      if (filterConfig == null)
         return;

      chain.doFilter(request, response);

      HttpSession session = ((HttpServletRequest)request).getSession();
      if (session.getAttribute("savedUserid") == null) {
         saveUserid(request, response);
         session.setAttribute("savedUserid", Boolean.TRUE);
      }
   }

   public void init(FilterConfig filterConfig) {
      this.filterConfig = filterConfig;
   }

   public void destroy() {}

   private void saveUserid(ServletRequest request, ServletResponse response)
{
      String userid = ((HttpServletRequest)request).getRemoteUser();
      System.out.println("In Filter, saving userid (" + userid + ")");

      if ((userid != null) && (userid.length() != 0)) {
         Cookie frswebCookie = new LongLivedCookie("userid", userid);
         ((HttpServletResponse)response).addCookie(frswebCookie);
      }

   }
//--------------------------------------------------------------------------
---

My Catalina.out log shows "In Filter, saving userid (name)", but it does not
seem to be working. I find no evidence of a cookie being created. A couple
of questions:

1) Is this the best approach for what I am trying to accomplish?
2) Why does this approach not work? Any debugging suggestions?

Thanks,

Dave Butler



--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message