Re: [WSS4J] Using wss4j from within a SecurityDomain
Jason Essington <[email protected]> Wed, 11 Feb 2004 14:33:45 -0700
| Newsgroups | gmane.text.xml.wss4j |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail-22--556222208 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Dims Here's a test case that checks the functionality. I did have to add the PrivilegedAccessor file described in the junit faq <http://junit.sourceforge.net/doc/faq/faq.htm#tests_11> The TestWSSecurityHooks tests that the private (or package) fields from the super classes are being set by the hooks. It tests all the hooks, then tries to do an "Encrypt Signature" round trip. The round trip test may really be more complicated that what a unit test should be, and the other tests really should catch any problems. --Apple-Mail-22--556222208 Content-Transfer-Encoding: quoted-printable Content-Type: application/octet-stream; x-unix-mode=0644; name="hooksTest.patch" Content-Disposition: attachment; filename=hooksTest.patch Index:=20test/wssec/PackageTests.java=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0ARCS=20file:=20= /cvsroot/wss4j/wss4j/test/wssec/PackageTests.java,v=0Aretrieving=20= revision=201.7=0Adiff=20-u=20-r1.7=20PackageTests.java=0A---=20= test/wssec/PackageTests.java=0921=20Jan=202004=2013:29:58=20-0000=091.7=0A= +++=20test/wssec/PackageTests.java=0911=20Feb=202004=2021:14:27=20-0000=0A= @@=20-25,7=20+25,8=20@@=0A=20=09=09= suite.addTestSuite(TestWSSecurity8.class);=0A=20=09=09= suite.addTestSuite(TestWSSecurity9.class);=0A=20=09=09= suite.addTestSuite(TestWSSecuritySOAP12.class);=0A-=20=20=20=20=20=20=20=20= return=20suite;=0A+=20=20=20=20=20=20= suite.addTestSuite(TestWSSecurityHooks.class);=0A+=20=20=20=20=20=20= return=20suite;=0A=20=20=20=20=20}=0A=20=0A=20=20=20=20=20/**=0A---=20= /dev/null=09Wed=20Feb=2011=2014:13:56=202004=0A+++=20= test/wssec/PrivilegedAccessor.java=09Wed=20Feb=2011=2012:55:52=202004=0A= @@=20-0,0=20+1,138=20@@=0A+/* +=20*=20This=20class=20was=20taken=20nearly=20verbatim=20from=20= http://junit.sourceforge.net/doc/faq/faq.htm#tests_11=20 +=20*=20I=20did=20add=20the=20setValue(Object,=20String,=20Object) +=20*=20Jason=20Essington=20<mailto:jasone-0ehoRKBSFavH/[email protected]> +=20*/ +package=20wssec; +import=20java.lang.reflect.*;=0A+=0A+/**=0A+=20*=20a.k.a.=20The=20= "ObjectMolester"=0A+=20*=20<p>=0A+=20*=20This=20class=20is=20used=20to=20= access=20a=20method=20or=20field=20of=20an=20object=20no=0A+=20*=20= matter=20what=20the=20access=20modifier=20of=20the=20method=20or=20= field.=20=20The=20syntax=0A+=20*=20for=20accessing=20fields=20and=20= methods=20is=20out=20of=20the=20ordinary=20because=20this=0A+=20*=20= class=20uses=20reflection=20to=20peel=20away=20protection.=0A+=20*=20<p>=0A= +=20*=20Here=20is=20an=20example=20of=20using=20this=20to=20access=20a=20= private=20member.=0A+=20*=20<code>resolveName</code>=20is=20a=20private=20= method=20of=20<code>Class</code>.=0A+=20*=0A+=20*=20<pre>=0A+=20*=20= Class=20c=20=3D=20Class.class;=0A+=20*=20System.out.println(=0A+=20*=20=20= =20=20=20=20PrivilegedAccessor.invokeMethod(=20c,=0A+=20*=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20"resolveName",=0A+=20*=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20"/net/iss/common/PrivilegeAccessor"=20)=20);=0A+=20*=20= </pre>=0A+=20*=0A+=20*[email protected]=20Charlie=20Hubbard=20= ([email protected])=0A+=20*=20@author=20Prashant=20Dhokte=20= ([email protected])=0A+=20*/=0A+=0A+public=20class=20PrivilegedAccessor=20= {=0A+=0A+=20=20=20=20/**=0A+=20=20=20=20=20*=20Gets=20the=20value=20of=20= the=20named=20field=20and=20returns=20it=20as=20an=20object.=0A+=20=20=20= =20=20*=0A+=20=20=20=20=20*[email protected]=20instance=20the=20object=20= instance=0A+=20=20=20=20=20*[email protected]=20fieldName=20the=20name=20of=20= the=20field=0A+=20=20=20=20=20*[email protected]=20an=20object=20representing=20= the=20value=20of=20the=20field=0A+=20=20=20=20=20*/=0A+=20=20=20=20= public=20static=20Object=20getValue(=20Object=20instance,=20String=20= fieldName=20)=20 +=20=20=20=20=20=20=20=20=20=20throws=20IllegalAccessException,=20= NoSuchFieldException=20{=0A+=20=20=20=20=20=20=20=20Field=20field=20=3D=20= getField(instance.getClass(),=20fieldName);=0A+=20=20=20=20=20=20=20=20= field.setAccessible(true);=0A+=20=20=20=20=20=20=20=20return=20= field.get(instance);=0A+=20=20=20=20} +=20=20=20=20 +=20=20=20=20/** +=20=20=20=20=20*=20Sets=20the=20value=20of=20the=20given=20field=20on=20= the=20object=20instance=20supplied=20to=20the=20value=20supplied. +=20=20=20=20=20*[email protected]=20instance=20the=20object=20instance +=20=20=20=20=20*[email protected]=20fieldName=20the=20name=20of=20the=20field +=20=20=20=20=20*[email protected]=20value=20the=20value=20to=20assign=20to=20= the=20field +=20=20=20=20=20*[email protected]=20IllegalAccessException +=20=20=20=20=20*[email protected]=20NoSuchFieldException +=20=20=20=20=20*/=0A+=20=20=20=20public=20static=20void=20setValue(=20= Object=20instance,=20String=20fieldName,=20Object=20value=20)=20 +=20=20=20=20=20=20=20=20=20=20throws=20IllegalAccessException,=20= NoSuchFieldException=20{ +=20=20=20=20=20=20=20Field=20field=20=3D=20= getField(instance.getClass(),=20fieldName); +=20=20=20=20=20=20=20field.setAccessible(true); +=20=20=20=20=20=20=20field.set(instance,=20value); +=20=20=20=20} +=20=20=20=20=0A+=20=20=20=20/**=0A+=20=20=20=20=20*=20Calls=20a=20= method=20on=20the=20given=20object=20instance=20with=20the=20given=20= argument.=0A+=20=20=20=20=20*=0A+=20=20=20=20=20*[email protected]=20instance=20= the=20object=20instance=0A+=20=20=20=20=20*[email protected]=20methodName=20the=20= name=20of=20the=20method=20to=20invoke=0A+=20=20=20=20=20*[email protected]=20= arg=20the=20argument=20to=20pass=20to=20the=20method=0A+=20=20=20=20=20*=20= @see=20PrivilegedAccessor#invokeMethod(Object,String,Object[])=0A+=20=20=20= =20=20*/=0A+=20=20=20=20public=20static=20Object=20invokeMethod(=20= Object=20instance,=20String=20methodName,=20Object=20arg=20)=20throws=20= NoSuchMethodException,=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20IllegalAccessException,=20= InvocationTargetException=20=20{=0A+=20=20=20=20=20=20=20=20Object[]=20= args=20=3D=20new=20Object[1];=0A+=20=20=20=20=20=20=20=20args[0]=20=3D=20= arg;=0A+=20=20=20=20=20=20=20=20return=20invokeMethod(instance,=20= methodName,=20args);=0A+=20=20=20=20}=0A+=0A+=20=20=20=20/**=0A+=20=20=20= =20=20*=20Calls=20a=20method=20on=20the=20given=20object=20instance=20= with=20the=20given=20arguments.=0A+=20=20=20=20=20*=0A+=20=20=20=20=20*=20= @param=20instance=20the=20object=20instance=0A+=20=20=20=20=20*[email protected]=20= methodName=20the=20name=20of=20the=20method=20to=20invoke=0A+=20=20=20=20= =20*[email protected]=20args=20an=20array=20of=20objects=20to=20pass=20as=20= arguments=0A+=20=20=20=20=20*[email protected]=20= PrivilegedAccessor#invokeMethod(Object,String,Object)=0A+=20=20=20=20=20= */=0A+=20=20=20=20public=20static=20Object=20invokeMethod(=20Object=20= instance,=20String=20methodName,=20Object[]=20args=20)=20throws=20= NoSuchMethodException,=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= IllegalAccessException,=20InvocationTargetException=20=20{=0A+=20=20=20=20= =20=20=20=20Class[]=20classTypes=20=3D=20null;=0A+=20=20=20=20=20=20=20=20= if(=20args=20!=3D=20null)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= classTypes=20=3D=20new=20Class[args.length];=0A+=20=20=20=20=20=20=20=20=20= =20=20=20for(=20int=20i=20=3D=200;=20i=20<=20args.length;=20i++=20)=20{=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20if(=20args[i]=20!=3D=20= null=20)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= classTypes[i]=20=3D=20args[i].getClass();=0A+=20=20=20=20=20=20=20=20=20=20= =20=20}=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20return=20= getMethod(instance,methodName,classTypes).invoke(instance,args);=0A+=20=20= =20=20}=0A+=0A+=20=20=20=20/**=0A+=20=20=20=20=20*=0A+=20=20=20=20=20*=20= @param=20instance=20the=20object=20instance=0A+=20=20=20=20=20*[email protected]=20= methodName=20the=0A+=20=20=20=20=20*/=0A+=20=20=20=20public=20static=20= Method=20getMethod(=20Object=20instance,=20String=20methodName,=20= Class[]=20classTypes=20)=20throws=20NoSuchMethodException=20{=0A+=20=20=20= =20=20=20=20=20Method=20accessMethod=20=3D=20= getMethod(instance.getClass(),=20methodName,=20classTypes);=0A+=20=20=20=20= =20=20=20=20accessMethod.setAccessible(true);=0A+=20=20=20=20=20=20=20=20= return=20accessMethod;=0A+=20=20=20=20}=0A+=0A+=20=20=20=20/**=0A+=20=20=20= =20=20*=20Return=20the=20named=20field=20from=20the=20given=20class.=0A+=20= =20=20=20=20*/=0A+=20=20=20=20private=20static=20Field=20getField(Class=20= thisClass,=20String=20fieldName)=20throws=20NoSuchFieldException=20{=0A+=20= =20=20=20=20=20=20=20if=20(thisClass=20=3D=3D=20null)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20throw=20new=20NoSuchFieldException("Invalid=20field=20= :=20"=20+=20fieldName);=0A+=20=20=20=20=20=20=20=20try=20{=0A+=20=20=20=20= =20=20=20=20=20=20=20=20return=20thisClass.getDeclaredField(=20fieldName=20= );=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20= catch(NoSuchFieldException=20e)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= return=20getField(thisClass.getSuperclass(),=20fieldName);=0A+=20=20=20=20= =20=20=20=20}=0A+=20=20=20=20}=0A+=0A+=20=20=20=20/**=0A+=20=20=20=20=20= *=20Return=20the=20named=20method=20with=20a=20method=20signature=20= matching=20classTypes=0A+=20=20=20=20=20*=20from=20the=20given=20class.=0A= +=20=20=20=20=20*/=0A+=20=20=20=20private=20static=20Method=20= getMethod(Class=20thisClass,=20String=20methodName,=20Class[]=20= classTypes)=20throws=20NoSuchMethodException=20{=0A+=20=20=20=20=20=20=20= =20if=20(thisClass=20=3D=3D=20null)=0A+=20=20=20=20=20=20=20=20=20=20=20=20= throw=20new=20NoSuchMethodException("Invalid=20method=20:=20"=20+=20= methodName);=0A+=20=20=20=20=20=20=20=20try=20{=0A+=20=20=20=20=20=20=20=20= =20=20=20=20return=20thisClass.getDeclaredMethod(=20methodName,=20= classTypes=20);=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20= catch(NoSuchMethodException=20e)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20= =20return=20getMethod(thisClass.getSuperclass(),=20methodName,=20= classTypes);=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20}=0A+}=0A\=20No=20= newline=20at=20end=20of=20file=0A---=20/dev/null=09Wed=20Feb=2011=20= 14:13:56=202004=0A+++=20test/wssec/TestWSSecurityHooks.java=09Wed=20Feb=20= 11=2014:13:04=202004=0A@@=20-0,0=20+1,257=20@@=0A+/*=0A+=20*=20Created=20= on=20Feb=2010,=202004=0A+=20*/=0A+package=20wssec;=0A+=0A+import=20= java.io.ByteArrayInputStream;=0A+import=20java.io.FileInputStream;=0A= +import=20java.io.IOException;=0A+import=20java.io.InputStream;=0A= +import=20java.security.KeyStore;=0A+=0A+import=20= javax.security.auth.callback.Callback;=0A+import=20= javax.security.auth.callback.CallbackHandler;=0A+import=20= javax.security.auth.callback.UnsupportedCallbackException;=0A+=0A+import=20= org.apache.axis.AxisFault;=0A+import=20org.apache.axis.Message;=0A= +import=20org.apache.axis.MessageContext;=0A+import=20= org.apache.axis.client.AxisClient;=0A+import=20= org.apache.axis.configuration.NullProvider;=0A+import=20= org.apache.commons.logging.Log;=0A+import=20= org.apache.commons.logging.LogFactory;=0A+import=20= org.apache.ws.axis.security.WSDoAllConstants;=0A+import=20= org.apache.ws.axis.security.WSDoAllReceiver;=0A+import=20= org.apache.ws.axis.security.WSDoAllSender;=0A+import=20= org.apache.ws.security.WSPasswordCallback;=0A+import=20= org.apache.ws.security.components.crypto.Crypto;=0A+import=20= org.apache.ws.security.components.crypto.Merlin;=0A+=0A+import=20= junit.framework.Test;=0A+import=20junit.framework.TestCase;=0A+import=20= junit.framework.TestSuite;=0A+=0A+/**=0A+=20*=20<dl>=0A+=20*=20= <dt><b>Title:=20</b><dd>WS=20Security=20Hooks=20Test=20Case</dd>=0A+=20*=20= <p>=0A+=20*=20<dt><b>Description:=20</b><dd>Test=20Case=20to=20verify=20= the=20load...Crypto=20hooks=20work=20properly.=20=0A+=20*=20Also=20tests=20= the=20setKeyStore=20method=20of=20Merlin=20</dd>=0A+=20*=20</dl>=0A+=20*=20= =0A+=20*[email protected]=20= org.apache.ws.security.components.crypto.Merlin#setKeyStore=0A+=20*=20= @see=20org.apache.ws.axis.security.WSDoAllReceiver#loadSignatureCrypto=0A= +=20*[email protected]=20= org.apache.ws.axis.security.WSDoAllReceiver#loadDecryptionCrypto=0A+=20*=20= @see=20org.apache.ws.axis.security.WSDoAllSender#loadSignatureCrypto=0A+=20= *[email protected]=20= org.apache.ws.axis.security.WSDoAllSender#loadEncryptionCrypto=0A+=20*=20= =0A+=20*[email protected]=20<a=20= href=3D"mailto:jasone-0ehoRKBSFavH/[email protected]>Jason=20Essington</a>=0A+=20= *[email protected]=20$Revision:=201.0=20$=0A+=20*/=0A+public=20class=20= TestWSSecurityHooks=20extends=20TestCase=20implements=20CallbackHandler=0A= +{=0A+=20=20=20private=20static=20Log=20log=20=3D=20= LogFactory.getLog(TestWSSecurityHooks.class);=0A+=20=20=20private=20= static=20final=20String=20soapMessage=20=3D=20"<?xml=20version=3D\"1.0\"=20= encoding=3D\"UTF-8\"?>"+=0A+=20=20=20=20=20=20=20=20=20= "<soapenv:Envelope=20"=20+=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "xmlns:soapenv=3D\"http://www.w3.org/2003/05/soap-envelope\"=20"=20+=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20= "xmlns:xsd=3D\"http://www.w3.org/2001/XMLSchema\"=20"=20+=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20= "xmlns:xsi=3D\"http://www.w3.org/2001/XMLSchema-instance\">"=20+=0A+=20=20= =20=20=20=20=20=20=20=20=20=20"<soapenv:Header>"=20+=0A+=20=20=20=20=20=20= =20=20=20=20=20=20"</soapenv:Header>"=20+=0A+=20=20=20=20=20=20=20=20=20=20= =20=20"<soapenv:Body>"=20+=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "<ns1:echo=20"=20+=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20"xmlns:ns1=3D\"http://org.apache.wss4j.wssec/TESTCASE\"=20"=20= +=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "soapenv:encodingStyle=3D\"http://www.w3.org/2003/05/soap-encoding\">"=20= +=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20"<inStr=20= xsi:type=3D\"xsd:string\">ECHO=20ECHo=20ECho=20Echo=20echo=20echO=20ecHO=20= eCHO=20ECHO</inStr>"=20+=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "</ns1:echo>"=20+=0A+=20=20=20=20=20=20=20=20=20=20=20=20= "</soapenv:Body>"=20+=0A+=20=20=20=20=20=20=20=20=20= "</soapenv:Envelope>";=0A+=0A+=20=20=20KeyStore=20keystore=20=3D=20null;=0A= +=20=20=20MessageContext=20mc=20=3D=20null;=0A+=20=20=20=0A+=20=20=20= public=20TestWSSecurityHooks(String=20name)=20{=0A+=20=20=20=20=20=20= super(name);=0A+=20=20=20}=0A+=20=20=20=0A+=20=20=20protected=20void=20= setUp()=20throws=20Exception=20{=0A+=20=20=20=20=20=20AxisClient=20= tmpEngine=20=3D=20new=20AxisClient(new=20NullProvider());=0A+=20=20=20=20= =20=20mc=20=3D=20new=20MessageContext(tmpEngine);=0A+=20=20=20=20=20=20= mc.setCurrentMessage(getSOAPMessage(soapMessage));=0A+=20=20=20=20=20=20= mc.setProperty(WSDoAllConstants.PW_CALLBACK_REF,=20this);=0A+=20=20=20=20= =20=20keystore=20=3D=20loadKeyStore();=0A+=20=20=20}=0A+=0A+=20=20=20= public=20static=20Test=20suite()=20{=0A+=20=20=20=20=20=20return=20new=20= TestSuite(TestWSSecurityHooks.class);=0A+=20=20=20}=0A+=0A+=20=20=20= public=20static=20void=20main(String[]=20args)=20{=0A+=20=20=20=20=20=20= junit.textui.TestRunner.run(suite());=0A+=20=20=20}=0A+=20=20=20=0A+=20=20= =20//=0A+=20=20=20//=0A+=20=20=20//=20Tests=0A+=20=20=20//=0A+=20=20=20= //=0A+=20=20=20=0A+=20=20=20public=20void=20testCryptoHook()=20throws=20= Exception=20{=0A+=20=20=20=20=20=20assertNotNull("",=20keystore);=0A+=20=20= =20=20=20=20Crypto=20crypto=20=3D=20new=20TestCryptoImpl(keystore);=0A+=20= =20=20=20=20=20assertNotNull(PrivilegedAccessor.getValue(crypto,=20= "keystore"));=0A+=20=20=20}=0A+=20=20=20public=20void=20= testSenderLoadSignatureHook()=20throws=20Exception=20{=0A+=20=20=20=20=20= =20TestSenderImpl=20sender=20=3D=20new=20TestSenderImpl();=0A+=20=20=20=20= =20=20//=20we=20have=20to=20coerce=20a=20value=20into=20this=20field=20= or=20we'll=20get=20a=20bunch=20of=20NPEs=20when=20calling=20= decodeSignatureParameter=0A+=20=20=20=20=20=20= PrivilegedAccessor.setValue(sender,=20"msgContext",=20mc);=0A+=20=20=20=20= =20=20PrivilegedAccessor.invokeMethod(sender,=20= "decodeSignatureParameter",=20new=20Object[]=20{});=0A+=20=20=20=20=20=20= assertNotNull(PrivilegedAccessor.getValue(sender,=20"sigCrypto"));=0A+=20= =20=20}=0A+=20=20=20public=20void=20testSenderLoadEncryptionHook()=20= throws=20Exception=20{=0A+=20=20=20=20=20=20TestSenderImpl=20sender=20=3D=20= new=20TestSenderImpl();=0A+=20=20=20=20=20=20//=20= decodeEcnryptionParameter()=20is=20rather=20insistant=20on=20having=20a=20= user=20(anyUser)=0A+=20=20=20=20=20=20= sender.setOption(WSDoAllConstants.ENCRYPTION_USER,=20"anyUserWillDo");=0A= +=20=20=20=20=20=20//=20we=20have=20to=20coerce=20a=20value=20into=20= this=20field=20or=20we'll=20get=20a=20bunch=20of=20NPEs=20when=20calling=20= decodeSignatureParameter=0A+=20=20=20=20=20=20= PrivilegedAccessor.setValue(sender,=20"msgContext",=20mc);=0A+=20=20=20=20= =20=20PrivilegedAccessor.invokeMethod(sender,=20= "decodeEncryptionParameter",=20new=20Object[]=20{});=0A+=20=20=20=20=20=20= assertNotNull(PrivilegedAccessor.getValue(sender,=20"encCrypto"));=0A+=20= =20=20}=0A+=20=20=20public=20void=20testReceiverLoadSignatureHook()=20= throws=20Exception=20{=0A+=20=20=20=20=20=20TestReceiverImpl=20receiver=20= =3D=20new=20TestReceiverImpl();=0A+=20=20=20=20=20=20= PrivilegedAccessor.invokeMethod(receiver,=20"decodeSignatureParameter",=20= new=20Object[]=20{});=0A+=20=20=20=20=20=20= assertNotNull(PrivilegedAccessor.getValue(receiver,=20"sigCrypto"));=0A+=20= =20=20}=0A+=20=20=20public=20void=20testReceiverLoadDecryptionHook()=20= throws=20Exception=20{=0A+=20=20=20=20=20=20TestReceiverImpl=20receiver=20= =3D=20new=20TestReceiverImpl();=0A+=20=20=20=20=20=20= PrivilegedAccessor.invokeMethod(receiver,=20"decodeDecryptionParameter",=20= new=20Object[]=20{});=0A+=20=20=20=20=20=20= assertNotNull(PrivilegedAccessor.getValue(receiver,=20"decCrypto"));=0A+=20= =20=20}=0A+=20=20=20=0A+=20=20=20public=20void=20= testRoundTripWithHooks()=20throws=20Exception=20{=0A+=20=20=20=20=20=20= //=20Setup=20our=20sender=20to=20Encrypt=20and=20Sign=20a=20soap=20= message=0A+=20=20=20=20=20=20TestSenderImpl=20sender=20=3D=20new=20= TestSenderImpl();=0A+=20=20=20=20=20=20= sender.setOption(WSDoAllConstants.ACTOR,=20"test");=0A+=20=20=20=20=20=20= sender.setOption(WSDoAllConstants.USER,=20= "16c73ab6-b892-458f-abf5-2f875f74882e");=0A+=20=20=20=20=20=20= sender.setOption(WSDoAllConstants.ACTION,=20"Encrypt=20Signature");=0A+=20= =20=20=20=20=20sender.setOption(WSDoAllConstants.SIG_KEY_ID,=20= "DirectReference");=0A+=20=20=20=20=20=20= sender.setOption(WSDoAllConstants.ENC_KEY_ID,=20"X509KeyIdentifier");=0A= +=20=20=20=20=20=20sender.invoke(mc);=0A+=20=20=20=20=20=20=0A+=20=20=20=20= =20=20//=20Make=20sure=20that=20at=20least=20SOMETHING=20happened=0A+=20=20= =20=20=20=20String=20soapPart=20=3D=20= mc.getCurrentMessage().getSOAPPartAsString();=0A+=20=20=20=20=20=20= assertNotSame("The=20message=20has=20not=20been=20Encrypted=20or=20= Signed",=20soapPart,=20soapMessage);=0A+=20=20=20=20=20=20=0A+=20=20=20=20= =20=20//=20Prepare=20the=20message=20context=20for=20the=20response=0A+=20= =20=20=20=20=20Message=20message=20=3D=20getSOAPMessage(soapPart);=0A+=20= =20=20=20=20=20mc.setPastPivot(true);=0A+=20=20=20=20=20=20= mc.setCurrentMessage(message);=0A+=20=20=20=20=20=20=0A+=20=20=20=20=20=20= //=20Setup=20our=20receiver=20for=20the=20decryption=20/=20signature=20= validation=0A+=20=20=20=20=20=20TestReceiverImpl=20receiver=20=3D=20new=20= TestReceiverImpl();=0A+=20=20=20=20=20=20= receiver.setOption(WSDoAllConstants.ACTOR,=20"test");=0A+=20=20=20=20=20=20= receiver.setOption(WSDoAllConstants.ACTION,=20"Encrypt=20Signature");=0A= +=20=20=20=20=20=20receiver.invoke(mc);=0A+=20=20=20}=0A+=20=20=20=0A+=20= =20=20//=0A+=20=20=20//=0A+=20=20=20//=20Test=20Utility=20Classes=0A+=20=20= =20//=0A+=20=20=20//=0A+=20=20=20=20=20=20=0A+=20=20=20/**=0A+=20=20=20=20= *=20This=20is=20a=20subclass=20of=20Merlin=20that=20uses=20the=20= setKeyStore()=20method=20rather=20than=20the=20=0A+=20=20=20=20*=20= load(is)=20method=20to=20set=20the=20private=20keystore=20field.=0A+=20=20= =20=20*/=0A+=20=20=20public=20class=20TestCryptoImpl=20extends=20Merlin=20= {=0A+=20=20=20=20=20=20TestCryptoImpl(KeyStore=20ks)=20throws=20= Exception=20{=0A+=20=20=20=20=20=20=20=20=20super(null);=0A+=20=20=20=20=20= =20=20=20=20assertNotNull(keystore);=0A+=20=20=20=20=20=20=20=20=20= setKeyStore(ks);=0A+=20=20=20=20=20=20}=0A+=20=20=20}=0A+=20=20=20=0A+=20= =20=20/**=0A+=20=20=20=20*=20Subclass=20of=20WSDoAllReceiver=20that=20= creates=20the=20Crypto's=20directly=0A+=20=20=20=20*/=0A+=20=20=20public=20= class=20TestReceiverImpl=20extends=20WSDoAllReceiver=0A+=20=20=20{=0A+=20= =20=20=20=20=20protected=20Crypto=20loadDecryptionCrypto()=20throws=20= AxisFault=20{=0A+=20=20=20=20=20=20=20=20=20try=20{=0A+=20=20=20=20=20=20= =20=20=20=20=20=20return=20new=20TestCryptoImpl(keystore);=0A+=20=20=20=20= =20=20=20=20=20}=20catch(Exception=20e)=20{=0A+=20=20=20=20=20=20=20=20=20= =20=20=20fail("Failed=20to=20create=20a=20Crypto=20instance.");=0A+=20=20= =20=20=20=20=20=20=20=20=20=20throw=20new=20AxisFault("Failed=20to=20= create=20a=20Crypto=20instance.",=20e);=0A+=20=20=20=20=20=20=20=20=20}=0A= +=20=20=20=20=20=20}=0A+=20=20=20=20=20=20protected=20Crypto=20= loadSignatureCrypto()=20throws=20AxisFault=20{=0A+=20=20=20=20=20=20=20=20= =20try=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20return=20new=20= TestCryptoImpl(keystore);=0A+=20=20=20=20=20=20=20=20=20}=20= catch(Exception=20e)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= fail("Failed=20to=20create=20a=20Crypto=20instance.");=0A+=20=20=20=20=20= =20=20=20=20=20=20=20throw=20new=20AxisFault("Failed=20to=20create=20a=20= Crypto=20instance.",=20e);=0A+=20=20=20=20=20=20=20=20=20}=0A+=20=20=20=20= =20=20}=0A+=20=20=20}=0A+=20=20=20=0A+=20=20=20/**=0A+=20=20=20=20*=20= Subclass=20of=20WSDoAllSender=20that=20creates=20the=20Crypto's=20= directly=0A+=20=20=20=20*/=0A+=20=20=20public=20class=20TestSenderImpl=20= extends=20WSDoAllSender=0A+=20=20=20{=0A+=20=20=20=20=20=20protected=20= Crypto=20loadEncryptionCrypto()=20throws=20AxisFault=20{=0A+=20=20=20=20=20= =20=20=20=20try=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20return=20new=20= TestCryptoImpl(keystore);=0A+=20=20=20=20=20=20=20=20=20}=20= catch(Exception=20e)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= fail("Failed=20to=20create=20a=20Crypto=20instance.");=0A+=20=20=20=20=20= =20=20=20=20=20=20=20throw=20new=20AxisFault("Failed=20to=20create=20a=20= Crypto=20instance.",=20e);=0A+=20=20=20=20=20=20=20=20=20}=0A+=20=20=20=20= =20=20}=0A+=20=20=20=20=20=20protected=20Crypto=20loadSignatureCrypto()=20= throws=20AxisFault=20{=0A+=20=20=20=20=20=20=20=20=20try=20{=0A+=20=20=20= =20=20=20=20=20=20=20=20=20return=20new=20TestCryptoImpl(keystore);=0A+=20= =20=20=20=20=20=20=20=20}=20catch(Exception=20e)=20{=0A+=20=20=20=20=20=20= =20=20=20=20=20=20fail("Failed=20to=20create=20a=20Crypto=20instance.");=0A= +=20=20=20=20=20=20=20=20=20=20=20=20throw=20new=20AxisFault("Failed=20= to=20create=20a=20Crypto=20instance.",=20e);=0A+=20=20=20=20=20=20=20=20=20= }=0A+=20=20=20=20=20=20}=0A+=20=20=20}=0A+=20=20=20=0A+=20=20=20=0A+=20=20= =20//=0A+=20=20=20//=0A+=20=20=20//=20test=20utility=20methods=0A+=20=20=20= //=0A+=20=20=20//=0A+=20=20=20=0A+=20=20=20protected=20Message=20= getSOAPMessage(String=20message)=20throws=20Exception=20{=0A+=20=20=20=20= =20=20InputStream=20in=20=3D=20new=20= ByteArrayInputStream(message.getBytes());=0A+=20=20=20=20=20=20Message=20= msg=20=3D=20new=20Message(in);=0A+=20=20=20=20=20=20= msg.setMessageContext(mc);=0A+=20=20=20=20=20=20return=20msg;=0A+=20=20=20= }=0A+=20=20=20=0A+=20=20=20protected=20KeyStore=20loadKeyStore()=20= throws=20Exception=20{=0A+=20=20=20=20=20=20KeyStore=20ks=20=3D=20null;=0A= +=20=20=20=20=20=20FileInputStream=20is=20=3D=20null;=0A+=20=20=20=20=20=20= is=20=3D=20new=20FileInputStream("keys/x509.PFX.MSFT");=0A+=20=20=20=20=20= =20ks=20=3D=20KeyStore.getInstance("pkcs12");=0A+=20=20=20=20=20=20= String=20password=20=3D=20"security";=0A+=20=20=20=20=20=20ks.load(is,=20= password.toCharArray());=0A+=20=20=20=20=20=20return=20ks;=0A+=20=20=20}=0A= +=20=20=20=0A+=20=20=20public=20void=20handle(Callback[]=20callbacks)=20= throws=20IOException,=20UnsupportedCallbackException=20{=0A+=20=20=20=20=20= =20for=20(int=20i=20=3D=200;=20i=20<=20callbacks.length;=20i++)=20{=0A+=20= =20=20=20=20=20=20=20=20if=20(callbacks[i]=20instanceof=20= WSPasswordCallback)=20{=0A+=20=20=20=20=20=20=20=20=20=20=20=20= WSPasswordCallback=20pc=20=3D=20(WSPasswordCallback)=20callbacks[i];=0A+=20= =20=20=20=20=20=20=20=20=20=20=20pc.setPassword("security");=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=0A+=20=20=20=20=20=20=20=20=20}=20else=20{=0A= +=20=20=20=20=20=20=20=20=20=20=20=20throw=20new=20= UnsupportedCallbackException(callbacks[i],=20"Unrecognized=20Callback");=0A= +=20=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20}=0A+=20=20=20}=0A+=20= =20=20=0A+}=0A= --Apple-Mail-22--556222208 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed -jason On Feb 10, 2004, at 2:17 PM, Davanum Srinivas wrote: > Jason, > > Checked in and Thanks. Is it possible to submit a small test case, > just so we don't break the > functionality. > > thanks, > dims --Apple-Mail-22--556222208-- ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click