Subject: Saving Userid under Form-based Security
From: "Dave Butler" <[EMAIL PROTECTED]>
 ===
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:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to