Any user that tries to access some secure resources on my webapp A needs to be authenticated with a webapp B. B has access to the user credentials password etc., I am wondering about the right way to go about this.
One alternative would be to have a filter protecting my secure pages. If a user that is unauthenticated access A secure resource from A, the filter catches the request and redirects the browser to B's login page.
B logs the user in and redirects the browser to the secure page on the A server, along with some B's session id and some token indicatng that the user is logged in.
The filter catches the redirect from B to A, extracts the authentication token info from the header of B's reuest and logs the user in A's session.
All subsequent requests from browser will pass the token that B has set. The filter sees this token and considers the user logged in.
Does this sound sane or am I missing big things ?
Also- is a servletfilter the best way to accomplish this flow ? What about declarative security in web.xml ? How can I accomplish the same flow with using declarative security ?