You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2006/04/06 04:28:11 UTC

svn commit: r391878 - in /webservices/axis2/trunk/java: etc/ modules/integration/ modules/integration/test-resources/security/rahas/ modules/integration/test/org/apache/axis2/security/rahas/ modules/security/ modules/security/src/org/apache/axis2/secur...

Author: ruchithf
Date: Wed Apr  5 19:28:07 2006
New Revision: 391878

URL: http://svn.apache.org/viewcvs?rev=391878&view=rev
Log:
- Added a RAHAS+Trust test case - The service is a Trust enabled service and the client will obtain an SCT from the service and will make two requests to the service with the msg body encrypted with key derived using the secret bound to the SCT. The secret is communicated to the client as an xenc:EncryptedKey
- Update Axis2Util.getDocumentFromSOAPEnvelope() to not to re-build the DOM elements if the given element is a DOM element
- When we set the token elements in the Tokens to be stored make sure we clone the element and set it
- Make sure we are not converting back to llom when we are going past the security outflow handler


Added:
    webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/
    webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s1-services.xml
    webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s2-services.xml
    webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sctIssuer.properties   (with props)
    webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.jks   (with props)
    webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.properties   (with props)
    webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sts.jks   (with props)
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/PWCallback.java   (with props)
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/RahasScenario1Test.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/Service.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/TestClient.java
Modified:
    webservices/axis2/trunk/java/etc/project.properties
    webservices/axis2/trunk/java/modules/integration/maven.xml
    webservices/axis2/trunk/java/modules/security/maven.xml
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java

Modified: webservices/axis2/trunk/java/etc/project.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/etc/project.properties?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/etc/project.properties (original)
+++ webservices/axis2/trunk/java/etc/project.properties Wed Apr  5 19:28:07 2006
@@ -23,6 +23,7 @@
 axis2_version=SNAPSHOT
 addressing_version=SNAPSHOT
 security_version=SNAPSHOT
+rahas_version=SNAPSHOT
 #axis2_version=${version_number}-${version_affix}
 #addressing_version=${version_number}-${version_affix}
 #security_version=${version_number}-${version_affix}

Modified: webservices/axis2/trunk/java/modules/integration/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/maven.xml?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/integration/maven.xml Wed Apr  5 19:28:07 2006
@@ -71,7 +71,61 @@
 
     <postGoal name="test:compile">
         <j:if test="${context.getVariable('maven.test.skip') != 'true'}">
-            <mkdir dir="target/test-resources/samples/modules"/>
+
+			<!-- Service classes for the Rahas tests -->
+			<mkdir dir="target/temp-rahas"/>
+			<mkdir dir="target/temp-rahas/META-INF"/>
+			
+			<copy overwrite="yes" file="target/test-classes/org/apache/axis2/security/rahas/Service.class"
+                  tofile="target/temp-rahas/org/apache/axis2/security/rahas/Service.class"/>
+			<copy overwrite="yes" file="target/test-classes/org/apache/axis2/security/rahas/PWCallback.class"
+                  tofile="target/temp-rahas/org/apache/axis2/security/rahas/PWCallback.class"/>
+				  
+			<copy overwrite="yes" todir="target/temp-rahas">
+            	<fileset dir="test-resources/security/rahas">
+					<include name="sctIssuer.properties"/>
+					<include name="sts.jks"/>
+				</fileset>
+			</copy>
+
+			<ant:path id="rahas.client.props" location="test-resources/security/rahas"/>
+            <maven:addPath id="maven.dependency.classpath" refid="rahas.client.props"/>
+			
+			<mkdir dir="target/test-resources/rahas_client_repo"/>
+            <mkdir dir="target/test-resources/rahas_client_repo/conf"/>
+            <mkdir dir="target/test-resources/rahas_client_repo/modules"/>
+			
+			<copy file="../addressing/target/addressing-${addressing_version}.mar"
+                  tofile="target/test-resources/rahas_client_repo/modules/addressing-${addressing_version}.mar"/>
+			<copy file="../security/target/rahas-${rahas_version}.mar"
+                  tofile="target/test-resources/rahas_client_repo/modules/rahas-${rahas_version}.mar"/>
+
+            <!-- Rahas Test - 1  -->
+
+            <mkdir dir="target/test-resources/rahas_service_repo_1"/>
+            <mkdir dir="target/test-resources/rahas_service_repo_1/conf"/>
+            <mkdir dir="target/test-resources/rahas_service_repo_1/services"/>
+            <mkdir dir="target/test-resources/rahas_service_repo_1/modules"/>
+
+			<copy file="../addressing/target/addressing-${addressing_version}.mar"
+                  tofile="target/test-resources/rahas_service_repo_1/modules/addressing-${addressing_version}.mar"/>
+			<copy file="../security/target/rahas-${rahas_version}.mar"
+                  tofile="target/test-resources/rahas_service_repo_1/modules/rahas-${rahas_version}.mar"/>
+
+			<!-- copy the services.xml and create the aar -->
+			<copy overwrite="yes" file="test-resources/security/rahas/s1-services.xml"
+                  tofile="target/temp-rahas/META-INF/services.xml"/>
+
+		    <jar jarfile="target/test-resources/rahas_service_repo_1/services/Service.aar"
+                 basedir="target/temp-rahas"/>
+
+            <!-- Rahas Test - 1 :END -->
+			
+			<!-- clean up temp rahas stuff -->
+			<!--<delete dir="target/temp-rahas"/> -->
+
+		
+			<mkdir dir="target/test-resources/samples/modules"/>
             <mkdir dir="target/test-resources/samples/conf"/>
             <mkdir dir="target/test-resources/repository-client/modules"/>
             <mkdir dir="target/test-resources/repository-client/conf"/>
@@ -533,7 +587,6 @@
             <!-- Create the .aar file -->
             <jar jarfile="target/test-resources/complete_service_repo/services/PingPort.aar"
                  basedir="../security/target/interop/classes"/>
-
 
             <!-- Standard repository -->
             <mkdir dir="target/Repository"/>

Added: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s1-services.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s1-services.xml?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s1-services.xml (added)
+++ webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s1-services.xml Wed Apr  5 19:28:07 2006
@@ -0,0 +1,40 @@
+<service name="SecureService">
+
+	<module ref="rahas"/>
+
+	<parameter locked="false" name="ServiceClass">org.apache.axis2.security.rahas.Service</parameter>
+
+	<operation name="echo">
+		<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+		<actionMapping>urn:echo</actionMapping>
+	</operation>    
+
+    <parameter name="sct-issuer-config">
+		<sct-issuer-config>
+			<proofToken>EncryptedKey</proofToken>
+			<cryptoProperties>sctIssuer.properties</cryptoProperties>
+		</sct-issuer-config>
+    </parameter>
+    
+    <parameter xmlns="" name="rahas-configuration">
+		<rahas-configuration xmlns="">
+			<scope xmlns="">service</scope>
+			<passwordCallbackClass xmlns="">org.apache.axis2.security.rahas.PWCallback</passwordCallbackClass>
+			<cryptoProperties xmlns="">sctIssuer.properties</cryptoProperties>
+		</rahas-configuration>
+	</parameter>
+
+    <parameter name="InflowSecurity">
+      <action>
+        <items>Timestamp Signature</items>
+        <signaturePropFile>sctIssuer.properties</signaturePropFile>
+      </action>
+    </parameter>
+
+    <parameter name="OutflowSecurity">
+      <action>
+        <items>Timestamp</items>
+      </action>
+    </parameter>
+    
+</service>

Added: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s2-services.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s2-services.xml?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s2-services.xml (added)
+++ webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/s2-services.xml Wed Apr  5 19:28:07 2006
@@ -0,0 +1,40 @@
+<service name="SecureService">
+
+	<module ref="rahas"/>
+
+	<parameter locked="false" name="ServiceClass">org.apache.axis2.security.rahas.Service</parameter>
+
+	<operation name="echo">
+		<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+		<actionMapping>urn:echo</actionMapping>
+	</operation>    
+
+    <parameter name="sct-issuer-config">
+		<sct-issuer-config>
+			<proofToken>BinarySecret</proofToken>
+			<cryptoProperties>sctIssuer.properties</cryptoProperties>
+		</sct-issuer-config>
+    </parameter>
+    
+    <parameter xmlns="" name="rahas-configuration">
+		<rahas-configuration xmlns="">
+			<scope xmlns="">service</scope>
+			<passwordCallbackClass xmlns="">org.apache.axis2.security.rahas.PWCallback</passwordCallbackClass>
+			<cryptoProperties xmlns="">sctIssuer.properties</cryptoProperties>
+		</rahas-configuration>
+	</parameter>
+
+    <parameter name="InflowSecurity">
+      <action>
+        <items>Timestamp Signature</items>
+        <signaturePropFile>sctIssuer.properties</signaturePropFile>
+      </action>
+    </parameter>
+
+    <parameter name="OutflowSecurity">
+      <action>
+        <items>Timestamp</items>
+      </action>
+    </parameter>
+    
+</service>

Added: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sctIssuer.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sctIssuer.properties?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sctIssuer.properties (added)
+++ webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sctIssuer.properties Wed Apr  5 19:28:07 2006
@@ -0,0 +1,4 @@
+org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
+org.apache.ws.security.crypto.merlin.keystore.type=jks
+org.apache.ws.security.crypto.merlin.keystore.password=password
+org.apache.ws.security.crypto.merlin.file=sts.jks

Propchange: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sctIssuer.properties
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.jks
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.jks?rev=391878&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.jks
------------------------------------------------------------------------------
    svn:executable = *

Propchange: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.jks
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.properties?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.properties (added)
+++ webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.properties Wed Apr  5 19:28:07 2006
@@ -0,0 +1,5 @@
+org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
+org.apache.ws.security.crypto.merlin.keystore.type=jks
+org.apache.ws.security.crypto.merlin.keystore.password=password
+org.apache.ws.security.crypto.merlin.file=sec.jks
+

Propchange: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sec.properties
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sts.jks
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sts.jks?rev=391878&view=auto
==============================================================================
Binary file - no diff available.

Propchange: webservices/axis2/trunk/java/modules/integration/test-resources/security/rahas/sts.jks
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/PWCallback.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/PWCallback.java?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/PWCallback.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/PWCallback.java Wed Apr  5 19:28:07 2006
@@ -0,0 +1,183 @@
+package org.apache.axis2.security.rahas;
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import org.apache.ws.security.WSPasswordCallback;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import java.io.IOException;
+
+
+
+/**
+
+ * Class PWCallback
+
+ */
+
+public class PWCallback implements CallbackHandler {
+
+
+
+    /** Field key */
+
+    private static final byte[] key = {
+
+        (byte) 0x31, (byte) 0xfd, (byte) 0xcb, (byte) 0xda, (byte) 0xfb,
+
+        (byte) 0xcd, (byte) 0x6b, (byte) 0xa8, (byte) 0xe6, (byte) 0x19,
+
+        (byte) 0xa7, (byte) 0xbf, (byte) 0x51, (byte) 0xf7, (byte) 0xc7,
+
+        (byte) 0x3e, (byte) 0x80, (byte) 0xae, (byte) 0x98, (byte) 0x51,
+
+        (byte) 0xc8, (byte) 0x51, (byte) 0x34, (byte) 0x04,
+
+    };
+
+
+
+    /*
+
+     * (non-Javadoc)
+
+     * @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[])
+
+     */
+
+
+
+    /**
+
+     * Method handle
+
+     * 
+
+     * @param callbacks 
+
+     * @throws java.io.IOException                  
+
+     * @throws javax.security.auth.callback.UnsupportedCallbackException 
+
+     */
+
+    public void handle(Callback[] callbacks)
+
+            throws IOException, UnsupportedCallbackException {
+
+
+
+        for (int i = 0; i < callbacks.length; i++) {
+
+            if (callbacks[i] instanceof WSPasswordCallback) {
+
+                WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
+
+
+
+                /*
+
+                 * This usage type is used only in case we received a
+
+                 * username token with a password of type PasswordText or
+
+                 * an unknown password type.
+
+                 * 
+
+                 * This case the WSPasswordCallback object contains the
+
+                 * identifier (aka username), the password we received, and
+
+                 * the password type string to identify the type.
+
+                 * 
+
+                 * Here we perform only a very simple check.
+
+                 */
+
+                if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
+
+                	if(pc.getIdentifer().equals("Ron") && pc.getPassword().equals("noR")) {
+
+                        return;
+
+                	}
+
+                    if (pc.getPassword().equals("sirhC")) {
+
+                        return;
+
+                    }               	
+
+                    throw new UnsupportedCallbackException(callbacks[i],
+
+                    "check failed");
+
+                }
+
+                /*
+
+                 * here call a function/method to lookup the password for
+
+                 * the given identifier (e.g. a user name or keystore alias)
+
+                 * e.g.: pc.setPassword(passStore.getPassword(pc.getIdentfifier))
+
+                 * for Testing we supply a fixed name here.
+
+                 */
+
+                if (pc.getUsage() == WSPasswordCallback.KEY_NAME) {
+
+                    pc.setKey(key);
+
+                } else if(pc.getIdentifer().equals("alice")) {
+
+                    pc.setPassword("password");
+
+                } else if(pc.getIdentifer().equals("bob")) {
+
+                    pc.setPassword("password");
+
+                } else if(pc.getIdentifer().equals("Ron")) {
+
+                    pc.setPassword("noR");
+
+                } else {
+
+                    pc.setPassword("sirhC");
+
+                }
+
+            } else {
+
+                throw new UnsupportedCallbackException(callbacks[i],
+
+                        "Unrecognized Callback");
+
+            }
+
+        }
+
+    }
+
+}
+
+

Propchange: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/PWCallback.java
------------------------------------------------------------------------------
    svn:executable = *

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/RahasScenario1Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/RahasScenario1Test.java?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/RahasScenario1Test.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/RahasScenario1Test.java Wed Apr  5 19:28:07 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.security.rahas;
+
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.security.handler.config.InflowConfiguration;
+import org.apache.axis2.security.handler.config.OutflowConfiguration;
+
+/**
+ * 
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
+public class RahasScenario1Test extends TestClient {
+
+    /**
+     * @param name
+     */
+    public RahasScenario1Test(String name) {
+        super(name);
+    }
+
+    public Parameter getClientRahasConfiguration() {
+        RahasConfiguration config = new RahasConfiguration();
+
+        config.setCryptoPropertiesFile("sec.properties");
+        config.setScope(RahasConfiguration.SCOPE_SERVICE);
+        config.setPasswordCallbackClass(PWCallback.class.getName());
+        config.setStsEPRAddress("http://localhost:" + port + "/axis2/services/Service");
+
+        return config.getParameter();
+    }
+
+    public OutflowConfiguration getClientOutflowConfiguration() {
+        OutflowConfiguration ofc = new OutflowConfiguration();
+
+        ofc.setActionItems("Timestamp Signature");
+        ofc.setUser("alice");
+        ofc.setSignaturePropFile("sec.properties");
+        ofc.setPasswordCallbackClass(PWCallback.class.getName());
+        return ofc;
+    }
+
+    public InflowConfiguration getClientInflowConfiguration() {
+        InflowConfiguration ifc = new InflowConfiguration();
+
+        ifc.setActionItems("Timestamp");
+
+        return ifc;
+    }
+
+    public String getServiceRepo() {
+        return "rahas_service_repo_1";
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/Service.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/Service.java?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/Service.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/Service.java Wed Apr  5 19:28:07 2006
@@ -0,0 +1,15 @@
+package org.apache.axis2.security.rahas;
+import org.apache.axiom.om.OMElement;
+
+
+
+public class Service {
+
+	public OMElement echo(OMElement elem) {
+		elem.build();
+		elem.detach();
+        System.out.println("Service invoked");
+		return elem;
+	}
+	
+}

Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/TestClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/TestClient.java?rev=391878&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/TestClient.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/security/rahas/TestClient.java Wed Apr  5 19:28:07 2006
@@ -0,0 +1,131 @@
+package org.apache.axis2.security.rahas;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.security.handler.WSSHandlerConstants;
+import org.apache.axis2.security.handler.config.InflowConfiguration;
+import org.apache.axis2.security.handler.config.OutflowConfiguration;
+import org.apache.axis2.security.rahas.RahasConfiguration;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ *
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
+public abstract class TestClient extends TestCase {
+    
+    private static final String AXIS2_ECHO_STRING = "Axis2 Echo String";
+    protected int port = UtilServer.TESTING_PORT;
+    private QName rahasModule = new QName("rahas");
+    
+    public TestClient(String name) {
+        super(name);
+    }
+
+    protected void setUp() throws Exception {
+        UtilServer.start(Constants.TESTING_PATH + getServiceRepo());
+    }
+    
+    protected void tearDown() throws Exception {
+        UtilServer.stop();
+    }
+
+    /**
+     * @param args
+     */
+    public void testRahas() {
+        try {
+
+            // Get the repository location from the args
+            String repo = Constants.TESTING_PATH + "rahas_client_repo";
+
+            OMElement payload = getEchoElement();
+            ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repo, null);
+            ServiceClient serviceClient = new ServiceClient(configContext, null);
+            Options options = new Options();
+            options.setTo(new EndpointReference("http://127.0.0.1:" + port + "/axis2/services/Service"));
+            options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+            options.setProperty(WSSHandlerConstants.OUTFLOW_SECURITY, getClientOutflowConfiguration().getProperty());
+            options.setProperty(WSSHandlerConstants.INFLOW_SECURITY, getClientInflowConfiguration().getProperty());
+            options.setProperty(RahasConfiguration.RAHAS_CONFIG, getClientRahasConfiguration());
+            
+            options.setAction("urn:echo");
+            
+            serviceClient.engageModule(rahasModule);
+
+            serviceClient.setOptions(options);
+            
+            //Blocking invocation
+            OMElement result = serviceClient.sendReceive(payload);
+            result = serviceClient.sendReceive(getEchoElement());
+            StringWriter writer = new StringWriter();
+            result.serialize(XMLOutputFactory.newInstance()
+                    .createXMLStreamWriter(writer));
+            writer.flush();
+            
+            assertTrue(writer.toString().indexOf(AXIS2_ECHO_STRING) > 0);
+            System.out.println("SecureService Invocation successful :-)");
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+            fail(axisFault.getMessage());
+        } catch (XMLStreamException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+    }
+
+    private OMElement getEchoElement() {
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace omNs = fac.createOMNamespace(
+                "http://example1.org/example1", "example1");
+        OMElement method = fac.createOMElement("echo", omNs);
+        OMElement value = fac.createOMElement("Text", omNs);
+        value.addChild(fac.createText(value, AXIS2_ECHO_STRING));
+        method.addChild(value);
+
+        return method;
+    }
+
+    public abstract Parameter getClientRahasConfiguration();
+    
+    public abstract OutflowConfiguration getClientOutflowConfiguration();
+
+    public abstract InflowConfiguration getClientInflowConfiguration();
+    
+    public abstract String getServiceRepo();
+    
+}

Modified: webservices/axis2/trunk/java/modules/security/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/maven.xml?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/security/maven.xml Wed Apr  5 19:28:07 2006
@@ -45,12 +45,12 @@
 		<copy file="src/META-INF/rahas-module.xml"
             tofile="target/temp-mar/META-INF/module.xml" overwrite="true"/>
 
-        <jar jarfile="target/rahas-${security_version}.mar" basedir="target/temp-mar/">
+        <jar jarfile="target/rahas-${rahas_version}.mar" basedir="target/temp-mar/">
             <include name="**/*"/>
         </jar>
 
-        <copy file="target/rahas-${security_version}.mar" tofile="target/modules/rahas-${security_version}.mar"/>
-        <copy file="target/rahas-${security_version}.mar" tofile="${maven.repo.local}/axis2/mars/rahas-${security_version}.mar"/>
+        <copy file="target/rahas-${rahas_version}.mar" tofile="target/modules/rahas-${rahas_version}.mar"/>
+        <copy file="target/rahas-${rahas_version}.mar" tofile="${maven.repo.local}/axis2/mars/rahas-${rahas_version}.mar"/>
 
 		<!-- Replace the maven.xml remove unwanted classes and create the security module -->
 

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java Wed Apr  5 19:28:07 2006
@@ -17,6 +17,7 @@
 package org.apache.axis2.security;
 
 import org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl;
+import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
@@ -196,7 +197,7 @@
                 ((MessageContext)reqData.getMsgContext()).setProperty(WSHandlerConstants.SND_SECURITY,
                         doc);
             } else {
-                msgContext.setEnvelope(Axis2Util.getSOAPEnvelopeFromDOOMDocument(doc, disableDoom));
+                msgContext.setEnvelope((SOAPEnvelope)doc.getDocumentElement());
                 ((MessageContext)reqData.getMsgContext()).setProperty(WSHandlerConstants.SND_SECURITY, null);
             }
             

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/RahasConfiguration.java Wed Apr  5 19:28:07 2006
@@ -263,7 +263,6 @@
         paramElem.addAttribute("name", RahasConfiguration.RAHAS_CONFIG, null);
         paramElem.addChild(element);
         param.setParameterElement(paramElem);
-        System.out.println(paramElem);
         return param;
     }
     

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/STSRequester.java Wed Apr  5 19:28:07 2006
@@ -36,6 +36,7 @@
 import org.apache.axis2.security.util.Axis2Util;
 import org.apache.axis2.util.Base64;
 import org.apache.axis2.util.Loader;
+import org.apache.axis2.util.StreamWrapper;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.message.token.SecurityContextToken;
 import org.apache.ws.security.processor.EncryptedKeyProcessor;
@@ -89,9 +90,9 @@
             rst.setContext(new URI("http://get.optional.attrs.working"));
             
             Axis2Util.useDOOM(false);
-            StAXOMBuilder builder = new StAXOMBuilder(rst
+            StAXOMBuilder builder = new StAXOMBuilder(new StreamWrapper(rst
                     .getPullParser(new QName(Constants.WST_NS,
-                            Constants.REQUEST_SECURITY_TOKEN_LN)));
+                            Constants.REQUEST_SECURITY_TOKEN_LN))));
 
             OMElement tempResult = client.sendReceive(rstQn, builder.getDocumentElement());
             Axis2Util.useDOOM(true);
@@ -115,7 +116,7 @@
             OMElement sctElem = rstElem.getFirstChildWithName(SecurityContextToken.TOKEN);
             if(sctElem != null) {
                 SecurityContextToken sct = new SecurityContextToken((Element)sctElem);
-                token = new Token(sct.getIdentifier(), sctElem);
+                token = new Token(sct.getIdentifier(), sctElem.cloneOMElement());
                 config.setSecurityContextToken(sct);
                 config.resgisterContext(sct.getIdentifier());
             } else {

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/rahas/Sender.java Wed Apr  5 19:28:07 2006
@@ -85,10 +85,6 @@
             }
             
             
-
-            
-            
-            
         } catch (Exception e) {
             e.printStackTrace();
             if(e instanceof RahasException) {

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/impl/SCTIssuer.java Wed Apr  5 19:28:07 2006
@@ -191,7 +191,7 @@
         binSecElem.setText(Base64.encode(secret));
     
         //Store the tokens
-        Token sctToken = new Token(sct.getIdentifier(), (OMElement)sct.getElement());
+        Token sctToken = new Token(sct.getIdentifier(), ((OMElement)sct.getElement()).cloneOMElement());
         sctToken.setSecret(secret);
         this.getTokenStore(msgCtx).add(sctToken);
         
@@ -234,8 +234,6 @@
         
         rstElem.addChild((OMElement)sct.getElement());
         
-        
-        
         Element encryptedKeyElem = encrKeyBuilder.getEncryptedKeyElement();
         Element bstElem = encrKeyBuilder.getBinarySecurityTokenElement();
         
@@ -250,9 +248,14 @@
         reqProofTok.addChild((OMElement)encryptedKeyElem);
     
         //Store the tokens
-        Token sctToken = new Token(sct.getIdentifier(), (OMElement)sct.getElement());
+        OMElement clonedElem = ((OMElement)sct.getElement()).cloneOMElement();
+        Token sctToken = new Token(sct.getIdentifier(), clonedElem);
         sctToken.setSecret(encrKeyBuilder.getEphemeralKey());
         this.getTokenStore(msgCtx).add(sctToken);
+        
+        String bodyStr = env.getBody().toString();
+        System.out.println(bodyStr);
+        System.out.println(env);
         
         return env;
     }

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java?rev=391878&r1=391877&r2=391878&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java Wed Apr  5 19:28:07 2006
@@ -82,6 +82,10 @@
 	public static Document getDocumentFromSOAPEnvelope(SOAPEnvelope env, boolean disableDoom)
 			throws WSSecurityException {
 		try {
+            if(env instanceof Element) {
+                return ((Element)env).getOwnerDocument();
+            }
+            
             if(!disableDoom) {
     			env.build();