1 7 8 package org.jboss.webservice.handler; 10 11 13 import org.jboss.axis.AxisFault; 14 import org.jboss.axis.MessageContext; 15 import org.jboss.axis.encoding.Base64; 16 import org.jboss.axis.handlers.BasicHandler; 17 import org.jboss.logging.Logger; 18 import org.jboss.security.SecurityAssociation; 19 import org.jboss.security.SimplePrincipal; 20 import org.jboss.webservice.Constants; 21 22 import javax.xml.soap.SOAPException ; 23 import javax.xml.soap.SOAPHeader ; 24 import javax.xml.soap.SOAPHeaderElement ; 25 import javax.xml.soap.SOAPMessage ; 26 import java.util.Iterator ; 27 28 40 public class ServerLoginHandler extends BasicHandler 41 { 42 43 static final long serialVersionUID = 8239981936517243635L; 44 45 private static final Logger log = Logger.getLogger(ServerLoginHandler.class); 47 48 50 public void invoke(MessageContext msgContext) throws AxisFault 51 { 52 try 53 { 54 SOAPMessage soapMessage = msgContext.getMessage(); 55 SOAPHeader soapHeader = soapMessage.getSOAPPart().getEnvelope().getHeader(); 56 Iterator it = soapHeader.extractHeaderElements(Constants.NAMESPACE + "/login"); 57 while (it.hasNext()) 58 { 59 SOAPHeaderElement element = (SOAPHeaderElement )it.next(); 60 String localName = element.getElementName().getLocalName(); 61 String value = element.getValue(); 62 if (localName.equals("username")) 63 { 64 SecurityAssociation.setPrincipal(new SimplePrincipal(value)); 65 } 66 if (localName.equals("password")) 67 { 68 String password = new String (Base64.decode(value)); 69 SecurityAssociation.setCredential(password); 70 } 71 } 72 } 73 catch (SOAPException e) 74 { 75 log.error("Server login failed: " + e.toString()); 76 throw new AxisFault("Server login failed", e); 77 } 78 } 79 } 80 | Popular Tags |