October 4, 2006

Struts authentication on every request

Today, somebody asked me if we always need to implement an interceptor design to authenticate the user request every time before it is processed. Fortunately for him, he is working on a Struts based solution, hence my answer was that you have an option to create a subclass of RequestProcessor.

Override processPreprocess() (which returns true in normal conditions) to call your method which will authenticate the user request. Return true to proceed and false to abort request processing.

I have learned this trick the hard way (doing it wrong the first time), but you have my blog to simplify things for you. Write to me (Sachin) if you need any particular solution.