Author: anil.saldhana(a)jboss.com
Date: 2009-01-14 20:15:52 -0500 (Wed, 14 Jan 2009)
New Revision: 218
Added:
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/DocumentUtil.java
Modified:
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/SignatureUtil.java
identity-federation/trunk/identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/util/XMLTimeUtilUnitTestCase.java
Log:
some signature support
Modified:
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
===================================================================
---
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java 2009-01-15
01:15:09 UTC (rev 217)
+++
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java 2009-01-15
01:15:52 UTC (rev 218)
@@ -39,7 +39,7 @@
*/
public class JBossSAMLAuthnRequestFactory
{
- private static String pkgName =
"org.jboss.identity.federation.saml.v2.protocol";
+ private static String pkgName =
"org.jboss.identity.federation.saml.v2.protocol:org.jboss.identity.xmlsec.w3.xmldsig";
private static String schemaLocation =
"schema/saml/v2/saml-schema-protocol-2.0.xsd";
private static ObjectFactory protocolObjectFactory = new ObjectFactory();
Modified:
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java
===================================================================
---
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java 2009-01-15
01:15:09 UTC (rev 217)
+++
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java 2009-01-15
01:15:52 UTC (rev 218)
@@ -47,7 +47,7 @@
*/
public class JBossSAMLAuthnResponseFactory
{
- private static String pkgName =
"org.jboss.identity.federation.saml.v2.protocol";
+ private static String pkgName =
"org.jboss.identity.federation.saml.v2.protocol:org.jboss.identity.xmlsec.w3.xmldsig";
private static String schemaLocation =
"schema/saml/v2/saml-schema-protocol-2.0.xsd";
private static ObjectFactory protocolObjectFactory = new ObjectFactory();
Added:
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/DocumentUtil.java
===================================================================
---
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/DocumentUtil.java
(rev 0)
+++
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/DocumentUtil.java 2009-01-15
01:15:52 UTC (rev 218)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.core.saml.v2.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.StringWriter;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+
+/**
+ * Utility dealing with DOM
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Jan 14, 2009
+ */
+public class DocumentUtil
+{
+ public static String getDocumentAsString(Document signedDoc) throws Exception
+ {
+ Source source = new DOMSource(signedDoc);
+ StringWriter sw = new StringWriter();
+
+ Result streamResult = new StreamResult(sw);
+ // Write the DOM document to the file
+ Transformer xformer = TransformerFactory.newInstance().newTransformer();
+ xformer.transform(source, streamResult);
+
+ return sw.toString();
+ }
+
+ public static InputStream getDocumentAsStream(Document signedDoc) throws Exception
+ {
+ Source source = new DOMSource(signedDoc);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ Result streamResult = new StreamResult(baos);
+ // Write the DOM document to the file
+ Transformer xformer = TransformerFactory.newInstance().newTransformer();
+ xformer.transform(source, streamResult);
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
+
+ return bis;
+ }
+}
\ No newline at end of file
Modified:
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/SignatureUtil.java
===================================================================
---
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/SignatureUtil.java 2009-01-15
01:15:09 UTC (rev 217)
+++
identity-federation/trunk/identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/util/SignatureUtil.java 2009-01-15
01:15:52 UTC (rev 218)
@@ -71,6 +71,13 @@
public static boolean validate(byte[] signedContent,
byte[] signatureValue, PublicKey validatingKey) throws Exception
{
+ if(signedContent == null)
+ throw new IllegalArgumentException("signedContent is null");
+ if(signatureValue == null)
+ throw new IllegalArgumentException("signatureValue is null");
+ if(validatingKey == null)
+ throw new IllegalArgumentException("validatingKey is null");
+
//We assume that the sigatureValue has the same algorithm as the public key
//If not, there will be an exception anyway
String algo = validatingKey.getAlgorithm();
@@ -86,6 +93,15 @@
String signatureAlgorithm,
X509Certificate validatingCert) throws Exception
{
+ if(signedContent == null)
+ throw new IllegalArgumentException("signedContent is null");
+ if(signatureValue == null)
+ throw new IllegalArgumentException("signatureValue is null");
+ if(signatureAlgorithm == null)
+ throw new IllegalArgumentException("signatureAlgorithm is null");
+ if(validatingCert == null)
+ throw new IllegalArgumentException("validatingCert is null");
+
Signature sig = getSignature(signatureAlgorithm);
sig.initVerify(validatingCert);
Modified:
identity-federation/trunk/identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/util/XMLTimeUtilUnitTestCase.java
===================================================================
---
identity-federation/trunk/identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/util/XMLTimeUtilUnitTestCase.java 2009-01-15
01:15:09 UTC (rev 217)
+++
identity-federation/trunk/identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/util/XMLTimeUtilUnitTestCase.java 2009-01-15
01:15:52 UTC (rev 218)
@@ -66,5 +66,6 @@
//isValid(now, notbefore, notOnOrAfter)
assertTrue(XMLTimeUtil.isValid(after5M, now, after10M));
+ assertFalse(XMLTimeUtil.isValid(now, after5M,after10M));
}
}
\ No newline at end of file