ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1153429 - in /webservices/wss4j/trunk/src: main/java/org/apache/ws/security/saml/ext/AssertionWrapper.java test/java/org/apache/ws/security/saml/SamlTokenTest.java test/java/org/apache/ws/security/saml/SignedSamlTokenHOKTest.java
Date Wed, 03 Aug 2011 11:23:42 GMT
Author: coheigea
Date: Wed Aug  3 11:23:41 2011
New Revision: 1153429

URL: http://svn.apache.org/viewvc?rev=1153429&view=rev
Log:
Provide an easy way to access the SignatureValue bytes of a received SAML Assertion.

Modified:
    webservices/wss4j/trunk/src/main/java/org/apache/ws/security/saml/ext/AssertionWrapper.java
    webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java
    webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SignedSamlTokenHOKTest.java

Modified: webservices/wss4j/trunk/src/main/java/org/apache/ws/security/saml/ext/AssertionWrapper.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/main/java/org/apache/ws/security/saml/ext/AssertionWrapper.java?rev=1153429&r1=1153428&r2=1153429&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/main/java/org/apache/ws/security/saml/ext/AssertionWrapper.java
(original)
+++ webservices/wss4j/trunk/src/main/java/org/apache/ws/security/saml/ext/AssertionWrapper.java
Wed Aug  3 11:23:41 2011
@@ -31,6 +31,9 @@ import org.apache.ws.security.saml.ext.b
 
 import org.apache.ws.security.util.DOM2Writer;
 import org.apache.ws.security.util.UUIDGenerator;
+import org.apache.xml.security.exceptions.XMLSecurityException;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
 
 import org.opensaml.common.SAMLVersion;
 import org.opensaml.common.SignableSAMLObject;
@@ -709,5 +712,33 @@ public class AssertionWrapper {
     public SAMLKeyInfo getSubjectKeyInfo() {
         return subjectKeyInfo;
     }
+    
+    /**
+     * Get the SignatureValue bytes of the signed SAML Assertion 
+     * @return the SignatureValue bytes of the signed SAML Assertion 
+     * @throws WSSecurityException
+     */
+    public byte[] getSignatureValue() throws WSSecurityException {
+        Signature sig = null;
+        if (saml2 != null && saml2.getSignature() != null) {
+            sig = saml2.getSignature();
+        } else if (saml1 != null && saml1.getSignature() != null) {
+            sig = saml1.getSignature();
+        }
+        if (sig != null) {
+            Element signatureElement = sig.getDOM();
+            
+            try {
+                // Use XML-Security class to obtain SignatureValue
+                XMLSignature xmlSignature = new XMLSignature(signatureElement, "");
+                return xmlSignature.getSignatureValue();
+            } catch (XMLSignatureException e) {
+                throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity");
+            } catch (XMLSecurityException e) {
+                throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity");
+            }
+        }
+        return null;
+    }
 
 }

Modified: webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java?rev=1153429&r1=1153428&r2=1153429&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java (original)
+++ webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SamlTokenTest.java Wed
Aug  3 11:23:41 2011
@@ -103,6 +103,7 @@ public class SamlTokenTest extends org.j
             (AssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
         assertTrue(receivedAssertion != null);
         assertTrue(!receivedAssertion.isSigned());
+        assertTrue(receivedAssertion.getSignatureValue() == null);
     }
     
     /**

Modified: webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SignedSamlTokenHOKTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SignedSamlTokenHOKTest.java?rev=1153429&r1=1153428&r2=1153429&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SignedSamlTokenHOKTest.java
(original)
+++ webservices/wss4j/trunk/src/test/java/org/apache/ws/security/saml/SignedSamlTokenHOKTest.java
Wed Aug  3 11:23:41 2011
@@ -128,6 +128,7 @@ public class SignedSamlTokenHOKTest exte
             (AssertionWrapper) actionResult.get(WSSecurityEngineResult.TAG_SAML_ASSERTION);
         assertTrue(receivedAssertion != null);
         assertTrue(receivedAssertion.isSigned());
+        assertTrue(receivedAssertion.getSignatureValue() != null);
         
         // Test we processed a signature (SOAP body)
         actionResult = WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);



Mime
View raw message