Picketlink SVN: r510 - in federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core: util and 1 other directory.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-25 12:46:42 -0400 (Mon, 25 Oct 2010)
New Revision: 510
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/SecurityActions.java
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java
Log:
PLFED-109:use a custom JAXP transformer
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/SecurityActions.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/SecurityActions.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/SecurityActions.java 2010-10-25 16:46:42 UTC (rev 510)
@@ -0,0 +1,50 @@
+/*
+ * 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.wst;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 25, 2010
+ */
+public class SecurityActions
+{
+ /**
+ * Get a system property
+ * @param key
+ * @param defaultValue
+ * @return
+ */
+ static String getSystemProperty( final String key, final String defaultValue )
+ {
+ return AccessController.doPrivileged( new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty( key, defaultValue );
+ }
+ } );
+ }
+}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-25 12:58:51 UTC (rev 509)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-25 16:46:42 UTC (rev 510)
@@ -23,23 +23,25 @@
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Iterator;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.EndElement;
-import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stax.StAXSource;
import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
-import org.picketlink.identity.federation.core.exceptions.ProcessingException;
import org.picketlink.identity.federation.core.parsers.ParserController;
import org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport;
import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
+import org.picketlink.identity.federation.core.util.TransformerUtil;
import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken;
import org.picketlink.identity.federation.ws.policy.AppliesTo;
@@ -50,6 +52,7 @@
import org.picketlink.identity.federation.ws.trust.RenewTargetType;
import org.picketlink.identity.federation.ws.trust.UseKeyType;
import org.picketlink.identity.federation.ws.trust.ValidateTargetType;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
@@ -61,21 +64,23 @@
{
public static final String X509CERTIFICATE = "X509Certificate";
public static final String KEYVALUE = "KeyValue";
-
+
+ public static final String JDK_TRANSFORMER_PROPERTY = "picketlink.jdk.transformer";
+
/**
* @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
*/
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
- {
+ {
StartElement startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
-
+
RequestSecurityToken requestToken = new RequestSecurityToken();
-
+
QName contextQName = new QName( "", WSTrustConstants.RST_CONTEXT );
Attribute contextAttribute = startElement.getAttributeByName( contextQName );
String contextValue = StaxParserUtil.getAttributeValue( contextAttribute );
requestToken.setContext( contextValue );
-
+
while( xmlEventReader.hasNext() )
{
XMLEvent xmlEvent = StaxParserUtil.peek( xmlEventReader );
@@ -89,31 +94,31 @@
if( endElementTag.equals( WSTrustConstants.RST ) )
break;
}
-
+
try
{
StartElement subEvent = StaxParserUtil.peekNextStartElement( xmlEventReader );
if( subEvent == null )
break;
-
+
String tag = StaxParserUtil.getStartElementName( subEvent );
if( tag.equals( WSTrustConstants.REQUEST_TYPE ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
-
+
if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
throw new ParsingException( "request type is expected ahead" );
-
+
String value = StaxParserUtil.getElementText(xmlEventReader);
requestToken.setRequestType( new URI( value ));
}
else if( tag.equals( WSTrustConstants.TOKEN_TYPE ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
-
+
if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
throw new ParsingException( "token type is expected ahead" );
-
+
String value = StaxParserUtil.getElementText(xmlEventReader);
requestToken.setTokenType( new URI( value ));
}
@@ -130,7 +135,7 @@
else if( tag.equals( WSTrustConstants.VALIDATE_TARGET ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
-
+
WSTValidateTargetParser wstValidateTargetParser = new WSTValidateTargetParser();
ValidateTargetType validateTarget = (ValidateTargetType) wstValidateTargetParser.parse( xmlEventReader );
requestToken.setValidateTarget( validateTarget );
@@ -140,7 +145,7 @@
else if( tag.equals( WSTrustConstants.RENEW_TARGET ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
-
+
WSTRenewTargetParser wstValidateTargetParser = new WSTRenewTargetParser();
RenewTargetType validateTarget = (RenewTargetType) wstValidateTargetParser.parse( xmlEventReader );
requestToken.setRenewTarget( validateTarget );
@@ -150,7 +155,7 @@
else if( tag.equals( WSTrustConstants.On_BEHALF_OF ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
-
+
WSTrustOnBehalfOfParser wstOnBehalfOfParser = new WSTrustOnBehalfOfParser();
OnBehalfOfType onBehalfOf = (OnBehalfOfType) wstOnBehalfOfParser.parse(xmlEventReader);
requestToken.setOnBehalfOf(onBehalfOf);
@@ -162,7 +167,7 @@
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
throw new ParsingException( "key type is expected ahead" );
-
+
String keyType = StaxParserUtil.getElementText(xmlEventReader);
try
{
@@ -177,10 +182,10 @@
else if( tag.equals( WSTrustConstants.KEY_SIZE ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
-
+
if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
throw new ParsingException( "key size is expected ahead" );
-
+
String keySize = StaxParserUtil.getElementText(xmlEventReader);
try
{
@@ -201,10 +206,10 @@
BinarySecretType binarySecret = new BinarySecretType();
Attribute typeAttribute = subEvent.getAttributeByName( new QName( "", "Type" ));
binarySecret.setType( StaxParserUtil.getAttributeValue( typeAttribute ));
-
+
if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
throw new ParsingException( "binary secret value is expected ahead" );
-
+
binarySecret.setValue( StaxParserUtil.getElementText(xmlEventReader).getBytes() );
entropy.getAny().add( binarySecret );
}
@@ -215,22 +220,21 @@
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
UseKeyType useKeyType = new UseKeyType();
StaxParserUtil.validate( subEvent, WSTrustConstants.USE_KEY ) ;
-
- /**
- * There has to be a better way of parsing a sub section into a DOM element
- */
- subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+
+ //We peek at the next start element as the stax source has to be in the START_ELEMENT mode
+ subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
if( StaxParserUtil.matches(subEvent, X509CERTIFICATE ))
{
- Element domElement = getX509CertificateAsDomElement( subEvent, xmlEventReader );
+ Element domElement = this.getDOMElement(xmlEventReader);
+ //Element domElement = getX509CertificateAsDomElement( subEvent, xmlEventReader );
useKeyType.setAny( domElement );
requestToken.setUseKey( useKeyType );
}
else if( StaxParserUtil.matches(subEvent, KEYVALUE ))
{
- Element domElement = getKeyValueAsDomElement( subEvent, xmlEventReader );
-
+ //Element domElement = getKeyValueAsDomElement( subEvent, xmlEventReader );
+ Element domElement = this.getDOMElement(xmlEventReader);//
useKeyType.setAny( domElement );
requestToken.setUseKey( useKeyType );
}
@@ -242,7 +246,7 @@
ParserNamespaceSupport parser = ParserController.get( qname );
if( parser == null )
throw new RuntimeException( "Cannot parse " + qname );
-
+
Object parsedObject = parser.parse( xmlEventReader );
if( parsedObject instanceof AppliesTo )
{
@@ -255,10 +259,10 @@
throw new ParsingException( e );
}
}
-
+
return requestToken;
}
-
+
/**
* @see {@link ParserNamespaceSupport#supports(QName)}
*/
@@ -266,143 +270,52 @@
{
String nsURI = qname.getNamespaceURI();
String localPart = qname.getLocalPart();
-
+
return WSTrustConstants.BASE_NAMESPACE.equals( nsURI )
- && WSTrustConstants.RST.equals( localPart );
+ && WSTrustConstants.RST.equals( localPart );
}
-
-
- private Element getX509CertificateAsDomElement( StartElement subEvent, XMLEventReader xmlEventReader ) throws ParsingException
+
+ /**
+ * Given that the {@code XMLEventReader} is in {@code XMLStreamConstants.START_ELEMENT}
+ * mode, we parse into a DOM Element
+ * @param xmlEventReader
+ * @return
+ * @throws ParsingException
+ */
+ private Element getDOMElement( XMLEventReader xmlEventReader ) throws ParsingException
{
- StringBuilder builder = new StringBuilder();
-
- QName subEventName = subEvent.getName();
- String prefix = subEventName.getPrefix();
- String localPart = subEventName.getLocalPart();
-
- builder.append( "<" ).append( prefix ).append( ":").append( localPart );
-
- @SuppressWarnings("unchecked")
- Iterator<Attribute> iter = subEvent.getAttributes();
-
- while( iter != null && iter.hasNext() )
- {
- Attribute attr = iter.next();
- QName attrName = attr.getName();
- if( attrName.getNamespaceURI().equals( WSTrustConstants.DSIG_NS ) )
- {
- builder.append( " ").append( prefix ).append( ":" ).append( attrName.getLocalPart() );
- builder.append( "=" ).append( StaxParserUtil.getAttributeValue( attr ));
- }
- }
-
- @SuppressWarnings("unchecked")
- Iterator<Namespace> namespaces = subEvent.getNamespaces();
- while( namespaces != null && namespaces.hasNext() )
- {
- Namespace namespace = namespaces.next();
- builder.append( " ").append( namespace.toString() );
- }
- builder.append( ">" );
- builder.append( StaxParserUtil.getElementText(xmlEventReader) ); //We are at the end of tag
-
- builder.append( "</" ).append( prefix ).append( ":" ).append( localPart ).append( ">" );
- Element domElement = null;
+ Transformer transformer = null;
+
+ boolean useJDKTransformer = Boolean.parseBoolean( SecurityActions.getSystemProperty(JDK_TRANSFORMER_PROPERTY, "false" ));
+
try
- {
- domElement = DocumentUtil.getDocument( builder.toString() ).getDocumentElement() ;
- }
- catch (ConfigurationException e)
- {
- throw new ParsingException( e );
- }
- catch (ProcessingException e)
- {
- throw new ParsingException( e );
- }
-
- return domElement;
- }
-
-
- private Element getKeyValueAsDomElement( StartElement subEvent, XMLEventReader xmlEventReader ) throws ParsingException
- {
- StringBuilder builder = new StringBuilder();
-
- QName subEventName = subEvent.getName();
- String prefix = subEventName.getPrefix();
- String localPart = subEventName.getLocalPart();
-
- //ds:KeyValue
- builder.append( "<" ).append( prefix ).append( ":").append( localPart );
-
- @SuppressWarnings("unchecked")
- Iterator<Attribute> iter = subEvent.getAttributes();
-
- while( iter != null && iter.hasNext() )
- {
- Attribute attr = iter.next();
- QName attrName = attr.getName();
- if( attrName.getNamespaceURI().equals( WSTrustConstants.DSIG_NS ) )
+ {
+ if( useJDKTransformer )
{
- builder.append( " ").append( prefix ).append( ":" ).append( attrName.getLocalPart() );
- builder.append( "=" ).append( StaxParserUtil.getAttributeValue( attr ));
+ transformer = TransformerUtil.getTransformer();
}
- }
-
- @SuppressWarnings("unchecked")
- Iterator<Namespace> namespaces = subEvent.getNamespaces();
- while( namespaces != null && namespaces.hasNext() )
- {
- Namespace namespace = namespaces.next();
- builder.append( " ").append( namespace.toString() );
- }
- builder.append( ">" );
- subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- StaxParserUtil.validate( subEvent, "RSAKeyValue" );
- builder.append( "<") .append( prefix) .append( ":" ).append( "RSAKeyValue>" );
-
- subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- StaxParserUtil.validate( subEvent, "Modulus" );
- builder.append( "<") .append( prefix) .append( ":" ).append( "Modulus>" );
-
- builder.append( StaxParserUtil.getElementText(xmlEventReader) ); //We are at the end of tag
-
- builder.append( "</" ).append( prefix ).append( ":" ).append( "Modulus" ).append( ">" );
-
+ else
+ {
+ transformer = TransformerUtil.getStaxSourceToDomResultTransformer();
+ }
- subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- StaxParserUtil.validate( subEvent, "Exponent" );
+ Document resultDocument = DocumentUtil.createDocument();
+ DOMResult domResult = new DOMResult( resultDocument );
+
+ StAXSource source = new StAXSource( xmlEventReader );
- builder.append( "<") .append( prefix) .append( ":" ).append( "Exponent>" );
-
- builder.append( StaxParserUtil.getElementText(xmlEventReader) ); //We are at the end of tag
-
- builder.append( "</" ).append( prefix ).append( ":" ).append( "Exponent" ).append( ">" );
-
- EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement, "RSAKeyValue" );
- builder.append( "</" ).append( prefix ).append( ":" ).append( "RSAKeyValue" ).append( ">" );
-
- endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement, KEYVALUE );
- builder.append( "</" ).append( prefix ).append( ":" ).append( KEYVALUE ).append( ">" );
-
-
- Element domElement = null;
- try
- {
- domElement = DocumentUtil.getDocument( builder.toString() ).getDocumentElement() ;
+ TransformerUtil.transform( transformer, source, domResult );
+
+ Document doc = ( Document ) domResult.getNode();
+ return doc.getDocumentElement();
}
- catch (ConfigurationException e)
+ catch ( ConfigurationException e )
{
throw new ParsingException( e );
}
- catch (ProcessingException e)
+ catch ( XMLStreamException e )
{
throw new ParsingException( e );
}
-
- return domElement;
- }
+ }
}
\ No newline at end of file
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java 2010-10-25 12:58:51 UTC (rev 509)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java 2010-10-25 16:46:42 UTC (rev 510)
@@ -58,6 +58,11 @@
*/
public class TransformerUtil
{
+ /**
+ * Get the Default Transformer
+ * @return
+ * @throws ConfigurationException
+ */
public static Transformer getTransformer() throws ConfigurationException
{
Transformer transformer;
@@ -78,10 +83,37 @@
return transformer;
}
+ /**
+ * Get the Custom Stax Source to DOM result transformer that has been written
+ * to get over the JDK transformer bugs (JDK6) as well as the issue of Xalan
+ * installing its Transformer (which does not support stax).
+ *
+ * @return
+ * @throws ConfigurationException
+ */
public static Transformer getStaxSourceToDomResultTransformer() throws ConfigurationException
{
return new PicketLinkStaxToDOMTransformer();
}
+
+ /**
+ * Use the transformer to transform
+ * @param transformer
+ * @param stax
+ * @param result
+ * @throws ParsingException
+ */
+ public static void transform( Transformer transformer, StAXSource stax, DOMResult result ) throws ParsingException
+ {
+ try
+ {
+ transformer.transform( stax, result );
+ }
+ catch (TransformerException e)
+ {
+ throw new ParsingException( e );
+ }
+ }
/**
* Custom Project {@code Transformer} that can take in a {@link StAXSource}
@@ -137,7 +169,7 @@
Node el = doc.importNode(docStartElement, true);
Node top = stack.peek();
-
+
if( !holder.encounteredTextNode )
{
stack.push(el);
@@ -153,8 +185,11 @@
String endTag = StaxParserUtil.getEndElementName( endElement );
if( rootTag.equals( endTag ))
return; //We are done with the dom parsing
- else
+ else
+ {
+ if( !stack.isEmpty() )
stack.pop();
+ }
break;
}
}
13 years, 11 months
Picketlink SVN: r509 - in trust/trunk: jbossws and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: mmoyses
Date: 2010-10-25 08:58:51 -0400 (Mon, 25 Oct 2010)
New Revision: 509
Modified:
trust/trunk/jbossws/pom.xml
trust/trunk/parent/pom.xml
trust/trunk/pom.xml
Log:
preparing next release
Modified: trust/trunk/jbossws/pom.xml
===================================================================
--- trust/trunk/jbossws/pom.xml 2010-10-25 12:57:37 UTC (rev 508)
+++ trust/trunk/jbossws/pom.xml 2010-10-25 12:58:51 UTC (rev 509)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-trust-parent</artifactId>
- <version>1.0.0.CR3</version>
+ <version>1.0.0.CR4</version>
<relativePath>../parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Modified: trust/trunk/parent/pom.xml
===================================================================
--- trust/trunk/parent/pom.xml 2010-10-25 12:57:37 UTC (rev 508)
+++ trust/trunk/parent/pom.xml 2010-10-25 12:58:51 UTC (rev 509)
@@ -8,7 +8,7 @@
<groupId>org.picketlink</groupId>
<artifactId>picketlink-trust-parent</artifactId>
<packaging>pom</packaging>
- <version>1.0.0.CR3</version>
+ <version>1.0.0.CR4</version>
<name>PicketLink Trust - Parent</name>
<url>http://labs.jboss.org/portal/picketlink/</url>
<description>PicketLink Trust integrates PicketLink with external projects</description>
Modified: trust/trunk/pom.xml
===================================================================
--- trust/trunk/pom.xml 2010-10-25 12:57:37 UTC (rev 508)
+++ trust/trunk/pom.xml 2010-10-25 12:58:51 UTC (rev 509)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-trust-parent</artifactId>
- <version>1.0.0.CR3</version>
+ <version>1.0.0.CR4</version>
<relativePath>parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
13 years, 11 months
Picketlink SVN: r508 - trust/tags.
by picketlink-commits@lists.jboss.org
Author: mmoyses
Date: 2010-10-25 08:57:37 -0400 (Mon, 25 Oct 2010)
New Revision: 508
Added:
trust/tags/1.0.0.CR3/
Log:
releasing 1.0.0.CR3
Copied: trust/tags/1.0.0.CR3 (from rev 507, trust/trunk)
13 years, 11 months
Picketlink SVN: r507 - trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler.
by picketlink-commits@lists.jboss.org
Author: mmoyses
Date: 2010-10-25 08:56:33 -0400 (Mon, 25 Oct 2010)
New Revision: 507
Modified:
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java
Log:
fixing the way username is retrieved from assertion
Modified: trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java
===================================================================
--- trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java 2010-10-23 01:23:08 UTC (rev 506)
+++ trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/SAML2Handler.java 2010-10-25 12:56:33 UTC (rev 507)
@@ -41,6 +41,8 @@
import org.picketlink.trust.jbossws.Util;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* A SAMLv2 WS handler.
@@ -91,7 +93,7 @@
}
Element subject = Util.findElement(assertion, new QName(SAML2Constants.SAML2_ASSERTION_URI, "Subject"));
Element nameID = Util.findElement(subject, new QName(SAML2Constants.SAML2_ASSERTION_URI, "NameID"));
- String username = nameID.getTextContent();
+ String username = getUsername(nameID);
// set SecurityContext
Subject s = new Subject();
SecurityContext sc = SecurityActions.createSecurityContext(new PicketLinkPrincipal(username), credential, s);
@@ -152,5 +154,20 @@
Util.addNamespace(element, Constants.XML_ENCRYPTION_PREFIX, Constants.XML_SIGNATURE_NS);
return element;
}
+
+ private String getUsername(final Element nameID) {
+ String username = nameID.getNodeValue();
+ if (username == null) {
+ final NodeList childNodes = nameID.getChildNodes();
+ final int size = childNodes.getLength();
+ for (int i = 0; i < size; i++) {
+ final Node childNode = childNodes.item(i);
+ if (childNode.getNodeType() == Node.TEXT_NODE) {
+ username = childNode.getNodeValue();
+ }
+ }
+ }
+ return username;
+ }
}
13 years, 11 months
Picketlink SVN: r506 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-22 21:23:08 -0400 (Fri, 22 Oct 2010)
New Revision: 506
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java
Log:
minor
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java 2010-10-23 01:20:17 UTC (rev 505)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java 2010-10-23 01:23:08 UTC (rev 506)
@@ -199,8 +199,7 @@
@Override
public Properties getOutputProperties()
- {
- // TODO Auto-generated method stub
+ {
return null;
}
13 years, 11 months
Picketlink SVN: r505 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/util and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-22 21:20:17 -0400 (Fri, 22 Oct 2010)
New Revision: 505
Added:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/DOMTransformerTestCase.java
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/DocumentUtil.java
Log:
Stax source to DOM result transformer
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/DocumentUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/DocumentUtil.java 2010-10-23 01:19:39 UTC (rev 504)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/util/DocumentUtil.java 2010-10-23 01:20:17 UTC (rev 505)
@@ -33,13 +33,10 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
@@ -50,6 +47,7 @@
import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.util.TransformerUtil;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -230,7 +228,7 @@
Result streamResult = new StreamResult(sw);
// Write the DOM document to the stream
- Transformer xformer = getTransformer();
+ Transformer xformer = TransformerUtil.getTransformer();
try
{
xformer.transform(source, streamResult);
@@ -257,7 +255,7 @@
Result streamResult = new StreamResult(sw);
// Write the DOM document to the file
- Transformer xformer = getTransformer();
+ Transformer xformer = TransformerUtil.getTransformer();
try
{
xformer.transform(source, streamResult);
@@ -284,7 +282,7 @@
Result streamResult = new StreamResult(baos);
// Write the DOM document to the stream
- Transformer transformer = getTransformer();
+ Transformer transformer = TransformerUtil.getTransformer();
try
{
transformer.transform(source, streamResult);
@@ -314,7 +312,7 @@
Result streamResult = new StreamResult(baos);
// Write the DOM document to the stream
- Transformer transformer = getTransformer();
+ Transformer transformer = TransformerUtil.getTransformer();
try
{
transformer.transform(source, streamResult);
@@ -420,7 +418,7 @@
{
try
{
- Transformer transformer = getTransformer();
+ Transformer transformer = TransformerUtil.getTransformer();
DOMResult result = new DOMResult();
transformer.transform(source, result);
return result.getNode();
@@ -456,25 +454,5 @@
factory.setNamespaceAware(true);
factory.setXIncludeAware(true);
return factory;
- }
-
- private static Transformer getTransformer() throws ProcessingException, ConfigurationException
- {
- Transformer transformer;
- try
- {
- transformer = TransformerFactory.newInstance().newTransformer();
- }
- catch (TransformerConfigurationException e)
- {
- throw new ConfigurationException(e);
- }
- catch (TransformerFactoryConfigurationError e)
- {
- throw new ConfigurationException(e);
- }
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.setOutputProperty(OutputKeys.INDENT, "no");
- return transformer;
- }
+ }
}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/TransformerUtil.java 2010-10-23 01:20:17 UTC (rev 505)
@@ -0,0 +1,279 @@
+/*
+ * 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.util;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Stack;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stax.StAXSource;
+
+import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
+import org.picketlink.identity.federation.core.exceptions.ParsingException;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Utility to deal with JAXP Transformer
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 22, 2010
+ */
+public class TransformerUtil
+{
+ public static Transformer getTransformer() throws ConfigurationException
+ {
+ Transformer transformer;
+ try
+ {
+ transformer = TransformerFactory.newInstance().newTransformer();
+ }
+ catch (TransformerConfigurationException e)
+ {
+ throw new ConfigurationException(e);
+ }
+ catch (TransformerFactoryConfigurationError e)
+ {
+ throw new ConfigurationException(e);
+ }
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.setOutputProperty(OutputKeys.INDENT, "no");
+ return transformer;
+ }
+
+ public static Transformer getStaxSourceToDomResultTransformer() throws ConfigurationException
+ {
+ return new PicketLinkStaxToDOMTransformer();
+ }
+
+ /**
+ * Custom Project {@code Transformer} that can take in a {@link StAXSource}
+ * and transform into {@link DOMResult}
+ * @author anil
+ */
+ private static class PicketLinkStaxToDOMTransformer extends Transformer
+ {
+ @Override
+ public void transform(Source xmlSource, Result outputTarget) throws TransformerException
+ {
+ if( !( xmlSource instanceof StAXSource ))
+ throw new IllegalArgumentException( "xmlSource should be a stax source" );
+ if( outputTarget instanceof DOMResult == false )
+ throw new IllegalArgumentException( "outputTarget should be a dom result" );
+
+ String rootTag = null;
+
+ StAXSource staxSource = (StAXSource) xmlSource;
+ XMLEventReader xmlEventReader = staxSource.getXMLEventReader();
+ if( xmlEventReader == null )
+ throw new TransformerException( "The StaxSource is expected to be created using XMLEventReader" );
+
+ DOMResult domResult = (DOMResult) outputTarget;
+ Document doc = (Document) domResult.getNode();
+
+ Stack<Node> stack = new Stack<Node>();
+
+ try
+ {
+ XMLEvent xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
+ if( xmlEvent instanceof StartElement == false )
+ throw new TransformerException( "Expected StartElement " );
+
+ StartElement rootElement = (StartElement) xmlEvent;
+ rootTag = StaxParserUtil.getStartElementName( rootElement );
+ Element docRoot = handleStartElement(xmlEventReader, rootElement, new CustomHolder(doc, false) );
+ Node parent = (Element) doc.importNode(docRoot, true);
+ doc.appendChild( parent );
+
+ stack.push(parent);
+
+ while( xmlEventReader.hasNext() )
+ {
+ xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
+ int type = xmlEvent.getEventType();
+ switch( type )
+ {
+ case XMLEvent.START_ELEMENT:
+ StartElement startElement = (StartElement) xmlEvent;
+ CustomHolder holder = new CustomHolder(doc, false);
+ Element docStartElement = handleStartElement(xmlEventReader, startElement, holder );
+ Node el = doc.importNode(docStartElement, true);
+
+ Node top = stack.peek();
+
+ if( !holder.encounteredTextNode )
+ {
+ stack.push(el);
+ }
+
+ if( top == null )
+ doc.appendChild(el);
+ else
+ top.appendChild( el );
+ break;
+ case XMLEvent.END_ELEMENT:
+ EndElement endElement = (EndElement) xmlEvent;
+ String endTag = StaxParserUtil.getEndElementName( endElement );
+ if( rootTag.equals( endTag ))
+ return; //We are done with the dom parsing
+ else
+ stack.pop();
+ break;
+ }
+ }
+ }
+ catch (ParsingException e)
+ {
+ throw new TransformerException( e );
+ }
+ }
+
+ @Override
+ public void setParameter(String name, Object value)
+ {
+ }
+
+ @Override
+ public Object getParameter(String name)
+ {
+ return null;
+ }
+
+ @Override
+ public void clearParameters()
+ {
+ }
+
+ @Override
+ public void setURIResolver(URIResolver resolver)
+ {
+ }
+
+ @Override
+ public URIResolver getURIResolver()
+ {
+ return null;
+ }
+
+ @Override
+ public void setOutputProperties(Properties oformat)
+ {
+ }
+
+ @Override
+ public Properties getOutputProperties()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setOutputProperty(String name, String value) throws IllegalArgumentException
+ {
+ }
+
+ @Override
+ public String getOutputProperty(String name) throws IllegalArgumentException
+ {
+ return null;
+ }
+
+ @Override
+ public void setErrorListener(ErrorListener listener) throws IllegalArgumentException
+ {
+ }
+
+ @Override
+ public ErrorListener getErrorListener()
+ {
+ return null;
+ }
+
+ private Element handleStartElement( XMLEventReader xmlEventReader, StartElement startElement,CustomHolder holder) throws ParsingException
+ {
+ Document doc = holder.doc;
+
+ QName elementName = startElement.getName();
+ String ns = elementName.getNamespaceURI();
+ String prefix = elementName.getPrefix();
+ String localPart = elementName.getLocalPart();
+
+ String qual = prefix != null && prefix != "" ? prefix + ":" + localPart : localPart ;
+ Element el = doc.createElementNS( ns, qual );
+
+ //Look for attributes
+ @SuppressWarnings("unchecked")
+ Iterator<Attribute> attrs = startElement.getAttributes();
+ while( attrs != null && attrs.hasNext() )
+ {
+ Attribute attr = attrs.next();
+ QName attrName = attr.getName();
+ ns = attrName.getNamespaceURI();
+ qual = attrName.getPrefix() + ":" + attrName.getLocalPart();
+
+ doc.createAttributeNS( ns, qual );
+ el.setAttributeNS( ns, qual , attr.getValue() );
+ }
+
+ XMLEvent nextEvent = StaxParserUtil.peek(xmlEventReader);
+ if( nextEvent.getEventType() == XMLEvent.CHARACTERS )
+ {
+ holder.encounteredTextNode = true;
+ String text = StaxParserUtil.getElementText(xmlEventReader);
+ Node textNode = doc.createTextNode( text );
+ textNode = doc.importNode(textNode, true);
+ el.appendChild( textNode );
+ }
+ return el;
+ }
+
+ private class CustomHolder
+ {
+ public Document doc;
+ public boolean encounteredTextNode = false;
+
+ public CustomHolder( Document document, boolean bool )
+ {
+ this.doc = document;
+ this.encounteredTextNode = bool;
+ }
+ }
+ }
+}
\ No newline at end of file
Added: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/DOMTransformerTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/DOMTransformerTestCase.java (rev 0)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/DOMTransformerTestCase.java 2010-10-23 01:20:17 UTC (rev 505)
@@ -0,0 +1,83 @@
+/*
+ * 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.test.identity.federation.core.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stax.StAXSource;
+
+import org.junit.Test;
+import org.picketlink.identity.federation.core.parsers.util.StaxParserUtil;
+import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
+import org.picketlink.identity.federation.core.util.TransformerUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Parse an xml file partially using StAX and then use JAXP Transformer
+ * to parse a DOM Element and resume stax
+ *
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Oct 22, 2010
+ */
+public class DOMTransformerTestCase
+{
+ String xml = "<a xmlns=\'urn:a\'><b><c><d>SomeD</d></c></b></a>";
+
+ @Test
+ public void testDOMTransformer() throws Exception
+ {
+ ByteArrayInputStream bis = new ByteArrayInputStream( xml.getBytes() );
+ XMLEventReader xmlEventReader = StaxParserUtil.getXMLEventReader( bis );
+
+ StartElement a = StaxParserUtil.getNextStartElement( xmlEventReader );
+ StaxParserUtil.validate(a, "a" );
+
+ Document resultDocument = DocumentUtil.createDocument();
+ DOMResult domResult = new DOMResult( resultDocument );
+
+ //Let us parse <b><c><d> using transformer
+ StAXSource source = new StAXSource(xmlEventReader);
+
+ Transformer transformer = TransformerUtil.getStaxSourceToDomResultTransformer();
+ transformer.transform( source, domResult );
+
+ Document doc = (Document) domResult.getNode();
+ Element elem = doc.getDocumentElement();
+ assertEquals( "b", elem.getLocalName() );
+
+ XMLEvent xmlEvent = xmlEventReader.nextEvent();
+ assertTrue( xmlEvent instanceof EndElement );
+ StaxParserUtil.validate( (EndElement) xmlEvent, "a" );
+
+ System.out.println( DocumentUtil.asString( (Document) domResult.getNode() ));
+ }
+}
\ No newline at end of file
13 years, 11 months
Picketlink SVN: r504 - in federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers: wsa and 2 other directories.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-22 21:19:39 -0400 (Fri, 22 Oct 2010)
New Revision: 504
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/WSSecurityParser.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
Log:
add the text char check
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java 2010-10-23 01:17:02 UTC (rev 503)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/saml/SAMLConditionsParser.java 2010-10-23 01:19:39 UTC (rev 504)
@@ -163,6 +163,9 @@
if( !StaxParserUtil.matches(audienceElement, JBossSAMLConstants.AUDIENCE.get() ) )
break;
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "audienceValue is expected ahead" );
+
String audienceValue = StaxParserUtil.getElementText( xmlEventReader );
audience.getAudience().add( audienceValue );
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java 2010-10-23 01:17:02 UTC (rev 503)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsa/WSAddressingParser.java 2010-10-23 01:19:39 UTC (rev 504)
@@ -71,6 +71,10 @@
startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
StaxParserUtil.validate(startElement, ADDRESS );
+
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "endpointURI is expected ahead" );
+
String endpointURI = StaxParserUtil.getElementText( xmlEventReader );
AttributedURIType attributedURI = new AttributedURIType();
@@ -79,7 +83,8 @@
reference.setAddress(attributedURI);
//Lets get the end element
- EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
+ xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
+ EndElement endElement = (EndElement)xmlEvent;
StaxParserUtil.validate( endElement, ENDPOINT_REFERENCE );
return new ObjectFactory().createEndpointReference( reference );
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/WSSecurityParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/WSSecurityParser.java 2010-10-23 01:17:02 UTC (rev 503)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wsse/WSSecurityParser.java 2010-10-23 01:19:39 UTC (rev 504)
@@ -80,6 +80,10 @@
userNameToken.setId( StaxParserUtil.getAttributeValue( idAttribute ));
startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
+
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "userName is expected ahead" );
+
String userName = StaxParserUtil.getElementText(xmlEventReader);
AttributedString attributedString = new AttributedString();
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-23 01:17:02 UTC (rev 503)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2010-10-23 01:19:39 UTC (rev 504)
@@ -101,6 +101,9 @@
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "request type is expected ahead" );
+
String value = StaxParserUtil.getElementText(xmlEventReader);
requestToken.setRequestType( new URI( value ));
}
@@ -108,6 +111,9 @@
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "token type is expected ahead" );
+
String value = StaxParserUtil.getElementText(xmlEventReader);
requestToken.setTokenType( new URI( value ));
}
@@ -154,6 +160,9 @@
else if( tag.equals( WSTrustConstants.KEY_TYPE ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "key type is expected ahead" );
+
String keyType = StaxParserUtil.getElementText(xmlEventReader);
try
{
@@ -168,6 +177,10 @@
else if( tag.equals( WSTrustConstants.KEY_SIZE ))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "key size is expected ahead" );
+
String keySize = StaxParserUtil.getElementText(xmlEventReader);
try
{
@@ -188,6 +201,10 @@
BinarySecretType binarySecret = new BinarySecretType();
Attribute typeAttribute = subEvent.getAttributeByName( new QName( "", "Type" ));
binarySecret.setType( StaxParserUtil.getAttributeValue( typeAttribute ));
+
+ if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
+ throw new ParsingException( "binary secret value is expected ahead" );
+
binarySecret.setValue( StaxParserUtil.getElementText(xmlEventReader).getBytes() );
entropy.getAny().add( binarySecret );
}
13 years, 11 months
Picketlink SVN: r503 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-22 21:17:02 -0400 (Fri, 22 Oct 2010)
New Revision: 503
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java
Log:
add a text look ahead
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-10-23 01:14:53 UTC (rev 502)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/StaxParserUtil.java 2010-10-23 01:17:02 UTC (rev 503)
@@ -197,7 +197,19 @@
return trim( endElement.getName().getLocalPart() );
}
+ /**
+ * Return whether the next event is going to be text
+ * @param xmlEventReader
+ * @return
+ * @throws ParsingException
+ */
+ public static boolean hasTextAhead( XMLEventReader xmlEventReader ) throws ParsingException
+ {
+ XMLEvent event = peek( xmlEventReader );
+ return event.getEventType() == XMLEvent.CHARACTERS;
+ }
+
/**
* Match that the start element with the expected tag
* @param startElement
13 years, 11 months
Picketlink SVN: r502 - federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers.
by picketlink-commits@lists.jboss.org
Author: anil.saldhana(a)jboss.com
Date: 2010-10-22 21:14:53 -0400 (Fri, 22 Oct 2010)
New Revision: 502
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java
Log:
the event filter should return CharacterEvent also
Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java 2010-10-21 14:12:51 UTC (rev 501)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/AbstractParser.java 2010-10-23 01:14:53 UTC (rev 502)
@@ -27,6 +27,7 @@
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Characters;
import javax.xml.stream.events.XMLEvent;
import org.picketlink.identity.federation.core.exceptions.ParsingException;
@@ -53,7 +54,7 @@
throw new IllegalArgumentException( " Input Stream is null " );
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
- //XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(xmlSource);
+
XMLEventReader xmlEventReader = StaxParserUtil.getXMLEventReader( configStream );
try
@@ -62,8 +63,24 @@
{
public boolean accept(XMLEvent xmlEvent)
{
- return xmlEvent.isStartElement() || xmlEvent.isEndElement();
+ //We are going to disregard characters that are new line and whitespace
+ if( xmlEvent.isCharacters() )
+ {
+ Characters chars = xmlEvent.asCharacters();
+ String data = chars.getData();
+ data = valid( data ) ? data.trim() : null;
+ return valid( data );
+ }
+ else
+ {
+ return xmlEvent.isStartElement() || xmlEvent.isEndElement();
+ }
}
+
+ private boolean valid( String str )
+ {
+ return str != null && str.length() > 0;
+ }
});
}
catch (XMLStreamException e)
13 years, 11 months
Picketlink SVN: r501 - in trust/trunk: jbossws and 1 other directories.
by picketlink-commits@lists.jboss.org
Author: mmoyses
Date: 2010-10-21 10:12:51 -0400 (Thu, 21 Oct 2010)
New Revision: 501
Modified:
trust/trunk/jbossws/pom.xml
trust/trunk/parent/pom.xml
trust/trunk/pom.xml
Log:
preparing next release
Modified: trust/trunk/jbossws/pom.xml
===================================================================
--- trust/trunk/jbossws/pom.xml 2010-10-21 14:02:52 UTC (rev 500)
+++ trust/trunk/jbossws/pom.xml 2010-10-21 14:12:51 UTC (rev 501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-trust-parent</artifactId>
- <version>1.0.0.CR2</version>
+ <version>1.0.0.CR3</version>
<relativePath>../parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Modified: trust/trunk/parent/pom.xml
===================================================================
--- trust/trunk/parent/pom.xml 2010-10-21 14:02:52 UTC (rev 500)
+++ trust/trunk/parent/pom.xml 2010-10-21 14:12:51 UTC (rev 501)
@@ -8,7 +8,7 @@
<groupId>org.picketlink</groupId>
<artifactId>picketlink-trust-parent</artifactId>
<packaging>pom</packaging>
- <version>1.0.0.CR2</version>
+ <version>1.0.0.CR3</version>
<name>PicketLink Trust - Parent</name>
<url>http://labs.jboss.org/portal/picketlink/</url>
<description>PicketLink Trust integrates PicketLink with external projects</description>
Modified: trust/trunk/pom.xml
===================================================================
--- trust/trunk/pom.xml 2010-10-21 14:02:52 UTC (rev 500)
+++ trust/trunk/pom.xml 2010-10-21 14:12:51 UTC (rev 501)
@@ -2,7 +2,7 @@
<parent>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-trust-parent</artifactId>
- <version>1.0.0.CR2</version>
+ <version>1.0.0.CR3</version>
<relativePath>parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
13 years, 11 months