1 16 17 package org.apache.axis.handlers.http; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.MessageContext; 21 import org.apache.axis.components.logger.LogFactory; 22 import org.apache.axis.encoding.Base64; 23 import org.apache.axis.handlers.BasicHandler; 24 import org.apache.axis.transport.http.HTTPConstants; 25 import org.apache.axis.utils.Messages; 26 import org.apache.commons.logging.Log; 27 28 29 35 public class HTTPAuthHandler extends BasicHandler 36 { 37 protected static Log log = 38 LogFactory.getLog(HTTPAuthHandler.class.getName()); 39 40 public void invoke(MessageContext msgContext) throws AxisFault 41 { 42 log.debug("Enter: HTTPAuthHandler::invoke"); 43 44 45 46 String tmp = (String )msgContext.getProperty(HTTPConstants.HEADER_AUTHORIZATION); 47 if ( tmp != null ) tmp = tmp.trim(); 48 if ( tmp != null && tmp.startsWith("Basic ") ) { 49 String user=null ; 50 int i ; 51 52 tmp = new String ( Base64.decode( tmp.substring(6) ) ); 53 i = tmp.indexOf( ':' ); 54 if ( i == -1 ) user = tmp ; 55 else user = tmp.substring( 0, i); 56 msgContext.setUsername( user ); 57 log.debug( Messages.getMessage("httpUser00", user) ); 58 if ( i != -1 ) { 59 String pwd = tmp.substring(i+1); 60 if ( pwd != null && pwd.equals("") ) pwd = null ; 61 if ( pwd != null ) { 62 msgContext.setPassword( pwd ); 63 log.debug( Messages.getMessage("httpPassword00", pwd) ); 64 } 65 } 66 } 67 68 log.debug("Exit: HTTPAuthHandler::invoke"); 69 } 70 } 71 | Popular Tags |