1 9 package org.jboss.net.axis.security.handler; 10 11 import java.security.KeyStore ; 12 import java.util.Map ; 13 14 import javax.naming.InitialContext ; 15 import javax.naming.NamingException ; 16 17 import org.apache.axis.AxisFault; 18 import org.apache.axis.MessageContext; 19 import org.apache.log4j.Logger; 20 import org.apache.ws.axis.security.WSDoAllConstants; 21 import org.apache.ws.axis.security.WSDoAllSender; 22 import org.apache.ws.security.components.crypto.Crypto; 23 import org.jboss.net.axis.security.JBossCryptoFactory; 24 import org.jboss.net.axis.security.SecurityConstants; 25 import org.jboss.security.SecurityDomain; 26 27 39 public class WSSResponseHandler extends WSDoAllSender 40 { 41 protected Logger log = Logger.getLogger(this.getClass()); 42 43 SecurityDomain domain = null; 44 45 public void invoke(MessageContext mc) throws AxisFault 46 { 47 52 if (!WSDoAllConstants.USE_REQ_SIG_CERT.equals(getOption(WSDoAllConstants.ENCRYPTION_USER))) 53 { 54 String actor = (String ) getOption(WSDoAllConstants.ACTOR); 56 String alias = null; 57 Map signers = (Map ) mc.getProperty(SecurityConstants.MC_REQ_SIGNERS); 58 if (signers != null) 59 { 60 alias = (String ) signers.get(actor); 61 } 62 mc.setProperty(WSDoAllConstants.ENCRYPTION_USER, alias); 66 } 67 68 super.invoke(mc); 69 } 70 71 protected Crypto loadSignatureCrypto() throws AxisFault 72 { 73 if (log.isDebugEnabled()) 74 log.debug("Loading the Signature Crypto Class"); 75 if (domain == null) 76 getSecurityDomain(); 77 79 KeyStore truststore = domain.getTrustStore(); 80 if (truststore == null) 81 throw new AxisFault("WSSReceiverHandler: No truststore available."); 82 String cryptoClass; 83 if ((cryptoClass = (String ) getOption(SecurityConstants.HANDLER_CRYPTO_CLASS)) == null) 84 throw new AxisFault("WSSReceiverHandler: No Crypto implementation was defined."); 85 return JBossCryptoFactory.getInstance(cryptoClass, truststore); 86 } 87 88 protected Crypto loadEncryptionCrypto() throws AxisFault 89 { 90 if (log.isDebugEnabled()) 91 log.debug("Loading the Decryption Crypto Class"); 92 if (domain == null) 93 getSecurityDomain(); 94 KeyStore keystore = domain.getKeyStore(); 96 if (keystore == null) 97 throw new AxisFault("WSSReceiverHandler: No keystore available."); 98 String cryptoClass; 99 if ((cryptoClass = (String ) getOption(SecurityConstants.HANDLER_CRYPTO_CLASS)) == null) 100 throw new AxisFault("WSSReceiverHandler: No Crypto implementation was defined."); 101 return JBossCryptoFactory.getInstance(cryptoClass, keystore); 102 103 } 104 105 private void getSecurityDomain() throws AxisFault 106 { 107 String sd; 108 if ((sd = (String ) getOption(SecurityConstants.HANDLER_SEC_DOMAIN)) == null) 109 sd = "java:/jaas/other"; if (log.isDebugEnabled()) 111 log.debug("WSSReceiveHandler, securityDomain=" + sd); 112 try 113 { 114 Object tempDomain = new InitialContext ().lookup(sd); 115 if (tempDomain != null && tempDomain instanceof SecurityDomain) 116 domain = (SecurityDomain) tempDomain; 117 else 118 { 119 log.fatal("The SecurityManager named " + sd + " is not a SecurityDomain"); 121 throw new AxisFault("WSSReceiverHandler: No security domain is available."); 122 } 123 } 124 catch (NamingException e) 125 { 126 throw new AxisFault("Unable to find the securityDomain named: " + sd, e); 127 } 128 } 129 } 130 | Popular Tags |