On Sun, 30 Jun 2002, John Baker wrote:
> Date: Sun, 30 Jun 2002 19:00:18 +0100
> From: John Baker <[EMAIL PROTECTED]>
> Reply-To: Tomcat Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Valves, requests and getting the session
>
> Hello.
>
> I'm am trying to write a Valve, very much like SingleSignOn but for our
> authetnication system that uses more than just a username and password. I
> want my Valve to pass login information from one Session to another when a
> user uses different webapps (Contexts).
>
> I am nearly there codewise, but have a small problem. I do not seem to
> be able to get the session from the request! I've tried calling
> request.getSession() and request.getSession(true) yet both return null.
> It's hardly worth pasting, but:
>
> public void invoke(Request request, Response response, ValveContext context)
> throws IOException, ServletException
> {
> System.out.println( ((HttpRequest)request).getSession(true) );
>
> Will always print null.
>
> I assume I can get at the session from this level and I'm obviously doing
> something dumb. Are there any obvious things I should check?
>
Try this slight variation (based on what Catalina does in the getSession()
method of AuthenticatorBase):
HttpServletRequest hrequest = (HttpServletRequest) request.getRequest();
HttpSession session = hrequest.getSession(true);
The code you quoted above shouldn't actually compile, because you're
calling getSession() on the internal HttpRequest interface, but there is
no getSession() method on that interface. You need the extra getRequest()
call to get to the HttpServletRequest object that would be handed to a
servlet -- that's the one with the getSession() method that operates as
you need it to.
> Thanks
>
>
> John Baker
>
Craig
>
> --
> John Baker, BSc CS.
> Java Developer, TEAM Slb. (http://www.teamenergy.com/)
> The views expressed in this mail are my own.
>
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>