I am writing an OpenID filter based on the JOID library to allow applications to transparently authenticate against our local OpenID Server. Since OpenID works via HTTP redirects, I end up losing the original request object in the process, especially if it’s a POST with a data body. Is it possible to save the request object in a way that I can reuse it later in the transaction, after the user has been authenticated? Even just saving the message body itself should suffice, as I can preserve the query URL easily enough with a roundtrip redirect (by using the OpenID’s return-to-url).
I want to make this completely transparent to the underlying servlets, so they behave the same whether the user went through the OpenID flow for this particular request or just has a valid/authenticated local session.
Store the data of interest (request parameters, request attributes, etc) in a
Mapin session scope by an unique ID as key which you add to the return-to-url.And then when it comes back, use
HttpServletRequestWrapperto wrap the current request wherein you override thegetParameter()and consorts to return the original data of interest. Do this in aFilter.The
HttpServletRequestWithDataOfInterestcan look like this:Note: any obvious nullcheck handling etc is up to you.