CODE SNIPPET OF THE SERVLET AUTHENTICATION
protected void forward (HttpServletRequest request, HttpServletResponse 
response) 
throws ServletException, IOException 
{ 
System.out.println("appel de accesPWS.forward()"); 
String useraction = request.getParameter("useraction"); 
String buildUrl = null; 
if (useraction!=null && useraction.equals("close")) 
{ 
HttpSession session = request.getSession(false); 
try { 
System.out.println("Appel de close"); 
gedAccess.remove(); 
deleteDirectory((String)session.getAttribute("repUsr")); 
session.invalidate(); 
}catch (Exception e) { 
e.printStackTrace(); 
} 
} 
else 
{ 
if (useraction!=null && useraction.equals("form")) 
{ 
String username = request.getParameter("j_username"); 
String password = request.getParameter("j_password"); 
try 
{ 
SecurityAssociationHandler handler = new SecurityAssociationHandler(); 
SimplePrincipal user = new SimplePrincipal(username); 
handler.setSecurityInfo(user, password.toCharArray()); 
LoginContext loginContext = new LoginContext("pws", (CallbackHandler)handler); 
loginContext.login(); 
System.out.println(username+" -> OK"); 
Subject subject = loginContext.getSubject(); 
Set principals = subject.getPrincipals(); 
principals.add(user); 
}catch(LoginException e) 
{ 
System.out.println("Erreur de login"); 
buildUrl = "error.jsp"; 
e.printStackTrace(); 
} 
} 
// CONNEXION OK ************************************** 
if (buildUrl==null) 
{ 
HttpSession session = request.getSession(true); 
System.out.println(session.getId()); 
File rep = new File("c:\\Temp\\"+session.getId()+"\\"); 
buildUrl = "/jsp/ged.jsp"; 
try { 
if (rep.mkdir()) 
session.setAttribute("repUsr","c:\\\\Temp\\\\"+session.getId()+"\\\\"); 
else 
System.out.println("Echec dans la creation du repertoire de travail"); 
String usr = "2"; 
session.setAttribute("usr",usr); 
session.setAttribute("username",request.getParameter("username")); 
initGedAccess(); 
try { 
gedAccess = gedAccessHome.create(); 
} catch (RemoteException e1) { 
e1.printStackTrace(); 
} catch (CreateException e2) { 
e2.printStackTrace(); 
} 
session.setAttribute("gedAccess",gedAccess); 
session.setAttribute("application",p_applicationMetier); 
Hashtable tokens = gedAccess.getTokens(usr); 
session.setAttribute("tokens",tokens); 
System.out.println("buildUrl="+buildUrl); 
RequestDispatcher rd = getServletContext().getRequestDispatcher(buildUrl); 
rd.forward(request,response); 
} catch (Exception e) { 
e.printStackTrace(); 
} 
} 
// FIN DE CONNEXION OK **************************************** 
} // fin du else si fin ou debut de session 




}

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3857340#3857340

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3857340


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to