Author: anil.saldhana(a)jboss.com
Date: 2011-07-26 14:56:56 -0400 (Tue, 26 Jul 2011)
New Revision: 1131
Modified:
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java
Log:
test signing the response type
Modified:
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java 2011-07-26
17:28:17 UTC (rev 1130)
+++
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java 2011-07-26
18:56:56 UTC (rev 1131)
@@ -24,17 +24,42 @@
import static org.junit.Assert.assertNotNull;
import java.io.InputStream;
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
import org.junit.Test;
import org.picketlink.identity.federation.api.saml.v2.response.SAML2Response;
+import org.picketlink.identity.federation.api.saml.v2.sig.SAML2Signature;
+import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
import org.picketlink.identity.federation.saml.v2.SAML2Object;
+import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+import org.picketlink.test.identity.federation.api.util.KeyUtilUnitTestCase;
+import org.w3c.dom.Document;
/**
+ * Parse a {@link ResponseType} that contains A
* @author Anil.Saldhana(a)redhat.com
* @since Jul 21, 2011
*/
public class SAML2ResponseUnitTestCase
{
+
+ private final String keystoreLocation = "keystore/jbid_test_keystore.jks";
+
+ private final String keystorePass = "store123";
+
+ private final String keyPass = "test123";
+
+ private final String alias = "servercert";
+
+ /**
+ * Parse a {@link ResponseType} that contains ADFS Claims
+ * and then try to sign
+ * @throws Exception
+ */
@Test
public void parseADFSClaims() throws Exception
{
@@ -43,6 +68,34 @@
SAML2Response samlResponse = new SAML2Response();
SAML2Object samlObject = samlResponse.getSAML2ObjectFromStream(configStream);
assertNotNull(samlObject);
+
+ SAML2Signature sig = new SAML2Signature();
+ Document signedDoc = sig.sign((ResponseType) samlObject, getKeyPair());
+ assertNotNull(signedDoc);
+
+ System.out.println("Signed Response=" +
DocumentUtil.asString(signedDoc));
}
+ /**
+ * @see {@link KeyUtilUnitTestCase}
+ * @return
+ * @throws Exception
+ */
+ private KeyPair getKeyPair() throws Exception
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ InputStream ksStream = tcl.getResourceAsStream(keystoreLocation);
+ assertNotNull("Input keystore stream is not null", ksStream);
+
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(ksStream, keystorePass.toCharArray());
+ assertNotNull("KeyStore is not null", ks);
+
+ Certificate cert = ks.getCertificate(alias);
+ assertNotNull("Cert not null", cert);
+
+ // Get private key
+ Key key = ks.getKey(alias, keyPass.toCharArray());
+ return new KeyPair(cert.getPublicKey(), (PrivateKey) key);
+ }
}
\ No newline at end of file
Show replies by date