[jboss-cvs] JBossAS SVN: r78611 - in projects/security/security-xacml/trunk/jboss-xacml-saml/src: tests/org/jboss/test/security/xacml/saml and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 16 23:57:04 EDT 2008
Author: anil.saldhana at jboss.com
Date: 2008-09-16 23:57:04 -0400 (Tue, 16 Sep 2008)
New Revision: 78611
Modified:
projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLRequest.java
projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLResponse.java
projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java
Log:
SECURITY-275: buildRequest method
Modified: projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLRequest.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLRequest.java 2008-09-17 03:56:46 UTC (rev 78610)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLRequest.java 2008-09-17 03:57:04 UTC (rev 78611)
@@ -25,9 +25,16 @@
import java.io.InputStream;
import java.util.List;
+import org.jboss.security.xacml.saml.integration.opensaml.core.OpenSAMLUtil;
import org.jboss.security.xacml.saml.integration.opensaml.util.DOMUtil;
import org.jboss.security.xacml.saml.integration.opensaml.util.SAML2Util;
+import org.joda.time.DateTime;
+import org.joda.time.chrono.ISOChronology;
import org.opensaml.common.SAMLObject;
+import org.opensaml.common.SAMLVersion;
+import org.opensaml.saml2.core.AuthnRequest;
+import org.opensaml.saml2.core.Issuer;
+import org.opensaml.saml2.core.RequestAbstractType;
import org.opensaml.ws.soap.soap11.Body;
import org.opensaml.ws.soap.soap11.Envelope;
import org.opensaml.xml.XMLObject;
@@ -44,6 +51,38 @@
public class JBossSAMLRequest
{
/**
+ * Build a SAML Request
+ * @param issueInstant
+ * @param requestId Id for the request
+ * @param issuerId ID of the issuer (can be null)
+ * @return
+ */
+ public SAMLObject buildRequest(DateTime issueInstant,
+ String requestId, String issuerId)
+ {
+ if(issueInstant == null)
+ issueInstant = new DateTime(ISOChronology.getInstanceUTC());
+
+ RequestAbstractType samlRequest =
+ (RequestAbstractType) OpenSAMLUtil.buildXMLObject(AuthnRequest.DEFAULT_ELEMENT_NAME);
+
+ if(issuerId != null)
+ {
+ Issuer issuer = (Issuer) OpenSAMLUtil.buildXMLObject(Issuer.DEFAULT_ELEMENT_NAME);
+ issuer.setValue(issuerId);
+ samlRequest.setIssuer(issuer);
+ }
+
+ samlRequest.setID(requestId);
+ samlRequest.setIssueInstant(issueInstant);
+
+ //Hard code support for SAMl2
+ samlRequest.setVersion(SAMLVersion.VERSION_20);
+
+ return samlRequest;
+ }
+
+ /**
* Given a saml request file, parse the saml object
* @param requestFile
* @return
Modified: projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLResponse.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLResponse.java 2008-09-17 03:56:46 UTC (rev 78610)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/main/java/org/jboss/security/xacml/saml/integration/opensaml/request/JBossSAMLResponse.java 2008-09-17 03:57:04 UTC (rev 78611)
@@ -30,6 +30,7 @@
import org.joda.time.DateTime;
import org.joda.time.chrono.ISOChronology;
import org.opensaml.common.SAMLObject;
+import org.opensaml.saml2.core.Issuer;
import org.opensaml.saml2.core.Response;
import org.opensaml.saml2.core.Status;
import org.opensaml.saml2.core.StatusCode;
@@ -74,14 +75,20 @@
/**
* Get a response object with the issue instant, response ID
* and Issuer ID
+ * <b>Note the response has been set to a status of success.</b>
+ *
* @param issueInstant if null, get the current time
- * @param responseId
- * @param issuerId
+ * @param responseId The ID of the responses
+ * @param issuerId Id of the Response Issuer - can be null
* @return
+ * @throws IllegalArgumentException if responseID is null
*/
public Response getSAMLResponse(DateTime issueInstant,
String responseId, String issuerId)
{
+ if(responseId == null)
+ throw new IllegalArgumentException("responseID is null");
+
if(issueInstant == null)
issueInstant = new DateTime(ISOChronology.getInstanceUTC());
@@ -89,6 +96,13 @@
samlResponse.setID(responseId);
samlResponse.setIssueInstant(issueInstant);
+ if(issuerId != null)
+ {
+ Issuer issuer = (Issuer) OpenSAMLUtil.buildXMLObject(Issuer.DEFAULT_ELEMENT_NAME);
+ issuer.setValue(issuerId);
+ samlResponse.setIssuer(issuer);
+ }
+
//Set samlp:Status
Status status = (Status) OpenSAMLUtil.buildXMLObject(Status.DEFAULT_ELEMENT_NAME);
StatusCode statusCode = (StatusCode) OpenSAMLUtil.buildXMLObject(StatusCode.DEFAULT_ELEMENT_NAME);
Modified: projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java 2008-09-17 03:56:46 UTC (rev 78610)
+++ projects/security/security-xacml/trunk/jboss-xacml-saml/src/tests/org/jboss/test/security/xacml/saml/SAMLRequestUnitTestCase.java 2008-09-17 03:57:04 UTC (rev 78611)
@@ -21,13 +21,18 @@
*/
package org.jboss.test.security.xacml.saml;
+import java.util.UUID;
+
import junit.framework.TestCase;
import org.jboss.security.xacml.interfaces.RequestContext;
import org.jboss.security.xacml.saml.integration.opensaml.core.JBossXACMLSAMLConfiguration;
import org.jboss.security.xacml.saml.integration.opensaml.request.JBossSAMLRequest;
import org.jboss.security.xacml.saml.integration.opensaml.types.XACMLAuthzDecisionQueryType;
+import org.jboss.security.xacml.saml.integration.opensaml.util.SAML2Util;
+import org.joda.time.DateTime;
import org.opensaml.common.SAMLObject;
+import org.opensaml.saml2.core.RequestAbstractType;
/**
* Tests for SAMLRequest read
@@ -37,6 +42,8 @@
*/
public class SAMLRequestUnitTestCase extends TestCase
{
+ private SAML2Util util = new SAML2Util();
+
protected void setUp() throws Exception
{
JBossXACMLSAMLConfiguration.initialize();
@@ -51,5 +58,19 @@
RequestContext requestContext = xacmlRequest.getRequest();
assertNotNull("XACML Request Context is not null", requestContext);
}
+
+ public void testSAMLRequestConstruction()
+ {
+ DateTime issueInstant = util.getIssueInstant();
+ String requestId = UUID.randomUUID().toString();
+ JBossSAMLRequest samlRequest = new JBossSAMLRequest();
+ Object request = samlRequest.buildRequest(issueInstant, requestId, "anil");
+ assertTrue(request instanceof RequestAbstractType);
+
+ RequestAbstractType rat = (RequestAbstractType) request;
+ assertEquals(issueInstant,rat.getIssueInstant());
+ assertEquals(requestId,rat.getID());
+ assertEquals("anil", rat.getIssuer().getValue());
+ }
-}
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list