Author: anil.saldhana(a)jboss.com
Date: 2010-12-16 18:00:13 -0500 (Thu, 16 Dec 2010)
New Revision: 606
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/xacml/
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/xacml/SAMLXACMLRequestParser.java
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/util/SAMLXACMLUnitTestCase.java
Log:
change ctr of RequestAbstractType and bring in xacml processing for saml profile
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLAuthNRequestParser.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -112,7 +112,8 @@
*/
private AuthnRequestType parseBaseAttributes( StartElement startElement ) throws
ParsingException
{
- AuthnRequestType authnRequest = new AuthnRequestType();
+ super.parseRequiredAttributes(startElement);
+ AuthnRequestType authnRequest = new AuthnRequestType( id, version, issueInstant );
//Let us get the attributes
super.parseBaseAttributes(startElement, authnRequest );
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLParser.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -30,6 +30,7 @@
import org.picketlink.identity.federation.core.parsers.AbstractParser;
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import
org.picketlink.identity.federation.core.parsers.saml.metadata.SAMLEntityDescriptorParser;
+import
org.picketlink.identity.federation.core.parsers.saml.xacml.SAMLXACMLRequestParser;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
@@ -88,6 +89,23 @@
SAMLResponseParser responseParser = new SAMLResponseParser();
return responseParser.parse( xmlEventReader );
}
+
+ else if( JBossSAMLURIConstants.PROTOCOL_NSURI.get().equals( nsURI )
&&
+ JBossSAMLConstants.REQUEST_ABSTRACT.get().equals(
startElementName.getLocalPart() ))
+ {
+ String xsiTypeValue = StaxParserUtil.getXSITypeValue(startElement);
+ if( xsiTypeValue.contains(
JBossSAMLConstants.XACML_AUTHZ_DECISION_QUERY_TYPE.get() ))
+ {
+ SAMLXACMLRequestParser samlXacmlParser = new SAMLXACMLRequestParser();
+ return samlXacmlParser.parse(xmlEventReader);
+ }
+ throw new RuntimeException( "Unknown xsi:type=" + xsiTypeValue
);
+ }
+ else if( JBossSAMLConstants.XACML_AUTHZ_DECISION_QUERY.get().equals(
localPart ) )
+ {
+ SAMLXACMLRequestParser samlXacmlParser = new SAMLXACMLRequestParser();
+ return samlXacmlParser.parse(xmlEventReader);
+ }
else if( JBossSAMLConstants.ENTITY_DESCRIPTOR.get().equals( localPart ))
{
SAMLEntityDescriptorParser entityDescriptorParser = new
SAMLEntityDescriptorParser();
@@ -97,8 +115,7 @@
{
SAMLAssertionParser assertionParser = new SAMLAssertionParser();
return assertionParser.parse( xmlEventReader );
- }
-
+ }
else throw new RuntimeException( "Unknown Tag:" + elementName );
}
else
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLRequestAbstractParser.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -21,6 +21,7 @@
*/
package org.picketlink.identity.federation.core.parsers.saml;
+import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.Attribute;
@@ -41,33 +42,41 @@
*/
public abstract class SAMLRequestAbstractParser
{
- /**
- * Parse the attributes that are common to all SAML Request Types
- * @param startElement
- * @param request
- * @throws ParsingException
- */
- protected void parseBaseAttributes( StartElement startElement , RequestAbstractType
request ) throws ParsingException
+ protected String id;
+ protected String version;
+ protected XMLGregorianCalendar issueInstant;
+
+ protected void parseRequiredAttributes( StartElement startElement ) throws
ParsingException
{
Attribute idAttr = startElement.getAttributeByName( new QName( "ID" ));
if( idAttr == null )
throw new RuntimeException( "ID attribute is missing" );
- request.setID( StaxParserUtil.getAttributeValue( idAttr ));
- Attribute version = startElement.getAttributeByName( new QName( "Version"
));
- if( version == null )
+ id = StaxParserUtil.getAttributeValue( idAttr );
+
+ Attribute versionAttr = startElement.getAttributeByName( new QName(
"Version" ));
+ if( versionAttr == null )
throw new RuntimeException( "Version attribute required in Request"
);
- request.setVersion( StaxParserUtil.getAttributeValue( version ));
+ version = StaxParserUtil.getAttributeValue( versionAttr );
- Attribute issueInstant = startElement.getAttributeByName( new QName(
"IssueInstant" ));
- if( issueInstant == null )
+ Attribute issueInstantAttr = startElement.getAttributeByName( new QName(
"IssueInstant" ));
+ if( issueInstantAttr == null )
throw new RuntimeException( "IssueInstant attribute required in
Request" );
- request.setIssueInstant( XMLTimeUtil.parse( StaxParserUtil.getAttributeValue(
issueInstant )));
+ issueInstant = XMLTimeUtil.parse( StaxParserUtil.getAttributeValue(
issueInstantAttr ));
+ }
+
+ /**
+ * Parse the attributes that are common to all SAML Request Types
+ * @param startElement
+ * @param request
+ * @throws ParsingException
+ */
+ protected void parseBaseAttributes( StartElement startElement, RequestAbstractType
request ) throws ParsingException
+ {
+ Attribute destinationAttr = startElement.getAttributeByName( new QName(
"Destination" ));
+ if( destinationAttr != null )
+ request.setDestination( NetworkUtil.createURI( StaxParserUtil.getAttributeValue(
destinationAttr ) ));
- Attribute destination = startElement.getAttributeByName( new QName(
"Destination" ));
- if( destination != null )
- request.setDestination( NetworkUtil.createURI( StaxParserUtil.getAttributeValue(
destination )));
-
Attribute consent = startElement.getAttributeByName( new QName( "Consent"
));
if( consent != null )
request.setConsent( StaxParserUtil.getAttributeValue( consent ));
@@ -87,8 +96,7 @@
}
else if( JBossSAMLConstants.SIGNATURE.get().equals( elementName ))
{
- request.setSignature( StaxParserUtil.getDOMElement(xmlEventReader) );
- //StaxParserUtil.bypassElementBlock(xmlEventReader,
JBossSAMLConstants.SIGNATURE.get() );
+ request.setSignature( StaxParserUtil.getDOMElement(xmlEventReader) );
}
}
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLSloRequestParser.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -90,7 +90,8 @@
*/
private LogoutRequestType parseBaseAttributes( StartElement startElement ) throws
ParsingException
{
- LogoutRequestType logoutRequest = new LogoutRequestType();
+ super.parseRequiredAttributes(startElement);
+ LogoutRequestType logoutRequest = new LogoutRequestType( id, version, issueInstant
);
//Let us get the attributes
super.parseBaseAttributes(startElement, logoutRequest );
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/xacml/SAMLXACMLRequestParser.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/xacml/SAMLXACMLRequestParser.java
(rev 0)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/xacml/SAMLXACMLRequestParser.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -0,0 +1,134 @@
+/*
+ * 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.picketlink.identity.federation.core.parsers.saml.xacml;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jboss.security.xacml.core.model.context.RequestType;
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLRequestAbstractParser;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
+import
org.picketlink.identity.federation.newmodel.saml.v2.profiles.xacml.protocol.XACMLAuthzDecisionQueryType;
+import org.w3c.dom.Element;
+
+/**
+ * Parse the XACML Elements as specified by the SAML-XACML Profile.
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Dec 16, 2010
+ */
+public class SAMLXACMLRequestParser extends SAMLRequestAbstractParser implements
ParserNamespaceSupport
+{
+ public Object parse( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+ String tag = StaxParserUtil.getStartElementName(startElement);
+ if( tag.equals( JBossSAMLConstants.REQUEST_ABSTRACT.get() ))
+ {
+ String xsiTypeValue = StaxParserUtil.getXSITypeValue(startElement);
+ if( xsiTypeValue.contains(
JBossSAMLConstants.XACML_AUTHZ_DECISION_QUERY_TYPE.get() ))
+ {
+ return parseXACMLAuthzDecisionQuery( startElement, xmlEventReader );
+ }
+ else throw new RuntimeException( "Unknown xsi:type=" + xsiTypeValue );
+ }
+ else if( tag.equals( JBossSAMLConstants.XACML_AUTHZ_DECISION_QUERY.get() ))
+ {
+ return parseXACMLAuthzDecisionQuery(startElement, xmlEventReader);
+ }
+
+ return null;
+ }
+
+ public boolean supports(QName qname)
+ {
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ private XACMLAuthzDecisionQueryType parseXACMLAuthzDecisionQuery( StartElement
startElement,
+ XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ super.parseRequiredAttributes( startElement );
+
+ XACMLAuthzDecisionQueryType xacmlQuery = new XACMLAuthzDecisionQueryType(id,
version, issueInstant );
+ super.parseBaseAttributes( startElement, xacmlQuery );
+
+ String inputContextOnly = StaxParserUtil.getAttributeValue(startElement,
JBossSAMLConstants.INPUT_CONTEXT_ONLY.get() );
+ if( inputContextOnly != null )
+ {
+ xacmlQuery.setInputContextOnly( Boolean.parseBoolean( inputContextOnly ));
+ }
+ String returnContext = StaxParserUtil.getAttributeValue(startElement,
JBossSAMLConstants.RETURN_CONTEXT.get() );
+ if( returnContext != null )
+ {
+ xacmlQuery.setReturnContext( Boolean.parseBoolean( returnContext ));
+ }
+
+ //Go thru the children
+ while( xmlEventReader.hasNext() )
+ {
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if( xmlEvent instanceof EndElement )
+ {
+ EndElement endElement = (EndElement) xmlEvent;
+ if( ! (StaxParserUtil.matches(endElement,
JBossSAMLConstants.REQUEST_ABSTRACT.get() )
+ || StaxParserUtil.matches(endElement,
JBossSAMLConstants.XACML_AUTHZ_DECISION_QUERY.get() ) ))
+ throw new ParsingException( "Expected endelement RequestAbstract or
XACMLAuthzDecisionQuery" );
+ break;
+ }
+ startElement = StaxParserUtil.peekNextStartElement( xmlEventReader );
+ super.parseCommonElements(startElement, xmlEventReader, xacmlQuery);
+ String tag = StaxParserUtil.getStartElementName(startElement);
+
+ if( tag.equals( JBossSAMLConstants.REQUEST.get() ))
+ {
+ Element xacmlRequest = StaxParserUtil.getDOMElement(xmlEventReader);
+ //xacml request
+ String xacmlPath = "org.jboss.security.xacml.core.model.context";
+ try
+ {
+ JAXBContext jaxb = JAXBContext.newInstance( xacmlPath );
+ Unmarshaller un = jaxb.createUnmarshaller();
+ un.setEventHandler(new
javax.xml.bind.helpers.DefaultValidationEventHandler());
+ JAXBElement<RequestType> jaxbRequestType =
(JAXBElement<RequestType>) un.unmarshal(
DocumentUtil.getNodeAsStream(xacmlRequest));
+ RequestType req = jaxbRequestType.getValue();
+ xacmlQuery.setRequest(req);
+ }
+ catch ( Exception e)
+ {
+ throw new ParsingException( e );
+ }
+ }
+ }
+ return xacmlQuery;
+ }
+}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -23,6 +23,7 @@
import java.io.InputStream;
+import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
@@ -37,6 +38,8 @@
import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
import org.picketlink.identity.federation.core.util.TransformerUtil;
import org.w3c.dom.Document;
@@ -80,6 +83,21 @@
}
/**
+ * Get the Attribute value
+ * @param startElement
+ * @param tag localpart of the qname of the attribute
+ * @return
+ */
+ public static String getAttributeValue( StartElement startElement, String tag )
+ {
+ String result = null;
+ Attribute attr = startElement.getAttributeByName( new QName( tag ));
+ if( attr != null )
+ result = getAttributeValue(attr);
+ return result;
+ }
+
+ /**
* Given that the {@code XMLEventReader} is in {@code
XMLStreamConstants.START_ELEMENT}
* mode, we parse into a DOM Element
* @param xmlEventReader
@@ -271,6 +289,21 @@
}
/**
+ * Given a start element, obtain the xsi:type defined
+ * @param startElement
+ * @return
+ * @throws RuntimeException if xsi:type is missing
+ */
+ public static String getXSITypeValue( StartElement startElement )
+ {
+ Attribute xsiType = startElement.getAttributeByName( new QName(
JBossSAMLURIConstants.XSI_NSURI.get(),
+ JBossSAMLConstants.TYPE.get() ));
+ if( xsiType == null )
+ throw new RuntimeException( "xsi:type expected" );
+ return StaxParserUtil.getAttributeValue( xsiType );
+ }
+
+ /**
* Return whether the next event is going to be text
* @param xmlEventReader
* @return
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -61,6 +61,7 @@
ID( "ID" ),
IDP_SSO_DESCRIPTOR( "IDPSSODescriptor" ),
INDEX( "index" ),
+ INPUT_CONTEXT_ONLY( "InputContextOnly" ),
IN_RESPONSE_TO( "InResponseTo" ),
ISDEFAULT( "isDefault" ),
ISSUE_INSTANT( "IssueInstant" ),
@@ -88,8 +89,11 @@
PROTOCOL_SUPPORT_ENUMERATION( "protocolSupportEnumeration" ),
REQUESTED_AUTHN_CONTEXT( "RequestedAuthnContext" ),
RECIPIENT( "Recipient" ),
+ REQUEST( "Request" ),
+ REQUEST_ABSTRACT( "RequestAbstract" ),
RESPONSE( "Response" ),
RESPONSE_LOCATION( "ResponseLocation" ),
+ RETURN_CONTEXT( "ReturnContext" ),
SESSION_INDEX( "SessionIndex" ),
SP_PROVIDED_ID( "SPProvidedID" ),
SP_NAME_QUALIFIER( "SPNameQualifier" ),
@@ -106,10 +110,13 @@
SUBJECT( "Subject" ),
SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
SUBJECT_CONFIRMATION_DATA( "SubjectConfirmationData" ),
+ TYPE( "type" ),
VALUE( "Value" ),
VERSION( "Version" ),
VERSION_2_0("2.0"),
WANT_AUTHN_REQUESTS_SIGNED( "WantAuthnRequestsSigned" ),
+ XACML_AUTHZ_DECISION_QUERY( "XACMLAuthzDecisionQuery" ),
+ XACML_AUTHZ_DECISION_QUERY_TYPE( "XACMLAuthzDecisionQueryType" ),
HTTP_POST_BINDING("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
private String val;
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -58,16 +58,14 @@
{
XMLGregorianCalendar issueInstant = XMLTimeUtil.getIssueInstant();
- AuthnRequestType authnRequest = new AuthnRequestType();
- authnRequest.setID(id);
- authnRequest.setVersion(JBossSAMLConstants.VERSION_2_0.get());
+ String version = JBossSAMLConstants.VERSION_2_0.get();
+ AuthnRequestType authnRequest = new AuthnRequestType( id, version, issueInstant );
authnRequest.setAssertionConsumerServiceURL( NetworkUtil.createURI(
assertionConsumerURL ));
authnRequest.setProtocolBinding( NetworkUtil.createURI(
JBossSAMLConstants.HTTP_POST_BINDING.get() ));
if( destination != null )
{
authnRequest.setDestination( NetworkUtil.createURI( destination ));
- }
- authnRequest.setIssueInstant(issueInstant);
+ }
//Create an issuer
NameIDType issuer = new NameIDType();
Modified:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/util/SAMLXACMLUnitTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/util/SAMLXACMLUnitTestCase.java 2010-12-16
21:30:09 UTC (rev 605)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/util/SAMLXACMLUnitTestCase.java 2010-12-16
23:00:13 UTC (rev 606)
@@ -21,86 +21,63 @@
*/
package org.picketlink.test.identity.federation.core.util;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.InputStream;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.Unmarshaller;
-
-import junit.framework.TestCase;
-
-import
org.picketlink.identity.federation.saml.v2.profiles.xacml.protocol.XACMLAuthzDecisionQueryType;
import org.jboss.security.xacml.core.model.context.RequestType;
+import org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import
org.picketlink.identity.federation.newmodel.saml.v2.profiles.xacml.protocol.XACMLAuthzDecisionQueryType;
+import org.picketlink.identity.federation.newmodel.saml.v2.protocol.RequestAbstractType;
/**
* Read a SAML-XACML request
* @author Anil.Saldhana(a)redhat.com
* @since Jan 8, 2009
*/
-public class SAMLXACMLUnitTestCase extends TestCase
+public class SAMLXACMLUnitTestCase
{
- @SuppressWarnings("unchecked")
/**
* Usage of samlp with xsi-type
*/
+ @Test
public void testSAML_XACML_Read() throws Exception
{
- throw new RuntimeException();
- /*String resourceName = "saml-xacml/saml-xacml-request.xml";
- String samlPath = "org.picketlink.identity.federation.saml.v2.protocol";
- String xacmlPath = "org.jboss.security.xacml.core.model.context";
- String xsAssert =
"org.picketlink.identity.federation.saml.v2.profiles.xacml.assertion";
- String xsProto =
"org.picketlink.identity.federation.saml.v2.profiles.xacml.protocol";
- String path = samlPath + ":" + xacmlPath + ":" + xsAssert +
":" + xsProto;
-
- JAXBContext jaxb = JAXBContext.newInstance(path);
- Unmarshaller un = jaxb.createUnmarshaller();
-
+ String resourceName = "saml-xacml/saml-xacml-request.xml";
+
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream is = tcl.getResourceAsStream(resourceName);
-
- un.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
-
- JAXBElement<RequestAbstractType> jaxbRequestType =
(JAXBElement<RequestAbstractType>) un.unmarshal(is);
- RequestAbstractType req = jaxbRequestType.getValue();
+
+ SAMLParser parser = new SAMLParser();
+ RequestAbstractType req = (RequestAbstractType) parser.parse( is );
assertNotNull(req);
- assertTrue( req instanceof XACMLAuthzDecisionQueryType);
+ assertTrue( req instanceof XACMLAuthzDecisionQueryType );
XACMLAuthzDecisionQueryType xadqt = (XACMLAuthzDecisionQueryType) req;
RequestType requestType = xadqt.getRequest();
- assertNotNull(requestType);*/
+ assertNotNull(requestType);
}
- @SuppressWarnings("unchecked")
/**
* Usage of xacml-samlp
*/
+ @Test
public void testSAML_XACML_Read_2() throws Exception
- {
- throw new RuntimeException();
+ {
+ String resourceName = "saml-xacml/saml-xacml-request-2.xml";
- /*String resourceName = "saml-xacml/saml-xacml-request-2.xml";
- String samlPath = "org.picketlink.identity.federation.saml.v2.protocol";
- String xacmlPath = "org.jboss.security.xacml.core.model.context";
- String xsAssert =
"org.picketlink.identity.federation.saml.v2.profiles.xacml.assertion";
- String xsProto =
"org.picketlink.identity.federation.saml.v2.profiles.xacml.protocol";
- String path = samlPath + ":" + xacmlPath + ":" + xsAssert +
":" + xsProto;
-
- JAXBContext jaxb = JAXBContext.newInstance(path);
- Unmarshaller un = jaxb.createUnmarshaller();
-
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream is = tcl.getResourceAsStream(resourceName);
- un.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
-
- JAXBElement<RequestAbstractType> jaxbRequestType =
(JAXBElement<RequestAbstractType>) un.unmarshal(is);
- RequestAbstractType req = jaxbRequestType.getValue();
+ SAMLParser parser = new SAMLParser();
+ RequestAbstractType req = (RequestAbstractType) parser.parse( is );
assertNotNull(req);
- assertTrue( req instanceof XACMLAuthzDecisionQueryType);
+ assertTrue( req instanceof XACMLAuthzDecisionQueryType );
XACMLAuthzDecisionQueryType xadqt = (XACMLAuthzDecisionQueryType) req;
RequestType requestType = xadqt.getRequest();
- assertNotNull(requestType);*/
+ assertNotNull(requestType);
}
}
\ No newline at end of file