You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2013/05/14 11:45:37 UTC

svn commit: r1482277 - in /cxf/branches/2.6.x-fixes/rt/ws/security/src: main/java/org/apache/cxf/ws/security/policy/model/AlgorithmSuite.java test/java/org/apache/cxf/ws/security/wss4j/CustomPolicyAlgorithmsTest.java

Author: coheigea
Date: Tue May 14 09:45:36 2013
New Revision: 1482277

URL: http://svn.apache.org/r1482277
Log:
Merged revisions 1482271 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

........
  r1482271 | coheigea | 2013-05-14 10:40:08 +0100 (Tue, 14 May 2013) | 10 lines

  Merged revisions 1482267 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1482267 | coheigea | 2013-05-14 10:37:09 +0100 (Tue, 14 May 2013) | 2 lines

    [CXF-5013] - Need support for SHA256 Signature Algorithms

  ........

........

Added:
    cxf/branches/2.6.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomPolicyAlgorithmsTest.java
Modified:
    cxf/branches/2.6.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/model/AlgorithmSuite.java

Modified: cxf/branches/2.6.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/model/AlgorithmSuite.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/model/AlgorithmSuite.java?rev=1482277&r1=1482276&r2=1482277&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/model/AlgorithmSuite.java (original)
+++ cxf/branches/2.6.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/model/AlgorithmSuite.java Tue May 14 09:45:36 2013
@@ -523,4 +523,22 @@ public class AlgorithmSuite extends Abst
             throw new WSSPolicyException(new Message("INVALID_ALGORITHM", LOG, algoSuite));
         }
     }
+
+
+
+    public void setSymmetricSignature(String symmetricSignature) {
+        this.symmetricSignature = symmetricSignature;
+    }
+
+
+
+    public void setAsymmetricSignature(String asymmetricSignature) {
+        this.asymmetricSignature = asymmetricSignature;
+    }
+
+
+
+    public void setDigest(String digest) {
+        this.digest = digest;
+    }
 }

Added: cxf/branches/2.6.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomPolicyAlgorithmsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomPolicyAlgorithmsTest.java?rev=1482277&view=auto
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomPolicyAlgorithmsTest.java (added)
+++ cxf/branches/2.6.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/CustomPolicyAlgorithmsTest.java Tue May 14 09:45:36 2013
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.ws.security.wss4j;
+
+import org.apache.cxf.ws.policy.AssertionInfo;
+import org.apache.cxf.ws.policy.AssertionInfoMap;
+import org.apache.cxf.ws.security.policy.SP12Constants;
+import org.apache.cxf.ws.security.policy.model.AsymmetricBinding;
+import org.apache.neethi.Policy;
+import org.junit.Test;
+
+public class CustomPolicyAlgorithmsTest extends AbstractPolicySecurityTest {
+
+    @Test
+    public void testSHA256AsymSigAlgorithm() throws Exception {
+
+        final String rsaSha2SigMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
+        String policyName = "signed_elements_policy.xml";
+        Policy policy = policyBuilder.getPolicy(this.getResourceAsStream(policyName)); 
+        AssertionInfoMap aim = new AssertionInfoMap(policy);
+
+        AssertionInfo assertInfo = aim.get(SP12Constants.ASYMMETRIC_BINDING).iterator().next();
+
+        AsymmetricBinding binding = (AsymmetricBinding) assertInfo.getAssertion();
+
+        // set Signature Algorithm to RSA SHA-256
+        binding.getAlgorithmSuite().setAsymmetricSignature(rsaSha2SigMethod);
+
+        String sigMethod = binding.getAlgorithmSuite().getAsymmetricSignature();
+
+        assertNotNull(sigMethod);
+        assertEquals(rsaSha2SigMethod, sigMethod);
+    }
+    
+    @Test
+    public void testSHA256DigestAlgorithm() throws Exception {
+
+        final String sha256 = "http://www.w3.org/2001/04/xmlenc#sha256";
+        String policyName = "signed_elements_policy.xml";
+        Policy policy = policyBuilder.getPolicy(this.getResourceAsStream(policyName)); 
+        AssertionInfoMap aim = new AssertionInfoMap(policy);
+
+        AssertionInfo assertInfo = aim.get(SP12Constants.ASYMMETRIC_BINDING).iterator().next();
+
+        AsymmetricBinding binding = (AsymmetricBinding) assertInfo.getAssertion();
+
+        // set Digest Algorithm to SHA-256
+        binding.getAlgorithmSuite().setDigest(sha256);
+
+        String digestMethod = binding.getAlgorithmSuite().getDigest();
+
+        assertNotNull(digestMethod);
+        assertEquals(sha256, digestMethod);
+    }
+  
+}