JAAS. How to set remote user in the session?

I have a working J2EE application (A), which uses internal authentication and authorization without JAAS as well as a custom engine library.

I need to replace the old engine with a new one.

The new application (B) should use JAAS. But the old application should be rebuilt step-by-step.

So, application will temporary be based on 2 engines at the same time.

All new application pages are protected with <security-constraint/> in the web.xml.

Functionally application logic has been separated successfully. An authentication problem is left.

Applciation A has login screen with inputs for username and password.

Question 1: How can I authenticate in application part B(login module) automatically after a user

passed authenication in application part A (custom authentication)?

I wrote LoginModule which keeps authentication logic.

It works when i send request to j_security_check?j_username=username&j_password=passwd

and then i can get remote user name from the session using request.getRemoteUser() method.

Question 2: How can I set remote user in session, without sending j_security_check request?

I created LoginContext and custom MyCallbackhandler and did login() in application part A authentication function.

LoginContext lc =new LoginContext("MyLoginModule",new MyCallbackHandler());

lc.login();

log.debug( lc.getSubject() );

log.debug( req.getRemoteUser() );

LoginModule login() and commit() work properly. It creates correct Subject, but RemoteUser is null and all pages are redirected to the login page.

Question 3: How can I set subject in the session to let login module to know about it?

Application should work under JBoss4.0, SAS7/SAS8.

[1908 byte] By [kdva] at [2007-10-2 21:56:50]
# 1
Hey, did you find out a solution for your problem, please respond.thanksVenkatesh
venkateshca at 2007-7-14 1:12:55 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 2

Seems it is impossible to set it by hand :(

The proposed work around approach suggests to use a custom application authentication and authorization logic, which can be easily migrated to the container layer when the old application logic will be removed from the project.

I used the following way to solve this problem.

1. Create and register LoginModule

2. Create custom SecurityFilter and map it to the *.faces url pattern. This filter should check if user attribute (Subject) is not in the session. If so, the filter forwards request to the login page, registred for this filter. Also this filter should implements authorization logic using LoginModule.

So, authorization logic is implemented in the separate module.

May be it is not best way. But it helps me to rebuild old application by parts.

kdva at 2007-7-14 1:12:55 > top of Java-index,Security,Other Security APIs, Tools, and Issues...