1 22 package org.jboss.web.tomcat.security; 23 24 import java.io.IOException ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpSession ; 27 28 import org.apache.catalina.connector.Request; 29 import org.apache.catalina.connector.Response; 30 import org.apache.catalina.valves.ValveBase; 31 import org.jboss.logging.Logger; 32 33 43 public class FormAuthValve 44 extends ValveBase 45 { 46 private static Logger log = Logger.getLogger(FormAuthValve.class); 47 private static boolean trace = log.isTraceEnabled(); 48 private boolean includePassword; 49 50 public boolean isIncludePassword() 51 { 52 return includePassword; 53 } 54 public void setIncludePassword(boolean includePassword) 55 { 56 this.includePassword = includePassword; 57 } 58 59 public void invoke(Request request, Response response) 60 throws IOException , ServletException 61 { 62 String username = request.getParameter("j_username"); 63 HttpSession session = request.getSession(false); 64 if( trace ) 65 log.trace("Enter, j_username="+username); 66 if( session != null ) 67 { 68 if( username != null ) 69 session.setAttribute("j_username", username); 70 if( includePassword ) 71 { 72 Object pass = request.getParameter("j_password"); 73 if( pass != null ) 74 session.setAttribute("j_password", pass); 75 } 76 } 77 78 getNext().invoke(request, response); 79 80 username = request.getParameter("j_username"); 81 session = request.getSession(false); 82 if( session != null ) 83 { 84 if( trace ) 85 log.trace("SessionID: "+session.getId()); 86 if( username != null ) 87 session.setAttribute("j_username", username); 88 Throwable t = (Throwable ) SecurityAssociationActions.getAuthException(); 90 if( trace ) 91 log.trace("SecurityAssociation.exception: "+t); 92 if( t != null ) 93 session.setAttribute("j_exception", t); 94 } 95 if( trace ) 96 log.trace("Exit, username: "+username); 97 } 98 } 99 | Popular Tags |