1 22 package org.jboss.web.tomcat.security; 23 24 import java.io.IOException ; 25 import javax.servlet.ServletException ; 26 27 import org.apache.catalina.connector.Request; 28 import org.apache.catalina.connector.Response; 29 import org.apache.catalina.valves.ValveBase; 30 import org.jboss.logging.Logger; 31 32 41 public class BasicAuthValve 42 extends ValveBase 43 { 44 private static Logger log = Logger.getLogger(BasicAuthValve.class); 45 private static boolean trace = log.isTraceEnabled(); 46 47 48 private boolean useExceptionAsMsg = false; 49 50 private boolean clearAuthException = true; 51 52 private String exceptionHeader = null; 53 54 public boolean isUseExceptionAsMsg() 55 { 56 return useExceptionAsMsg; 57 } 58 public void setUseExceptionAsMsg(boolean useExceptionAsMsg) 59 { 60 this.useExceptionAsMsg = useExceptionAsMsg; 61 } 62 63 public String getExceptionHeader() 64 { 65 return exceptionHeader; 66 } 67 public void setExceptionHeader(String exceptionHeader) 68 { 69 this.exceptionHeader = exceptionHeader; 70 } 71 72 public void invoke(Request request, Response response) 73 throws IOException , ServletException 74 { 75 getNext().invoke(request, response); 76 Throwable t = SecurityAssociationActions.getAuthException(); 78 int status = response.getStatus(); 79 80 if( trace ) 81 log.trace("Status: "+status+"SecurityAssociation.exception: ", t); 82 if( status >= 400 && t != null ) 83 { 84 String msg = t.getMessage(); 85 if( useExceptionAsMsg ) 87 { 88 if( response.getCoyoteResponse() != null ) 89 response.getCoyoteResponse().setMessage(msg); 90 } 91 if( exceptionHeader != null ) 93 response.setHeader(exceptionHeader, msg); 94 if( clearAuthException ) 96 { 97 try 98 { 99 SecurityAssociationActions.clearAuthException(); 100 } 101 catch(Throwable e) 102 { 103 log.warn("Unable to clear auth exception ", e); 104 } 105 } 106 } 107 } 108 } | Popular Tags |