1 54 55 package org.jboss.axis.handlers.http; 56 57 import org.jboss.axis.AxisFault; 58 import org.jboss.axis.MessageContext; 59 import org.jboss.axis.encoding.Base64; 60 import org.jboss.axis.handlers.BasicHandler; 61 import org.jboss.axis.transport.http.HTTPConstants; 62 import org.jboss.axis.utils.Messages; 63 import org.jboss.logging.Logger; 64 65 66 73 public class HTTPAuthHandler extends BasicHandler 74 { 75 private static Logger log = Logger.getLogger(HTTPAuthHandler.class.getName()); 76 77 public void invoke(MessageContext msgContext) throws AxisFault 78 { 79 log.debug("Enter: HTTPAuthHandler::invoke"); 80 81 82 83 String tmp = (String )msgContext.getProperty(HTTPConstants.HEADER_AUTHORIZATION); 84 if (tmp != null) tmp = tmp.trim(); 85 if (tmp != null && tmp.startsWith("Basic ")) 86 { 87 String user = null; 88 int i; 89 90 tmp = new String (Base64.decode(tmp.substring(6))); 91 i = tmp.indexOf(':'); 92 if (i == -1) 93 user = tmp; 94 else 95 user = tmp.substring(0, i); 96 msgContext.setUsername(user); 97 log.debug(Messages.getMessage("httpUser00", user)); 98 if (i != -1) 99 { 100 String pwd = tmp.substring(i + 1); 101 if (pwd != null && pwd.equals("")) pwd = null; 102 if (pwd != null) 103 { 104 msgContext.setPassword(pwd); 105 log.debug(Messages.getMessage("httpPassword00", pwd)); 106 } 107 } 108 } 109 110 log.debug("Exit: HTTPAuthHandler::invoke"); 111 } 112 } 113 | Popular Tags |