Form based auth + EJB Auth working, How to use form-auth on
websel Oct 14, 2004 6:51 AMHi!,
I've a problem which i haven't figured out yet.
I have a form based authentication () which works fine.
I have my EJB's protected with the same security domain which works ok if I supply a valid username & password to a standalone client
What I would expected is that the servlet container would authenticate itself to the beans but this isn't the case (or can I configure this so it would? that would be great!)
As a way to fix this, I'm having my web-app authenticate to the beans with the javax.security.auth.login.LoginContext
Got this working example from jkuhn (thanks!!)
I can't bridge the authenticated servlet to the EJB's only if i fill in a password in the servlet code which of course is not an option :-(
Q1 Is there a way how i can have the servlet container authenticate it self to the beans in another way than this one below?
Q2 How can i get the value of j_password from the form. This is not possible with the usual request.getParameter("j_password")
This is a code snippet of my LogonAction.java
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
HttpSession session = request.getSession();
String username="";
String password="";
username = "wessel";
password = "mysecretpassword";
// ****** HERE's the Headace! How to get these two from the
// web-servlet!
// request.getParameter("j_password"); always returns null
LoginContext lc = null;
try{
AppCallbackHandler handler = new
AppCallbackHandler(username, password.toCharArray() );
lc = new LoginContext("spawnzone", handler);
System.out.println("Created LoginContext");
lc.login();
System.out.println("Logged in.");
Iterator it = lc.getSubject().getPrincipals().iterator();
while(it.hasNext()) {
Object o = it.next();
System.out.println("principle: "+
o.getClass().getName()+ " "+o);
}
}catch (LoginException le){
System.out.println("Login failed");
le.printStackTrace();
}
Many many thanks for who gives the solution to bridge these two ... it's pritty frustrating having the two ends 'just' not close enough to tie them together :-)
Wessel