You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by am...@apache.org on 2012/03/01 10:54:07 UTC

svn commit: r1295489 [4/5] - in /axis/axis2/java/rampart/branches/1_6: ./ modules/rampart-core/src/main/java/org/apache/rampart/ modules/rampart-core/src/main/java/org/apache/rampart/builder/ modules/rampart-core/src/main/java/org/apache/rampart/handle...

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario4Test.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario4Test.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario4Test.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario4Test.java Thu Mar  1 09:54:05 2012
@@ -42,7 +42,7 @@ public class Scenario4Test extends Inter
 		ofc.setEmbeddedKeyName("SessionKey");
 		ofc.setSignatureKeyIdentifier(WSSHandlerConstants.BST_DIRECT_REFERENCE);
 		ofc.setEmbeddedKeyCallbackClass("org.apache.axis2.security.PWCallback");
-		
+
 		return ofc;
 	}
 
@@ -52,6 +52,12 @@ public class Scenario4Test extends Inter
 		ifc.setActionItems("Signature Encrypt Timestamp");
 		ifc.setPasswordCallbackClass("org.apache.axis2.security.PWCallback");
 		ifc.setSignaturePropFile("interop.properties");
+
+        /**
+         * This test is not "Basic Security Profile(BSP)" compatible. Cos we use
+         * KeyInfo/KeyName. Therefore setting this test as not BSP compatible.
+         */
+        ifc.setBSPCompliant(false);
 		
 		return ifc;
 	}
@@ -92,6 +98,7 @@ public class Scenario4Test extends Inter
         ifc.setPasswordCallbackClass("org.apache.axis2.security.PWCallback");
         
         ifc.setSignaturePropRefId("key2");
+        ifc.setBSPCompliant(false);
         
         return ifc;
     }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario5Test.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario5Test.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario5Test.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/axis2/security/Scenario5Test.java Thu Mar  1 09:54:05 2012
@@ -32,7 +32,7 @@ public class Scenario5Test extends Inter
 	protected OutflowConfiguration getOutflowConfiguration() {
 		OutflowConfiguration ofc = new OutflowConfiguration(2);
 		
-		ofc.setActionItems("Signature NoSerialization");
+		ofc.setActionItems("Signature");
 		ofc.setUser("alice");
 		ofc.setSignaturePropFile("interop.properties");
 		ofc.setPasswordCallbackClass("org.apache.axis2.security.PWCallback");
@@ -68,7 +68,7 @@ public class Scenario5Test extends Inter
     protected OutflowConfiguration getOutflowConfigurationWithRefs() {
         OutflowConfiguration ofc = new OutflowConfiguration(2);
         
-        ofc.setActionItems("Signature NoSerialization");
+        ofc.setActionItems("Signature");
         ofc.setUser("alice");
         ofc.setSignaturePropRefId("key1");
         ofc.setPasswordCallbackClass("org.apache.axis2.security.PWCallback");

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java Thu Mar  1 09:54:05 2012
@@ -36,11 +36,24 @@ import org.apache.axis2.integration.Util
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyEngine;
 
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
 
 public class RampartTest extends TestCase {
 
     public final static int PORT = UtilServer.TESTING_PORT;
 
+    private static ResourceBundle resources;
+
+    static {
+        try {
+            resources = ResourceBundle.getBundle("org.apache.rampart.errors");
+        } catch (MissingResourceException e) {
+            throw new RuntimeException(e.getMessage());
+        }
+    }
+
     public RampartTest(String name) {
         super(name);
     }
@@ -83,7 +96,7 @@ public class RampartTest extends TestCas
                         "Unlimited Strength Jurisdiction Policy !!!");
             }
             
-            for (int i = 1; i <= 33; i++) { //<-The number of tests we have
+            for (int i = 1; i <= 34; i++) { //<-The number of tests we have
                 if(!basic256Supported && (i == 3 || i == 4 || i == 5)) {
                     //Skip the Basic256 tests
                     continue;
@@ -122,19 +135,34 @@ public class RampartTest extends TestCas
                     serviceClient.addHeader(header);
                 }
                 
-                // Invoking the serive in the TestCase-28 should fail. So handling it differently..
-                if (i == 28) {
+                // Invoking the service in the TestCase-28 should fail. So handling it differently..
+                if (i == 28 || i == 34) {
                     try {
+
                         //Blocking invocation
                         serviceClient.sendReceive(getOMElement());
-                        fail("Service Should throw an error..");
+
+                        String message = "";
+
+                        if (i == 34) {
+                            message = "Test case 34 should fail. We are running the service in symmetric binding mode " +
+                                      "and client in asymmetric binding mode. Therefore test case 34 should fail.";
+                        }
+
+                        fail("Service Should throw an error - " + message);
 
                     } catch (AxisFault axisFault) {
-                        assertEquals("Expected encrypted part missing", axisFault.getMessage());
+
+                        if (i == 28) {
+                            assertEquals(resources.getString("encryptionMissing"), axisFault.getMessage());
+                        } else if (i == 34) {
+                            assertEquals(resources.getString("invalidSignatureAlgo"), axisFault.getMessage());
+                        }
+
                     }
                 }
-
                 else{
+
                     //Blocking invocation
                     serviceClient.sendReceive(getEchoElement());
                 }

Added: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/policy/34.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/policy/34.xml?rev=1295489&view=auto
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/policy/34.xml (added)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/policy/34.xml Thu Mar  1 09:54:05 2012
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ !
+ ! Copyright 2006 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.
+ !-->
+
+<wsp:Policy wsu:Id="SigEncr"
+            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
+            xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+	    xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+    <wsp:ExactlyOne>
+        <wsp:All>
+	<sp:SymmetricBinding>
+                                <wsp:Policy>
+                                        <sp:ProtectionToken>
+                                                <wsp:Policy>
+                                                        <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
+                                                                <wsp:Policy>
+                                                                        <sp:RequireThumbprintReference/>
+                                                                        <sp:WssX509V3Token10/>
+                                                                </wsp:Policy>
+                                                        </sp:X509Token>
+                                                </wsp:Policy>
+                                        </sp:ProtectionToken>
+                                        <sp:AlgorithmSuite>
+                                                <wsp:Policy>
+                                                        <sp:Basic256/>
+                                                </wsp:Policy>
+                                        </sp:AlgorithmSuite>
+                                        <sp:Layout>
+                                                <wsp:Policy>
+                                                        <sp:Lax/>
+                                                </wsp:Policy>
+                                        </sp:Layout>
+                                        <sp:IncludeTimestamp/>
+                                        <sp:OnlySignEntireHeadersAndBody/>
+                                </wsp:Policy>
+            </sp:SymmetricBinding>
+            <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <wsp:Policy>
+                    <sp:MustSupportRefKeyIdentifier/>
+                    <sp:MustSupportRefIssuerSerial/>
+                </wsp:Policy>
+            </sp:Wss10>
+            <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <sp:Body/>
+            </sp:SignedParts>
+            <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <sp:Body/>
+            </sp:EncryptedParts>
+
+           <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
+                    <ramp:user>alice</ramp:user>
+                    <ramp:encryptionUser>bob</ramp:encryptionUser>
+                    <ramp:passwordCallbackClass>org.apache.rampart.PWCallback
+                    </ramp:passwordCallbackClass>
+
+                    <ramp:signatureCrypto>
+                        <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.type">JKS
+                            </ramp:property>
+                            <ramp:property name="org.apache.ws.security.crypto.merlin.file">
+                                rampart/store.jks
+                            </ramp:property>
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.password">
+                                password
+                            </ramp:property>
+                        </ramp:crypto>
+                    </ramp:signatureCrypto>
+                    <ramp:encryptionCypto>
+                        <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.type">JKS
+                            </ramp:property>
+                            <ramp:property name="org.apache.ws.security.crypto.merlin.file">
+                                rampart/store.jks
+                            </ramp:property>
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.password">
+                                password
+                            </ramp:property>
+                        </ramp:crypto>
+                    </ramp:encryptionCypto>
+                </ramp:RampartConfig>
+
+        </wsp:All>
+    </wsp:ExactlyOne>
+</wsp:Policy>
\ No newline at end of file

Added: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/services-34.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/services-34.xml?rev=1295489&view=auto
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/services-34.xml (added)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/rampart/services-34.xml Thu Mar  1 09:54:05 2012
@@ -0,0 +1,113 @@
+<service name="SecureService34">
+
+	<module ref="addressing"/>
+	<module ref="rampart"/>
+
+	<parameter locked="false" name="ServiceClass">org.apache.rampart.Service</parameter>
+
+	<operation name="echo">
+		<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+		<actionMapping>urn:echo</actionMapping>
+	</operation>
+
+	<operation name="returnError">
+        <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
+        <actionMapping>urn:returnError</actionMapping>
+    </operation>
+
+     <wsp:Policy wsu:Id="SigEncr"
+                xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
+                xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+        <wsp:ExactlyOne>
+            <wsp:All>
+                <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                    <wsp:Policy>
+                        <sp:InitiatorToken>
+                            <wsp:Policy>
+                                <sp:X509Token
+                                        sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
+                                    <wsp:Policy>
+                                        <sp:RequireThumbprintReference/>
+                                        <sp:WssX509V3Token10/>
+                                    </wsp:Policy>
+                                </sp:X509Token>
+                            </wsp:Policy>
+                        </sp:InitiatorToken>
+                        <sp:RecipientToken>
+                            <wsp:Policy>
+                                <sp:X509Token
+                                        sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
+                                    <wsp:Policy>
+                                        <sp:RequireThumbprintReference/>
+                                        <sp:WssX509V3Token10/>
+                                    </wsp:Policy>
+                                </sp:X509Token>
+                            </wsp:Policy>
+                        </sp:RecipientToken>
+                        <sp:AlgorithmSuite>
+                            <wsp:Policy>
+                                <sp:TripleDesRsa15/>
+                            </wsp:Policy>
+                        </sp:AlgorithmSuite>
+                        <sp:Layout>
+                            <wsp:Policy>
+                                <sp:Strict/>
+                            </wsp:Policy>
+                        </sp:Layout>
+                        <sp:IncludeTimestamp/>
+                        <sp:OnlySignEntireHeadersAndBody/>
+                    </wsp:Policy>
+                </sp:AsymmetricBinding>
+                <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                    <wsp:Policy>
+                        <sp:MustSupportRefKeyIdentifier/>
+                        <sp:MustSupportRefIssuerSerial/>
+                    </wsp:Policy>
+                </sp:Wss10>
+                <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                    <sp:Body/>
+                </sp:SignedParts>
+                <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                    <sp:Body/>
+                </sp:EncryptedParts>
+
+                <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
+                    <ramp:user>alice</ramp:user>
+                    <ramp:encryptionUser>bob</ramp:encryptionUser>
+                    <ramp:passwordCallbackClass>org.apache.rampart.PWCallback
+                    </ramp:passwordCallbackClass>
+
+                    <ramp:signatureCrypto>
+                        <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.type">JKS
+                            </ramp:property>
+                            <ramp:property name="org.apache.ws.security.crypto.merlin.file">
+                                rampart/store.jks
+                            </ramp:property>
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.password">
+                                password
+                            </ramp:property>
+                        </ramp:crypto>
+                    </ramp:signatureCrypto>
+                    <ramp:encryptionCypto>
+                        <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.type">JKS
+                            </ramp:property>
+                            <ramp:property name="org.apache.ws.security.crypto.merlin.file">
+                                rampart/store.jks
+                            </ramp:property>
+                            <ramp:property
+                                    name="org.apache.ws.security.crypto.merlin.keystore.password">
+                                password
+                            </ramp:property>
+                        </ramp:crypto>
+                    </ramp:encryptionCypto>
+                </ramp:RampartConfig>
+            </wsp:All>
+        </wsp:ExactlyOne>
+    </wsp:Policy>
+
+</service>

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s2a.service.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s2a.service.xml?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s2a.service.xml (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s2a.service.xml Thu Mar  1 09:54:05 2012
@@ -7,7 +7,7 @@
 
     <parameter name="InflowSecurity">
       <action>
-        <items>UsernameTokenSignature UsernameToken Encrypt Timestamp</items>
+        <items>UsernameTokenSignature UsernameTokenNoPassword Encrypt Timestamp</items>
         <passwordCallbackClass>org.apache.axis2.security.PWCallback</passwordCallbackClass>
         <decryptionPropFile>interop.properties</decryptionPropFile>
       </action>

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.client.axis2.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.client.axis2.xml?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.client.axis2.xml (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.client.axis2.xml Thu Mar  1 09:54:05 2012
@@ -15,8 +15,8 @@
             <encryptionKeyIdentifier>EmbeddedKeyName</encryptionKeyIdentifier>
             <encryptionSymAlgorithm>http://www.w3.org/2001/04/xmlenc#tripledes-cbc</encryptionSymAlgorithm>
             <signaturePropFile>interop.properties</signaturePropFile>
-            <EmbeddedKeyCallbackClass>org.apache.axis2.security.PWCallback</EmbeddedKeyCallbackClass>
-            <EmbeddedKeyName>SessionKey</EmbeddedKeyName>
+            <embeddedKeyCallbackClass>org.apache.axis2.security.PWCallback</embeddedKeyCallbackClass>
+            <embeddedKeyName>SessionKey</embeddedKeyName>
         </action>
     </parameter>
 
@@ -25,6 +25,7 @@
             <items>Signature Encrypt Timestamp</items>
             <passwordCallbackClass>org.apache.axis2.security.PWCallback</passwordCallbackClass>
             <signaturePropFile>interop.properties</signaturePropFile>
+	    <isBSPCompliant>false</isBSPCompliant>
         </action>
     </parameter>
 

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.service.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.service.xml?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.service.xml (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s4.service.xml Thu Mar  1 09:54:05 2012
@@ -10,6 +10,7 @@
         <items>Signature Encrypt Timestamp</items>
         <passwordCallbackClass>org.apache.axis2.security.PWCallback</passwordCallbackClass>
         <signaturePropFile>interop.properties</signaturePropFile>
+	<isBSPCompliant>false</isBSPCompliant>
       </action>
     </parameter>
 
@@ -22,8 +23,8 @@
         <encryptionKeyIdentifier>EmbeddedKeyName</encryptionKeyIdentifier>
         <encryptionSymAlgorithm>http://www.w3.org/2001/04/xmlenc#tripledes-cbc</encryptionSymAlgorithm>
         <signaturePropFile>interop.properties</signaturePropFile>
-        <EmbeddedKeyCallbackClass>org.apache.axis2.security.PWCallback</EmbeddedKeyCallbackClass>
-        <EmbeddedKeyName>SessionKey</EmbeddedKeyName>
+        <embeddedKeyCallbackClass>org.apache.axis2.security.PWCallback</embeddedKeyCallbackClass>
+        <embeddedKeyName>SessionKey</embeddedKeyName>
       </action>
     </parameter>
 

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s5.client.axis2.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s5.client.axis2.xml?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s5.client.axis2.xml (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-integration/src/test/resources/security/s5.client.axis2.xml Thu Mar  1 09:54:05 2012
@@ -9,7 +9,7 @@
     <parameter name="OutflowSecurity">
 
         <action>
-            <items>Signature NoSerialization</items>
+            <items>Signature</items>
             <user>alice</user>
             <passwordCallbackClass>org.apache.axis2.security.PWCallback</passwordCallbackClass>
             <signatureKeyIdentifier>DirectReference</signatureKeyIdentifier>
@@ -115,7 +115,7 @@
         <phase name="OperationOutFaultPhase"/>
         <phase name="RMPhase"/>
         <phase name="PolicyDetermination"/>
-        <phase name="MessageOut"/>
+        <phase name="MessageOut"/>
         <phase name="Security"/>
     </phaseOrder>
 </axisconfig>

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/MessageBuilderTestBase.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/MessageBuilderTestBase.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/MessageBuilderTestBase.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/MessageBuilderTestBase.java Thu Mar  1 09:54:05 2012
@@ -125,7 +125,8 @@ public class MessageBuilderTestBase exte
         while (secHeaderChildren.hasNext()) {
             OMElement element = (OMElement) secHeaderChildren.next();
             if (qnameList.hasNext()) {
-                if (!element.getQName().equals(qnameList.next())) {
+                QName elementQName = (QName)qnameList.next();
+                if (!element.getQName().equals(elementQName)) {
                     fail("Incorrect Element" + element);
                 }
             } else {

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/RampartEngineTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/RampartEngineTest.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/RampartEngineTest.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/RampartEngineTest.java Thu Mar  1 09:54:05 2012
@@ -17,24 +17,15 @@
 package org.apache.rampart;
 
 import java.io.ByteArrayInputStream;
-import java.util.Vector;
-import java.util.ArrayList;
+import java.util.List;
 import java.security.cert.X509Certificate;
 
-import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.builder.SOAPBuilder;
 import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.engine.AxisEngine;
-import org.apache.axis2.namespace.Constants;
 import org.apache.neethi.Policy;
-import org.apache.rampart.util.Axis2Util;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSecurityEngineResult;
-import org.apache.ws.security.handler.WSHandlerResult;
-import org.apache.ws.security.handler.WSHandlerConstants;
-
-import javax.xml.namespace.QName;
 
 public class RampartEngineTest extends MessageBuilderTestBase {
 
@@ -77,7 +68,7 @@ public class RampartEngineTest extends M
         buildSOAPEnvelope(ctx);
 
         RampartEngine engine = new RampartEngine();
-        Vector results = engine.process(ctx);
+        List<WSSecurityEngineResult> results = engine.process(ctx);
 
         /*
         The principle purpose of the test case is to verify that the above processes
@@ -87,12 +78,11 @@ public class RampartEngineTest extends M
         assertNotNull("RampartEngine returned null result", results);
         //verify cert was stored
         X509Certificate usedCert = null;
-        for (int i = 0; i < results.size(); i++) {
-            WSSecurityEngineResult wser = (WSSecurityEngineResult) results.get(i);
-            Integer action = (Integer) wser.get(WSSecurityEngineResult.TAG_ACTION);
-            if (action.intValue() == WSConstants.SIGN) {
+        for (WSSecurityEngineResult result : results) {
+            Integer action = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);
+            if (action == WSConstants.SIGN) {
                 //the result is for the signature, which contains the used certificate
-                usedCert = (X509Certificate) wser.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE);
+                usedCert = (X509Certificate) result.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE);
                 break;
             }
         }
@@ -115,7 +105,7 @@ public class RampartEngineTest extends M
         buildSOAPEnvelope(ctx);
 
         RampartEngine engine = new RampartEngine();
-        Vector results = engine.process(ctx);
+        List<org.apache.ws.security.WSSecurityEngineResult> results = engine.process(ctx);
 
         /*
         The principle purpose of the test case is to verify that the above processes
@@ -125,12 +115,11 @@ public class RampartEngineTest extends M
         assertNotNull("RampartEngine returned null result", results);
         //verify cert was stored
         X509Certificate usedCert = null;
-        for (int i = 0; i < results.size(); i++) {
-            WSSecurityEngineResult wser = (WSSecurityEngineResult) results.get(i);
-            Integer action = (Integer) wser.get(WSSecurityEngineResult.TAG_ACTION);
-            if (action.intValue() == WSConstants.SIGN) {
+        for (WSSecurityEngineResult result : results) {
+            Integer action = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);
+            if (action == WSConstants.SIGN) {
                 //the result is for the signature, which contains the used certificate
-                usedCert = (X509Certificate) wser.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE);
+                usedCert = (X509Certificate) result.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE);
                 break;
             }
         }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/TestCBHandler.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/TestCBHandler.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/TestCBHandler.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/src/test/java/org/apache/rampart/TestCBHandler.java Thu Mar  1 09:54:05 2012
@@ -74,40 +74,38 @@ public class TestCBHandler implements Ca
             throws IOException, UnsupportedCallbackException {
 
 
+        for (Callback callback : callbacks) {
 
-        for (int i = 0; i < callbacks.length; i++) {
-
-            if (callbacks[i] instanceof WSPasswordCallback) {
-
-                WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
+            if (callback instanceof WSPasswordCallback) {
 
+                WSPasswordCallback pc = (WSPasswordCallback) callback;
 
 
                 /*
 
-                 * This usage type is used only in case we received a
+                * This usage type is used only in case we received a
 
-                 * username token with a password of type PasswordText or
+                * username token with a password of type PasswordText or
 
-                 * an unknown password type.
+                * an unknown password type.
 
-                 * 
+                *
 
-                 * This case the WSPasswordCallback object contains the
+                * This case the WSPasswordCallback object contains the
 
-                 * identifier (aka username), the password we received, and
+                * identifier (aka username), the password we received, and
 
-                 * the password type string to identify the type.
+                * the password type string to identify the type.
 
-                 * 
+                *
 
-                 * Here we perform only a very simple check.
+                * Here we perform only a very simple check.
 
-                 */
+                */
 
                 if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
 
-                    if(pc.getIdentifer().equals("Ron") && pc.getPassword().equals("noR")) {
+                    if (pc.getIdentifier().equals("Ron") && pc.getPassword().equals("noR")) {
 
                         return;
 
@@ -117,11 +115,11 @@ public class TestCBHandler implements Ca
 
                         return;
 
-                    }                   
+                    }
 
-                    throw new UnsupportedCallbackException(callbacks[i],
+                    throw new UnsupportedCallbackException(callback,
 
-                    "check failed");
+                            "check failed");
 
                 }
 
@@ -141,15 +139,15 @@ public class TestCBHandler implements Ca
 
                     pc.setKey(key);
 
-                } else if(pc.getIdentifer().equals("alice")) {
+                } else if (pc.getIdentifier().equals("alice")) {
 
                     pc.setPassword("password");
 
-                } else if(pc.getIdentifer().equals("bob")) {
+                } else if (pc.getIdentifier().equals("bob")) {
 
                     pc.setPassword("password");
 
-                } else if(pc.getIdentifer().equals("Ron")) {
+                } else if (pc.getIdentifier().equals("Ron")) {
 
                     pc.setPassword("noR");
 
@@ -161,7 +159,7 @@ public class TestCBHandler implements Ca
 
             } else {
 
-                throw new UnsupportedCallbackException(callbacks[i],
+                throw new UnsupportedCallbackException(callback,
 
                         "Unrecognized Callback");
 

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/test-resources/PWCallback.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/test-resources/PWCallback.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/test-resources/PWCallback.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-tests/test-resources/PWCallback.java Thu Mar  1 09:54:05 2012
@@ -116,7 +116,7 @@ public class PWCallback implements Callb
 
                 if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
 
-                	if(pc.getIdentifer().equals("Ron") && pc.getPassword().equals("noR")) {
+                	if(pc.getIdentifier().equals("Ron") && pc.getPassword().equals("noR")) {
 
                         return;
 
@@ -150,15 +150,15 @@ public class PWCallback implements Callb
 
                     pc.setKey(key);
 
-                } else if(pc.getIdentifer().equals("alice")) {
+                } else if(pc.getIdentifier().equals("alice")) {
 
                     pc.setPassword("password");
 
-                } else if(pc.getIdentifer().equals("bob")) {
+                } else if(pc.getIdentifier().equals("bob")) {
 
                     pc.setPassword("password");
 
-                } else if(pc.getIdentifer().equals("Ron")) {
+                } else if(pc.getIdentifier().equals("Ron")) {
 
                     pc.setPassword("noR");
 

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/RahasData.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/RahasData.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/RahasData.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/RahasData.java Thu Mar  1 09:54:05 2012
@@ -35,7 +35,7 @@ import javax.xml.namespace.QName;
 
 import java.security.Principal;
 import java.security.cert.X509Certificate;
-import java.util.Vector;
+import java.util.List;
 
 /**
  * Common data items on WS-Trust request messages
@@ -153,38 +153,35 @@ public class RahasData {
          * we will not be encrypting the response
          */
 
-        Vector results;
-        if ((results = (Vector) this.inMessageContext
+        List<WSHandlerResult> results;
+        if ((results = (List<WSHandlerResult>) this.inMessageContext
                 .getProperty(WSHandlerConstants.RECV_RESULTS)) == null) {
             throw new TrustException(TrustException.REQUEST_FAILED);
         } else {
 
-            for (int i = 0; i < results.size(); i++) {
-                WSHandlerResult rResult = (WSHandlerResult) results.get(i);
-                Vector wsSecEngineResults = rResult.getResults();
-
-                for (int j = 0; j < wsSecEngineResults.size(); j++) {
-                    WSSecurityEngineResult wser = (WSSecurityEngineResult) wsSecEngineResults
-                            .get(j);
+            for (WSHandlerResult result : results) {
+                List<WSSecurityEngineResult> wsSecEngineResults = result.getResults();
+
+                for (WSSecurityEngineResult wser : wsSecEngineResults) {
                     Object principalObject = wser.get(WSSecurityEngineResult.TAG_PRINCIPAL);
-                    int act = ((Integer)wser.get(WSSecurityEngineResult.TAG_ACTION)).
-                            intValue();
+                    int act = (Integer) wser.get(WSSecurityEngineResult.TAG_ACTION);
+
                     if (act == WSConstants.SIGN && principalObject != null) {
                         this.clientCert = (X509Certificate) wser
                                 .get(WSSecurityEngineResult.TAG_X509_CERTIFICATE);
-                        this.principal = (Principal)principalObject;
+                        this.principal = (Principal) principalObject;
                     } else if (act == WSConstants.UT && principalObject != null) {
-                        this.principal = (Principal)principalObject;
+                        this.principal = (Principal) principalObject;
                     } else if (act == WSConstants.BST) {
-                        final X509Certificate[] certificates = 
-                            (X509Certificate[]) wser
-                                .get(WSSecurityEngineResult.TAG_X509_CERTIFICATES);
+                        final X509Certificate[] certificates =
+                                (X509Certificate[]) wser
+                                        .get(WSSecurityEngineResult.TAG_X509_CERTIFICATES);
                         this.clientCert = certificates[0];
                         this.principal = this.clientCert.getSubjectDN();
                     } else if (act == WSConstants.ST_UNSIGNED) {
                         this.assertion = (Assertion) wser
                                 .get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
-                        
+
                     }
                 }
             }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java Thu Mar  1 09:54:05 2012
@@ -16,6 +16,7 @@
 
 package org.apache.rahas.client;
 
+import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNode;
@@ -43,6 +44,7 @@ import org.apache.rahas.Token;
 import org.apache.rahas.TokenStorage;
 import org.apache.rahas.TrustException;
 import org.apache.rahas.TrustUtil;
+import org.apache.rahas.impl.util.CommonUtil;
 import org.apache.ws.secpolicy.model.AlgorithmSuite;
 import org.apache.ws.secpolicy.model.Binding;
 import org.apache.ws.secpolicy.model.Trust10;
@@ -54,7 +56,6 @@ import org.apache.ws.security.components
 import org.apache.ws.security.conversation.ConversationException;
 import org.apache.ws.security.conversation.dkalgo.P_SHA1;
 import org.apache.ws.security.message.token.Reference;
-import org.apache.ws.security.processor.EncryptedKeyProcessor;
 import org.apache.ws.security.util.WSSecurityUtil;
 import org.apache.ws.security.util.XmlSchemaDateFormat;
 import org.w3c.dom.Element;
@@ -70,7 +71,6 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Vector;
 
 public class STSClient {
 
@@ -137,6 +137,10 @@ public class STSClient {
             
             client.getServiceContext().setProperty(RAMPART_POLICY, issuerPolicy);
             client.getOptions().setSoapVersionURI(this.soapVersion);
+
+            //TODO Remove later
+            client.getOptions().setTimeOutInMilliSeconds(300000);
+
             if(this.addressingNs != null) {
                 client.getOptions().setProperty(AddressingConstants.WS_ADDRESSING_VERSION, this.addressingNs);
             }
@@ -474,36 +478,34 @@ public class STSClient {
                 String b64Secret = child.getText();
                 secret = Base64.decode(b64Secret);
             } else if (child.getQName().equals(new QName(ns, WSConstants.ENC_KEY_LN))) {
-                try {
-                    Element domChild = (Element) new StAXOMBuilder(
-                            DOOMAbstractFactory.getOMFactory(), child
-                            .getXMLStreamReader()).getDocumentElement();
 
-                    EncryptedKeyProcessor processor = new EncryptedKeyProcessor();
+                Element domChild = (Element) new StAXOMBuilder(
+                        OMAbstractFactory.getMetaFactory(
+                                OMAbstractFactory.FEATURE_DOM).getOMFactory(),
+                        child.getXMLStreamReader()).getDocumentElement();
 
-                    processor.handleToken(domChild, null, this.crypto,
-                                          this.cbHandler, null, new Vector(),
-                                          null);
-
-                    secret = processor.getDecryptedBytes();
+                try {
+                    secret = CommonUtil.getDecryptedBytes(this.cbHandler, this.crypto, domChild);
                 } catch (WSSecurityException e) {
+                    log.error("Error decrypting encrypted key element", e);
                     throw new TrustException("errorInProcessingEncryptedKey", e);
                 }
+
             } else if (child.getQName().equals(new QName(ns,
-                                                         RahasConstants.IssuanceBindingLocalNames.
-                                                                 COMPUTED_KEY))) {
+                    RahasConstants.IssuanceBindingLocalNames.
+                            COMPUTED_KEY))) {
                 //Handle the computed key
 
                 //Get service entropy
                 OMElement serviceEntrElem = rstr
                         .getFirstChildWithName(new QName(ns,
-                                                         RahasConstants.IssuanceBindingLocalNames.
-                                                                 ENTROPY));
+                                RahasConstants.IssuanceBindingLocalNames.
+                                        ENTROPY));
 
                 OMElement binSecElem = serviceEntrElem.getFirstElement();
 
                 if (binSecElem != null && binSecElem.getText() != null
-                    && !"".equals(binSecElem.getText().trim())) {
+                        && !"".equals(binSecElem.getText().trim())) {
 
                     byte[] serviceEntr = Base64.decode(binSecElem.getText());
 
@@ -511,10 +513,10 @@ public class STSClient {
                     P_SHA1 p_sha1 = new P_SHA1();
 
                     int length = (this.keySize > 0) ? keySize
-                                 : this.algorithmSuite
+                            : this.algorithmSuite
                             .getMaximumSymmetricKeyLength();
                     try {
-                        secret = p_sha1.createKey(this.requestorEntropy, serviceEntr, 0, length/8);
+                        secret = p_sha1.createKey(this.requestorEntropy, serviceEntr, 0, length / 8);
                     } catch (ConversationException e) {
                         throw new TrustException("keyDerivationError", e);
                     }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/errors.properties
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/errors.properties?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/errors.properties (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/errors.properties Thu Mar  1 09:54:05 2012
@@ -97,4 +97,7 @@ issuerPrivateKeyNotFound = Unable to get
 errorMarshallingAssertion = Error while marshalling assertion
 errorSigningAssertion = Error signing SAML Assertion. An error occurred while signing SAML Assertion with alias : \"{0}\"
 sha1NotFound = Unable to find SHA-1 algorithm implementation
-certificateEncodingError = Error encoding certificate
\ No newline at end of file
+certificateEncodingError = Error encoding certificate
+
+errorLoadingCryptoProperties = An error occurred while loading crypto properties
+errorLoadingCryptoPropertiesFile = An error occurred while loading crypto properties from file : \"{0}\"
\ No newline at end of file

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java Thu Mar  1 09:54:05 2012
@@ -26,6 +26,7 @@ import org.apache.axis2.description.Para
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.rahas.*;
+import org.apache.rahas.impl.util.CommonUtil;
 import org.apache.rahas.impl.util.SAMLAttributeCallback;
 import org.apache.rahas.impl.util.SAMLCallbackHandler;
 import org.apache.rahas.impl.util.SignKeyHolder;
@@ -85,8 +86,6 @@ import java.util.List;
 
 public class SAML2TokenIssuer implements TokenIssuer {
 
-    private Assertion SAMLAssertion;
-
     private String configParamName;
 
     private OMElement configElement;
@@ -355,12 +354,14 @@ public class SAML2TokenIssuer implements
      * @return Subject
      * @throws Exception
      */
-    private Subject createSubjectWithHolderOfKeySC(SAMLTokenIssuerConfig config,
+    Subject createSubjectWithHolderOfKeySC(SAMLTokenIssuerConfig config,
                                                    Document doc, Crypto crypto,
                                                    DateTime creationTime,
                                                    DateTime expirationTime, RahasData data) throws Exception {
 
 
+        // TODO modify these to use proper SAML apis
+
         XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory();
         SAMLObjectBuilder<Subject> subjectBuilder =
                 (SAMLObjectBuilder<Subject>) builderFactory.getBuilder(Subject.DEFAULT_ELEMENT_NAME);
@@ -392,11 +393,13 @@ public class SAML2TokenIssuer implements
                 // set keysize
                 int keysize = data.getKeysize();
                 keysize = (keysize != -1) ? keysize : config.keySize;
-                encrKeyBuilder.setKeySize(keysize);
+
+                // TODO setting keysize is removed with wss4j 1.6 migration - do we actually need this ?
 
                 encrKeyBuilder.setEphemeralKey(TokenIssuerUtil.getSharedSecret(
                         data, config.keyComputation, keysize));
 
+
                 // Set key encryption algo
                 encrKeyBuilder
                         .setKeyEncAlgo(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSA15);
@@ -448,9 +451,8 @@ public class SAML2TokenIssuer implements
                 X509Certificate clientCert = data.getClientCert();
 
                 if (clientCert == null) {
-                    X509Certificate[] certs = crypto.getCertificates(
-                            data.getPrincipal().getName());
-                    clientCert = certs[0];
+                    // TODO are we always looking up by alias ? Dont we need to lookup by any other attribute ?
+                    clientCert = CommonUtil.getCertificateByAlias(crypto, data.getPrincipal().getName());
                 }
 
                 byte[] clientCertBytes = clientCert.getEncoded();
@@ -642,8 +644,7 @@ public class SAML2TokenIssuer implements
         SignKeyHolder signKeyHolder = new SignKeyHolder();
 
         try {
-            X509Certificate[] issuerCerts = crypto
-                    .getCertificates(config.issuerKeyAlias);
+            X509Certificate[] issuerCerts = CommonUtil.getCertificatesByAlias(crypto,config.issuerKeyAlias);
 
             String sigAlgo = XMLSignature.ALGO_ID_SIGNATURE_RSA;
             String pubKeyAlgo = issuerCerts[0].getPublicKey().getAlgorithm();

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java Thu Mar  1 09:54:05 2012
@@ -29,36 +29,23 @@ import org.apache.rahas.Token;
 import org.apache.rahas.TokenIssuer;
 import org.apache.rahas.TrustException;
 import org.apache.rahas.TrustUtil;
-import org.apache.rahas.impl.util.SAMLAttributeCallback;
-import org.apache.rahas.impl.util.SAMLCallbackHandler;
-import org.apache.rahas.impl.util.SAMLNameIdentifierCallback;
-import org.apache.rahas.impl.util.SAMLUtils;
+import org.apache.rahas.impl.util.*;
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.WSUsernameTokenPrincipal;
 import org.apache.ws.security.components.crypto.Crypto;
 import org.apache.ws.security.components.crypto.CryptoFactory;
-import org.apache.ws.security.util.Base64;
 import org.apache.ws.security.util.Loader;
 import org.apache.ws.security.util.XmlSchemaDateFormat;
-import org.apache.xml.security.signature.XMLSignature;
 
 import org.joda.time.DateTime;
 import org.opensaml.common.SAMLException;
 import org.opensaml.saml1.core.*;
-import org.opensaml.xml.security.*;
-import org.opensaml.xml.security.SecurityException;
-import org.opensaml.xml.security.credential.Credential;
 import org.opensaml.xml.signature.KeyInfo;
-import org.opensaml.xml.signature.Signature;
-import org.opensaml.xml.signature.SignatureException;
-import org.opensaml.xml.signature.Signer;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
 import java.security.Principal;
-import java.security.PrivateKey;
-import java.security.PublicKey;
 import java.security.SecureRandom;
 import java.security.cert.X509Certificate;
 import java.text.DateFormat;
@@ -118,15 +105,14 @@ public class SAMLTokenIssuer implements 
                 .getEnvelope().getNamespace().getNamespaceURI());
 
         Crypto crypto;
-        if (config.cryptoElement != null) { // crypto props
-                                                        // defined as
-                                                        // elements
-            crypto = CryptoFactory.getInstance(TrustUtil
+        if (config.cryptoElement != null) { // crypto props defined as elements
+            crypto = CommonUtil.getCrypto(TrustUtil
                     .toProperties(config.cryptoElement), inMsgCtx
                     .getAxisService().getClassLoader());
+
         } else { // crypto props defined in a properties file
-            crypto = CryptoFactory.getInstance(config.cryptoPropertiesFile,
-                    inMsgCtx.getAxisService().getClassLoader());
+            crypto = CommonUtil.getCrypto(config.cryptoPropertiesFile, inMsgCtx
+                    .getAxisService().getClassLoader());
         }
 
         // Creation and expiration times
@@ -361,9 +347,7 @@ public class SAMLTokenIssuer implements 
                 X509Certificate clientCert = data.getClientCert();
 
                 if(clientCert == null) {
-                    X509Certificate[] certs = crypto.getCertificates(
-                            data.getPrincipal().getName());
-                    clientCert = certs[0];
+                    clientCert = CommonUtil.getCertificateByAlias(crypto,data.getPrincipal().getName());;
                 }
 
                 KeyInfo keyInfo = SAMLUtils.getCertificateBasedKeyInfo(clientCert);
@@ -380,27 +364,28 @@ public class SAMLTokenIssuer implements 
      * Uses the <code>wst:AppliesTo</code> to figure out the certificate to
      * encrypt the secret in the SAML token
      * 
-     * @param config
-     * @param crypto
+     * @param config Token issuer configuration.
+     * @param crypto Crypto properties.
      * @param serviceAddress
      *            The address of the service
-     * @return
-     * @throws WSSecurityException
+     * @return The X509 certificate.
+     * @throws org.apache.rahas.TrustException If an error occurred while retrieving certificate from crypto.
      */
     private X509Certificate getServiceCert(SAMLTokenIssuerConfig config,
-            Crypto crypto, String serviceAddress) throws WSSecurityException {
-        
+            Crypto crypto, String serviceAddress) throws TrustException {
+
+        // TODO a duplicate method !!
         if (serviceAddress != null && !"".equals(serviceAddress)) {
             String alias = (String) config.trustedServices.get(serviceAddress);
             if (alias != null) {
-                return crypto.getCertificates(alias)[0];
+                return CommonUtil.getCertificateByAlias(crypto,alias);
             } else {
                 alias = (String) config.trustedServices.get("*");
-                return crypto.getCertificates(alias)[0];
+                return CommonUtil.getCertificateByAlias(crypto,alias);
             }
         } else {
             String alias = (String) config.trustedServices.get("*");
-            return crypto.getCertificates(alias)[0];
+            return CommonUtil.getCertificateByAlias(crypto,alias);
         }
 
     }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java Thu Mar  1 09:54:05 2012
@@ -25,6 +25,7 @@ import org.apache.axis2.description.Para
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.rahas.TrustException;
+import org.apache.rahas.impl.util.CommonUtil;
 import org.apache.rahas.impl.util.SAMLCallbackHandler;
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.components.crypto.Crypto;
@@ -441,21 +442,21 @@ public class SAMLTokenIssuerConfig exten
      * @param serviceAddress
      *            The address of the service
      * @return
-     * @throws org.apache.ws.security.WSSecurityException
+     * @throws org.apache.rahas.TrustException If unable to find certificate by given alias.
      */
-    public X509Certificate getServiceCert(Crypto crypto, String serviceAddress) throws WSSecurityException {
+    public X509Certificate getServiceCert(Crypto crypto, String serviceAddress) throws TrustException {
 
         if (serviceAddress != null && !"".equals(serviceAddress)) {
             String alias = (String) this.trustedServices.get(serviceAddress);
             if (alias != null) {
-                return crypto.getCertificates(alias)[0];
+                return CommonUtil.getCertificateByAlias(crypto,alias);
             } else {
                 alias = (String) this.trustedServices.get("*");
-                return crypto.getCertificates(alias)[0];
+                return CommonUtil.getCertificateByAlias(crypto,alias);
             }
         } else {
             String alias = (String) this.trustedServices.get("*");
-            return crypto.getCertificates(alias)[0];
+            return CommonUtil.getCertificateByAlias(crypto,alias);
         }
 
     }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenRenewer.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenRenewer.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenRenewer.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenRenewer.java Thu Mar  1 09:54:05 2012
@@ -15,9 +15,9 @@ import org.apache.rahas.TokenRenewer;
 import org.apache.rahas.TokenStorage;
 import org.apache.rahas.TrustException;
 import org.apache.rahas.TrustUtil;
+import org.apache.rahas.impl.util.CommonUtil;
 import org.apache.rahas.impl.util.SAMLUtils;
 import org.apache.ws.security.components.crypto.Crypto;
-import org.apache.ws.security.components.crypto.CryptoFactory;
 import org.apache.ws.security.util.XmlSchemaDateFormat;
 import org.joda.time.DateTime;
 import org.opensaml.saml1.core.Assertion;
@@ -89,15 +89,14 @@ public class SAMLTokenRenewer implements
         }
 
         Crypto crypto;
+        ClassLoader classLoader = inMsgCtx.getAxisService().getClassLoader();
         if (config.cryptoElement != null) {
             // crypto props defined as elements
-            crypto = CryptoFactory.getInstance(TrustUtil
-                    .toProperties(config.cryptoElement), inMsgCtx
-                    .getAxisService().getClassLoader());
+            crypto = CommonUtil.getCrypto(TrustUtil
+                    .toProperties(config.cryptoElement), classLoader);
         } else {
             // crypto props defined in a properties file
-            crypto = CryptoFactory.getInstance(config.cryptoPropertiesFile,
-                    inMsgCtx.getAxisService().getClassLoader());
+            crypto = CommonUtil.getCrypto(config.cryptoPropertiesFile, classLoader);
         }
 
         // Create TokenType element

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenValidator.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenValidator.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenValidator.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenValidator.java Thu Mar  1 09:54:05 2012
@@ -6,7 +6,6 @@ import java.security.cert.X509Certificat
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.Parameter;
@@ -19,6 +18,7 @@ import org.apache.rahas.TokenStorage;
 import org.apache.rahas.TokenValidator;
 import org.apache.rahas.TrustException;
 import org.apache.rahas.TrustUtil;
+import org.apache.rahas.impl.util.CommonUtil;
 import org.apache.rahas.impl.util.SAMLUtils;
 import org.apache.ws.security.components.crypto.Crypto;
 import org.apache.ws.security.components.crypto.CryptoFactory;
@@ -47,83 +47,77 @@ public class SAMLTokenValidator implemen
      *                request.
      */
     public SOAPEnvelope validate(RahasData data) throws TrustException {
-	// retrieve the message context
-	MessageContext inMsgCtx = data.getInMessageContext();
+        // retrieve the message context
+        MessageContext inMsgCtx = data.getInMessageContext();
 
-	// retrieve the list of tokens from the message context
-	TokenStorage tkStorage = TrustUtil.getTokenStore(inMsgCtx);
+        // retrieve the list of tokens from the message context
+        TokenStorage tkStorage = TrustUtil.getTokenStore(inMsgCtx);
 
-	try {
-	    // Set the DOM impl to DOOM
-	    DocumentBuilderFactoryImpl.setDOOMRequired(true);
-
-	    // Create envelope
-	    SOAPEnvelope env = TrustUtil.createSOAPEnvelope(inMsgCtx
-		    .getEnvelope().getNamespace().getNamespaceURI());
-
-	    // Create RSTR element, with respective version
-	    OMElement rstrElem;
-	    int wstVersion = data.getVersion();
-	    if (RahasConstants.VERSION_05_02 == wstVersion) {
-		rstrElem = TrustUtil.createRequestSecurityTokenResponseElement(
-			wstVersion, env.getBody());
-	    } else {
-		OMElement rstrcElem = TrustUtil
-			.createRequestSecurityTokenResponseCollectionElement(
-				wstVersion, env.getBody());
-		rstrElem = TrustUtil.createRequestSecurityTokenResponseElement(
-			wstVersion, rstrcElem);
-	    }
-
-	    // Create TokenType element, set to RSTR/Status
-	    TrustUtil.createTokenTypeElement(wstVersion, rstrElem).setText(
-		    TrustUtil.getWSTNamespace(wstVersion)
-			    + RahasConstants.TOK_TYPE_STATUS);
-
-	    // Create Status element
-	    OMElement statusElement = createMessageElement(wstVersion,
-		    rstrElem, RahasConstants.LocalNames.STATUS);
-
-	    // Obtain the token
-	    Token tk = tkStorage.getToken(data.getTokenId());
-
-	    // create the crypto object
-	    PublicKey issuerPBKey = getIssuerPublicKey(inMsgCtx);
-
-	    boolean valid = isValid(tk, issuerPBKey);
-	    String validityCode;
-
-	    if (valid) {
-		validityCode = RahasConstants.STATUS_CODE_VALID;
-	    } else {
-		validityCode = RahasConstants.STATUS_CODE_INVALID;
-	    }
-
-	    // Create Code element (inside Status) and set it to the
-	    // correspondent value
-	    createMessageElement(wstVersion, statusElement,
-		    RahasConstants.LocalNames.CODE).setText(
-		    TrustUtil.getWSTNamespace(wstVersion) + validityCode);
-
-	    return env;
-	} finally {
-	    DocumentBuilderFactoryImpl.setDOOMRequired(false);
-	}
+        // Create envelope
+        SOAPEnvelope env = TrustUtil.createSOAPEnvelope(inMsgCtx
+                .getEnvelope().getNamespace().getNamespaceURI());
+
+        // Create RSTR element, with respective version
+        OMElement rstrElem;
+        int wstVersion = data.getVersion();
+        if (RahasConstants.VERSION_05_02 == wstVersion) {
+            rstrElem = TrustUtil.createRequestSecurityTokenResponseElement(
+                    wstVersion, env.getBody());
+        } else {
+            OMElement rstrcElem = TrustUtil
+                    .createRequestSecurityTokenResponseCollectionElement(
+                            wstVersion, env.getBody());
+            rstrElem = TrustUtil.createRequestSecurityTokenResponseElement(
+                    wstVersion, rstrcElem);
+        }
+
+        // Create TokenType element, set to RSTR/Status
+        TrustUtil.createTokenTypeElement(wstVersion, rstrElem).setText(
+                TrustUtil.getWSTNamespace(wstVersion)
+                        + RahasConstants.TOK_TYPE_STATUS);
+
+        // Create Status element
+        OMElement statusElement = createMessageElement(wstVersion,
+                rstrElem, RahasConstants.LocalNames.STATUS);
+
+        // Obtain the token
+        Token tk = tkStorage.getToken(data.getTokenId());
+
+        // create the crypto object
+        PublicKey issuerPBKey = getIssuerPublicKey(inMsgCtx);
+
+        boolean valid = isValid(tk, issuerPBKey);
+        String validityCode;
+
+        if (valid) {
+            validityCode = RahasConstants.STATUS_CODE_VALID;
+        } else {
+            validityCode = RahasConstants.STATUS_CODE_INVALID;
+        }
+
+        // Create Code element (inside Status) and set it to the
+        // correspondent value
+        createMessageElement(wstVersion, statusElement,
+                RahasConstants.LocalNames.CODE).setText(
+                TrustUtil.getWSTNamespace(wstVersion) + validityCode);
+
+        return env;
     }
 
     /**
      * Checks whether the token is valid or not, by verifying the issuer's own
      * signature. If it has been signed by the token issuer, then it is a valid
      * token.
-     *
-     * @param token       the token to validate.
+     * 
+     * @param token
+     *                the token to validate.
      * @param issuerPBKey Public key which should be used during validation.
      * @return true if the token has been signed by the issuer.
      */
     private boolean isValid(Token token, PublicKey issuerPBKey) {
         // extract SAMLAssertion object from token
         OMElement assertionOMElement = token.getToken();
-        Assertion samlAssertion = null;
+        Assertion samlAssertion;
 
         try {
             samlAssertion = SAMLUtils.buildAssertion((Element) assertionOMElement);
@@ -133,6 +127,7 @@ public class SAMLTokenValidator implemen
             // check if the token has been signed by the issuer.
             SignatureValidator validator = new SignatureValidator(samlAssertion.getSignature().getSigningCredential());
             validator.validate(samlAssertion.getSignature());
+
         } catch (ValidationException e) {
             log.error("Signature verification failed on SAML token.", e);
             return false;
@@ -145,72 +140,71 @@ public class SAMLTokenValidator implemen
     //here we basically reuse the SAMLTokenIssuer config
     // to create the crypto object, so we can load the issuer's certificates
     private PublicKey getIssuerPublicKey(MessageContext inMsgCtx) {
-	PublicKey issuerPBKey = null;
-	SAMLTokenIssuerConfig config = null;
+        PublicKey issuerPBKey = null;
+        SAMLTokenIssuerConfig config = null;
+
+        try {
+            if (configElement != null) {
+                config = new SAMLTokenIssuerConfig(
+                        configElement
+                                .getFirstChildWithName(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG));
+            }
+
+            // Look for the file
+            if ((config == null) && (configFile != null)) {
+                config = new SAMLTokenIssuerConfig(configFile);
+            }
+
+            // Look for the param
+            if ((config == null) && (configParamName != null)) {
+                Parameter param = inMsgCtx.getParameter(configParamName);
+                if ((param != null) && (param.getParameterElement() != null)) {
+                    config = new SAMLTokenIssuerConfig(param
+                            .getParameterElement().getFirstChildWithName(
+                                    SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG));
+                } else {
+                    throw new TrustException("expectedParameterMissing",
+                            new String[] { configParamName });
+                }
+            }
+
+            if (config == null) {
+                throw new TrustException("configurationIsNull");
+            }
+
+            Crypto crypto;
+            if (config.cryptoElement != null) { // crypto props
+                // defined as
+                // elements
+                crypto = CryptoFactory.getInstance(TrustUtil
+                        .toProperties(config.cryptoElement), inMsgCtx
+                        .getAxisService().getClassLoader());
+            } else { // crypto props defined in a properties file
+                crypto = CryptoFactory.getInstance(config.cryptoPropertiesFile,
+                        inMsgCtx.getAxisService().getClassLoader());
+            }
 
-	try {
-	    if (configElement != null) {
-		config = new SAMLTokenIssuerConfig(
-			configElement
-				.getFirstChildWithName(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG));
-	    }
-
-	    // Look for the file
-	    if ((config == null) && (configFile != null)) {
-		config = new SAMLTokenIssuerConfig(configFile);
-	    }
-
-	    // Look for the param
-	    if ((config == null) && (configParamName != null)) {
-		Parameter param = inMsgCtx.getParameter(configParamName);
-		if ((param != null) && (param.getParameterElement() != null)) {
-		    config = new SAMLTokenIssuerConfig(param
-			    .getParameterElement().getFirstChildWithName(
-				    SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG));
-		} else {
-		    throw new TrustException("expectedParameterMissing",
-			    new String[] { configParamName });
-		}
-	    }
-
-	    if (config == null) {
-		throw new TrustException("configurationIsNull");
-	    }
-
-	    Crypto crypto;
-	    if (config.cryptoElement != null) { // crypto props
-		// defined as
-		// elements
-		crypto = CryptoFactory.getInstance(TrustUtil
-			.toProperties(config.cryptoElement), inMsgCtx
-			.getAxisService().getClassLoader());
-	    } else { // crypto props defined in a properties file
-		crypto = CryptoFactory.getInstance(config.cryptoPropertiesFile,
-			inMsgCtx.getAxisService().getClassLoader());
-	    }
-
-	    X509Certificate[] issuerCerts = crypto
-		    .getCertificates(config.issuerKeyAlias);
-
-	    issuerPBKey = issuerCerts[0].getPublicKey();
-
-	} catch (Exception e) {
-	    log.error("Could not retrieve issuer public key", e);
-	}
-	return issuerPBKey;
+            X509Certificate issuerCert = CommonUtil.getCertificateByAlias(crypto,config.issuerKeyAlias);
+
+            issuerPBKey = issuerCert.getPublicKey();
+
+        } catch (Exception e) {
+            log.error("Could not retrieve issuer public key", e);
+        }
+        return issuerPBKey;
     }
 
 
     private static OMElement createMessageElement(int version,
-	    OMElement parent, String elementName) throws TrustException {
-	return createOMElement(parent, TrustUtil.getWSTNamespace(version),
-		elementName, RahasConstants.WST_PREFIX);
+            OMElement parent, String elementName) throws TrustException {
+        return createOMElement(parent, TrustUtil.getWSTNamespace(version),
+                elementName, RahasConstants.WST_PREFIX);
     }
 
     private static OMElement createOMElement(OMElement parent, String ns,
-	    String ln, String prefix) {
-	return parent.getOMFactory().createOMElement(new QName(ns, ln, prefix),
-		parent);
+            String ln, String prefix) {
+        return parent.getOMFactory().createOMElement(new QName(ns, ln, prefix),
+                parent);
     }
 
     // ========================================================================
@@ -223,7 +217,7 @@ public class SAMLTokenValidator implemen
      * @param configFile  configuration file to be used.
      */
     public void setConfigurationFile(String configFile) {
-	this.configFile = configFile;
+        this.configFile = configFile;
     }
 
     /**
@@ -236,11 +230,11 @@ public class SAMLTokenValidator implemen
      * @see org.apache.axis2.description.Parameter
      */
     public void setConfigurationParamName(String configParamName) {
-	this.configParamName = configParamName;
+        this.configParamName = configParamName;
     }
 
     public void setConfigurationElement(OMElement configElement) {
-	this.configElement = configElement;
+        this.configElement = configElement;
     }
 
 }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/TokenIssuerUtil.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/TokenIssuerUtil.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/TokenIssuerUtil.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/TokenIssuerUtil.java Thu Mar  1 09:54:05 2012
@@ -24,10 +24,10 @@ import org.apache.rahas.RahasData;
 import org.apache.rahas.Token;
 import org.apache.rahas.TrustException;
 import org.apache.rahas.TrustUtil;
+import org.apache.rahas.impl.util.CommonUtil;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.components.crypto.Crypto;
-import org.apache.ws.security.components.crypto.CryptoFactory;
 import org.apache.ws.security.conversation.ConversationException;
 import org.apache.ws.security.conversation.dkalgo.P_SHA1;
 import org.apache.ws.security.message.WSSecEncryptedKey;
@@ -107,14 +107,13 @@ public class TokenIssuerUtil {
             if (TokenIssuerUtil.ENCRYPTED_KEY.equals(config.proofKeyType)) {
                 WSSecEncryptedKey encrKeyBuilder = new WSSecEncryptedKey();
                 Crypto crypto;
+
+                ClassLoader classLoader = data.getInMessageContext().getAxisService().getClassLoader();
+
                 if (config.cryptoElement != null) { // crypto props defined as elements
-                    crypto = CryptoFactory.getInstance(TrustUtil.toProperties(config.cryptoElement),
-                                                       data.getInMessageContext().
-                                                               getAxisService().getClassLoader());
+                    crypto = CommonUtil.getCrypto(TrustUtil.toProperties(config.cryptoElement),classLoader);
                 } else { // crypto props defined in a properties file
-                    crypto = CryptoFactory.getInstance(config.cryptoPropertiesFile,
-                                                       data.getInMessageContext().
-                                                               getAxisService().getClassLoader());
+                    crypto = CommonUtil.getCrypto(config.cryptoPropertiesFile, classLoader);
                 }
 
                 encrKeyBuilder.setKeyIdentifierType(WSConstants.THUMBPRINT_IDENTIFIER);

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/CommonUtil.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/CommonUtil.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/CommonUtil.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/CommonUtil.java Thu Mar  1 09:54:05 2012
@@ -18,12 +18,31 @@ package org.apache.rahas.impl.util;
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.dom.DOMMetaFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.rahas.TrustException;
+import org.apache.rahas.TrustUtil;
+import org.apache.ws.security.WSDocInfo;
+import org.apache.ws.security.WSSConfig;
+import org.apache.ws.security.WSSecurityEngineResult;
+import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.components.crypto.CryptoFactory;
+import org.apache.ws.security.components.crypto.CryptoType;
+import org.apache.ws.security.handler.RequestData;
+import org.apache.ws.security.processor.EncryptedKeyProcessor;
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
+import javax.security.auth.callback.CallbackHandler;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import java.security.cert.X509Certificate;
+import java.util.List;
+import java.util.Properties;
+
 import static org.apache.axiom.om.OMAbstractFactory.FEATURE_DOM;
 
 /**
@@ -31,6 +50,8 @@ import static org.apache.axiom.om.OMAbst
  */
 public class CommonUtil {
 
+    private static Log log = LogFactory.getLog(CommonUtil.class);
+
     /**
      * This method creates a DOM compatible Axiom document.
      * @return DOM compatible Axiom document
@@ -45,4 +66,123 @@ public class CommonUtil {
             throw new TrustException("Error creating Axiom compatible DOM Document", e);
         }
     }
+
+    /**
+     * Gets the certificates chain by alias. Always returns the first certificate if a certificate chain is found.
+     * @param crypto Crypto to lookup certificate.
+     * @param alias Alias name.
+     * @return X509 certificate object.
+     * @throws org.apache.rahas.TrustException If an error occurred
+     *                              while retrieving the certificate or if no certificates are found for given alias.
+     */
+    public static X509Certificate getCertificateByAlias(Crypto crypto, String alias) throws TrustException {
+
+        X509Certificate[] certificates = getCertificatesByAlias(crypto, alias);
+
+        if (certificates == null) {
+            log.error("Unable to retrieve certificate for alias " + alias);
+            throw new TrustException("issuerCertificateNotFound");
+        }
+
+        return certificates[0];
+    }
+
+    /**
+     * Gets the certificates chain by alias. If no certificates are found return an empty array.
+     * @param crypto Crypto to lookup certificate.
+     * @param alias Alias name.
+     * @return X509 certificates array.
+     * @throws org.apache.rahas.TrustException If an error occurred
+     *                                          while retrieving the certificate.
+     */
+    public static X509Certificate[] getCertificatesByAlias(Crypto crypto, String alias) throws TrustException {
+
+        // TODO are we always looking up by alias ? Dont we need to lookup by any other attribute ?
+        CryptoType type = new CryptoType(CryptoType.TYPE.ALIAS);
+        type.setAlias(alias);
+
+        try {
+            X509Certificate[] certificates = crypto.getX509Certificates(type);
+
+            if (certificates == null) {
+                log.debug("Unable to retrieve certificate for alias " + alias);
+                return new X509Certificate[0];
+            }
+            return certificates;
+        } catch (WSSecurityException e) {
+            log.error("Unable to retrieve certificate for alias " + alias, e);
+            throw new TrustException("issuerCertificateNotFound", e);
+        }
+    }
+
+    /**
+     * Decrypts the EncryptedKey element and returns the secret that was used.
+     * @param callbackHandler Callback handler to pass to WSS4J framework.
+     * @param crypto To get private key information.
+     * @param encryptedKeyElement The encrypted Key element.
+     * @return The secret as a byte stream.
+     * @throws WSSecurityException If an error is occurred while decrypting the element.
+     */
+    public static byte[] getDecryptedBytes(CallbackHandler callbackHandler, Crypto crypto, Node encryptedKeyElement)
+            throws WSSecurityException {
+
+        // TODO make this code more efficient and reader friendly
+
+        EncryptedKeyProcessor encryptedKeyProcessor = new EncryptedKeyProcessor();
+
+        RequestData requestData = new RequestData();
+        requestData.setCallbackHandler(callbackHandler);
+        requestData.setDecCrypto(crypto);
+
+        final WSSConfig cfg = WSSConfig.getNewInstance();
+        requestData.setWssConfig(cfg);
+
+        WSDocInfo docInfo = new WSDocInfo(encryptedKeyElement.getOwnerDocument());
+
+        List<WSSecurityEngineResult> resultList
+                = null;
+
+        resultList = encryptedKeyProcessor.handleToken((Element) encryptedKeyElement, requestData, docInfo);
+
+
+        WSSecurityEngineResult wsSecurityEngineResult = resultList.get(0);
+
+        return (byte[]) wsSecurityEngineResult.get(WSSecurityEngineResult.TAG_SECRET);
+    }
+
+    /**
+     * Constructs crypto configuration based on the given properties. Provider is instantiated using
+     * given class loader.
+     * @param properties Crypto configuration properties.
+     * @param classLoader Class loader used to create provider.
+     * @return A crypto object.
+     * @throws TrustException If an error occurred while creating the Crypto object.
+     */
+    public static Crypto getCrypto(Properties properties, ClassLoader classLoader) throws TrustException {
+        try {
+            return CryptoFactory.getInstance(properties, classLoader);
+        } catch (WSSecurityException e) {
+            log.error("An error occurred while loading crypto properties", e);
+            throw new TrustException("errorLoadingCryptoProperties", e);
+
+        }
+    }
+
+    /**
+     * Constructs crypto configuration based on the given properties. Provider is instantiated using
+     * given class loader.
+     * @param propertiesFile Crypto configuration properties file name.
+     * @param classLoader Class loader used to create provider.
+     * @return A crypto object.
+     * @throws TrustException If an error occurred while creating the Crypto object.
+     */
+    public static Crypto getCrypto(String propertiesFile, ClassLoader classLoader) throws TrustException {
+        try {
+            return CryptoFactory.getInstance(propertiesFile, classLoader);
+        } catch (WSSecurityException e) {
+            log.error("An error occurred while loading crypto properties with property file " + propertiesFile, e);
+            throw new TrustException("errorLoadingCryptoProperties", new Object[]{propertiesFile}, e);
+
+        }
+    }
 }

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/SAML2Utils.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/SAML2Utils.java?rev=1295489&r1=1295488&r2=1295489&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/SAML2Utils.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/util/SAML2Utils.java Thu Mar  1 09:54:05 2012
@@ -22,11 +22,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.rahas.RahasConstants;
 import org.apache.rahas.TrustException;
-import org.apache.ws.security.WSConstants;
-import org.apache.ws.security.WSPasswordCallback;
-import org.apache.ws.security.WSSecurityEngine;
-import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.*;
 import org.apache.ws.security.components.crypto.Crypto;
+import org.apache.ws.security.handler.RequestData;
 import org.apache.ws.security.processor.EncryptedKeyProcessor;
 import org.apache.ws.security.util.Base64;
 import org.apache.xml.security.exceptions.XMLSecurityException;
@@ -119,7 +117,7 @@ public class SAML2Utils {
      *
      */
     public static SAML2KeyInfo getSAML2KeyInfo(Element elem, Crypto crypto,
-                                              CallbackHandler cb) throws WSSecurityException {
+                                              CallbackHandler cb) throws WSSecurityException, TrustException {
         Assertion assertion;
 
         //build the assertion by unmarhalling the DOM element.
@@ -258,10 +256,9 @@ public class SAML2Utils {
                         QName el = new QName(child.getNamespaceURI(), child.getLocalName());
                         if (el.equals(WSSecurityEngine.ENCRYPTED_KEY)) {
 
-                            EncryptedKeyProcessor proc = new EncryptedKeyProcessor();
-                            proc.handleEncryptedKey((Element) child, cb, crypto, null);
+                            byte[] secret = CommonUtil.getDecryptedBytes(cb, crypto, child);
 
-                            return new SAML2KeyInfo(assertion, proc.getDecryptedBytes());
+                            return new SAML2KeyInfo(assertion, secret);
                         } else if (el.equals(new QName(WSConstants.WST_NS, "BinarySecret"))) {
                             Text txt = (Text) child.getFirstChild();
                             return new SAML2KeyInfo(assertion, Base64.decode(txt.getData()));