Author: anil.saldhana(a)jboss.com
Date: 2011-05-17 00:58:37 -0400 (Tue, 17 May 2011)
New Revision: 941
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/wstrust/writers/WSTrustRequestWriter.java
Log:
parse/write RST Issuer
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 2011-05-17
04:57:46 UTC (rev 940)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/wst/WSTRequestSecurityTokenParser.java 2011-05-17
04:58:37 UTC (rev 941)
@@ -35,9 +35,12 @@
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.wsa.WSAddressingConstants;
import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
import org.picketlink.identity.federation.core.wstrust.wrappers.Lifetime;
import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken;
+import org.picketlink.identity.federation.ws.addressing.AttributedURIType;
+import org.picketlink.identity.federation.ws.addressing.EndpointReferenceType;
import org.picketlink.identity.federation.ws.policy.AppliesTo;
import org.picketlink.identity.federation.ws.trust.BinarySecretType;
import org.picketlink.identity.federation.ws.trust.CancelTargetType;
@@ -56,68 +59,69 @@
* @since Oct 11, 2010
*/
public class WSTRequestSecurityTokenParser implements ParserNamespaceSupport
-{
+{
public static final String X509CERTIFICATE = "X509Certificate";
+
public static final String KEYVALUE = "KeyValue";
/**
* @see {@link ParserNamespaceSupport#parse(XMLEventReader)}
*/
public Object parse(XMLEventReader xmlEventReader) throws ParsingException
- {
- StartElement startElement = StaxParserUtil.getNextStartElement( xmlEventReader );
+ {
+ StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
RequestSecurityToken requestToken = new RequestSecurityToken();
- QName contextQName = new QName( "", WSTrustConstants.RST_CONTEXT );
- Attribute contextAttribute = startElement.getAttributeByName( contextQName );
+ QName contextQName = new QName("", WSTrustConstants.RST_CONTEXT);
+ Attribute contextAttribute = startElement.getAttributeByName(contextQName);
if (contextAttribute != null)
{
String contextValue = StaxParserUtil.getAttributeValue(contextAttribute);
requestToken.setContext(contextValue);
}
- while( xmlEventReader.hasNext() )
+ while (xmlEventReader.hasNext())
{
- XMLEvent xmlEvent = StaxParserUtil.peek( xmlEventReader );
- if( xmlEvent == null )
+ XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
+ if (xmlEvent == null)
break;
- if( xmlEvent instanceof EndElement )
+ if (xmlEvent instanceof EndElement)
{
- xmlEvent = StaxParserUtil.getNextEvent( xmlEventReader );
+ xmlEvent = StaxParserUtil.getNextEvent(xmlEventReader);
EndElement endElement = (EndElement) xmlEvent;
- String endElementTag = StaxParserUtil.getEndElementName( endElement );
- if( endElementTag.equals( WSTrustConstants.RST ) )
+ String endElementTag = StaxParserUtil.getEndElementName(endElement);
+ if (endElementTag.equals(WSTrustConstants.RST))
break;
else
- throw new RuntimeException( "Unknown End Element:" +
endElementTag );
+ throw new RuntimeException("Unknown End Element:" +
endElementTag);
}
try
{
- StartElement subEvent = StaxParserUtil.peekNextStartElement( xmlEventReader
);
- if( subEvent == null )
+ StartElement subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
+ if (subEvent == null)
break;
- String tag = StaxParserUtil.getStartElementName( subEvent );
- if( tag.equals( WSTrustConstants.REQUEST_TYPE ))
- {
+ 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"
);
+ if (!StaxParserUtil.hasTextAhead(xmlEventReader))
+ throw new ParsingException("request type is expected
ahead");
String value = StaxParserUtil.getElementText(xmlEventReader);
- requestToken.setRequestType( new URI( value ));
+ requestToken.setRequestType(new URI(value));
}
- else if( tag.equals( WSTrustConstants.TOKEN_TYPE ))
+ else if (tag.equals(WSTrustConstants.TOKEN_TYPE))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
- throw new ParsingException( "token type is expected ahead"
);
+ if (!StaxParserUtil.hasTextAhead(xmlEventReader))
+ throw new ParsingException("token type is expected ahead");
String value = StaxParserUtil.getElementText(xmlEventReader);
- requestToken.setTokenType( new URI( value ));
+ requestToken.setTokenType(new URI(value));
}
else if (tag.equals(WSTrustConstants.LIFETIME))
{
@@ -150,145 +154,165 @@
EndElement lifeTimeElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
StaxParserUtil.validate(lifeTimeElement, WSTrustConstants.LIFETIME);
}
- else if( tag.equals( WSTrustConstants.CANCEL_TARGET ))
+ else if (tag.equals(WSTrustConstants.CANCEL_TARGET))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- StaxParserUtil.validate(subEvent, WSTrustConstants.CANCEL_TARGET );
+ StaxParserUtil.validate(subEvent, WSTrustConstants.CANCEL_TARGET);
WSTCancelTargetParser wstCancelTargetParser = new
WSTCancelTargetParser();
- CancelTargetType cancelTarget = (CancelTargetType)
wstCancelTargetParser.parse( xmlEventReader );
- requestToken.setCancelTarget( cancelTarget );
+ CancelTargetType cancelTarget = (CancelTargetType)
wstCancelTargetParser.parse(xmlEventReader);
+ requestToken.setCancelTarget(cancelTarget);
EndElement cancelTargetEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate( cancelTargetEndElement,
WSTrustConstants.CANCEL_TARGET ) ;
+ StaxParserUtil.validate(cancelTargetEndElement,
WSTrustConstants.CANCEL_TARGET);
}
- else if( tag.equals( WSTrustConstants.VALIDATE_TARGET ))
+ else if (tag.equals(WSTrustConstants.VALIDATE_TARGET))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
WSTValidateTargetParser wstValidateTargetParser = new
WSTValidateTargetParser();
- ValidateTargetType validateTarget = (ValidateTargetType)
wstValidateTargetParser.parse( xmlEventReader );
- requestToken.setValidateTarget( validateTarget );
+ ValidateTargetType validateTarget = (ValidateTargetType)
wstValidateTargetParser.parse(xmlEventReader);
+ requestToken.setValidateTarget(validateTarget);
EndElement validateTargetEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate( validateTargetEndElement,
WSTrustConstants.VALIDATE_TARGET ) ;
- }
- else if( tag.equals( WSTrustConstants.RENEW_TARGET ))
+ StaxParserUtil.validate(validateTargetEndElement,
WSTrustConstants.VALIDATE_TARGET);
+ }
+ else if (tag.equals(WSTrustConstants.RENEW_TARGET))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
WSTRenewTargetParser wstValidateTargetParser = new
WSTRenewTargetParser();
- RenewTargetType validateTarget = (RenewTargetType)
wstValidateTargetParser.parse( xmlEventReader );
- requestToken.setRenewTarget( validateTarget );
+ RenewTargetType validateTarget = (RenewTargetType)
wstValidateTargetParser.parse(xmlEventReader);
+ requestToken.setRenewTarget(validateTarget);
EndElement validateTargetEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate( validateTargetEndElement,
WSTrustConstants.RENEW_TARGET ) ;
- }
- else if( tag.equals( WSTrustConstants.ON_BEHALF_OF ))
+ StaxParserUtil.validate(validateTargetEndElement,
WSTrustConstants.RENEW_TARGET);
+ }
+ else if (tag.equals(WSTrustConstants.ON_BEHALF_OF))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- WSTrustOnBehalfOfParser wstOnBehalfOfParser = new
WSTrustOnBehalfOfParser();
- OnBehalfOfType onBehalfOf = (OnBehalfOfType)
wstOnBehalfOfParser.parse(xmlEventReader);
+ WSTrustOnBehalfOfParser wstOnBehalfOfParser = new
WSTrustOnBehalfOfParser();
+ OnBehalfOfType onBehalfOf = (OnBehalfOfType)
wstOnBehalfOfParser.parse(xmlEventReader);
requestToken.setOnBehalfOf(onBehalfOf);
EndElement onBehalfOfEndElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate( onBehalfOfEndElement,
WSTrustConstants.ON_BEHALF_OF ) ;
- }
- else if( tag.equals( WSTrustConstants.KEY_TYPE ))
+ StaxParserUtil.validate(onBehalfOfEndElement,
WSTrustConstants.ON_BEHALF_OF);
+ }
+ else if (tag.equals(WSTrustConstants.KEY_TYPE))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
- throw new ParsingException( "key type is expected ahead" );
+ if (!StaxParserUtil.hasTextAhead(xmlEventReader))
+ throw new ParsingException("key type is expected ahead");
String keyType = StaxParserUtil.getElementText(xmlEventReader);
try
{
- URI keyTypeURI = new URI( keyType );
- requestToken.setKeyType( keyTypeURI );
+ URI keyTypeURI = new URI(keyType);
+ requestToken.setKeyType(keyTypeURI);
}
- catch( URISyntaxException e )
+ catch (URISyntaxException e)
{
- throw new ParsingException( e );
- }
- }
- else if( tag.equals( WSTrustConstants.KEY_SIZE ))
+ throw new ParsingException(e);
+ }
+ }
+ else if (tag.equals(WSTrustConstants.KEY_SIZE))
{
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- if( !StaxParserUtil.hasTextAhead( xmlEventReader ))
- throw new ParsingException( "key size is expected ahead" );
+ if (!StaxParserUtil.hasTextAhead(xmlEventReader))
+ throw new ParsingException("key size is expected ahead");
String keySize = StaxParserUtil.getElementText(xmlEventReader);
try
- {
- requestToken.setKeySize(Long.parseLong( keySize ));
+ {
+ requestToken.setKeySize(Long.parseLong(keySize));
}
- catch( NumberFormatException e )
+ catch (NumberFormatException e)
{
- throw new ParsingException( e );
- }
- }
- else if( tag.equals( WSTrustConstants.ENTROPY ))
+ throw new ParsingException(e);
+ }
+ }
+ else if (tag.equals(WSTrustConstants.ENTROPY))
{
- subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
EntropyType entropy = new EntropyType();
subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- if( StaxParserUtil.matches(subEvent, WSTrustConstants.BINARY_SECRET ))
+ if (StaxParserUtil.matches(subEvent, WSTrustConstants.BINARY_SECRET))
{
BinarySecretType binarySecret = new BinarySecretType();
- Attribute typeAttribute = subEvent.getAttributeByName( new QName(
"", "Type" ));
- binarySecret.setType( StaxParserUtil.getAttributeValue( typeAttribute
));
+ 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" );
+ if (!StaxParserUtil.hasTextAhead(xmlEventReader))
+ throw new ParsingException("binary secret value is expected
ahead");
- binarySecret.setValue(
StaxParserUtil.getElementText(xmlEventReader).getBytes() );
- entropy.getAny().add( binarySecret );
+
binarySecret.setValue(StaxParserUtil.getElementText(xmlEventReader).getBytes());
+ entropy.getAny().add(binarySecret);
}
requestToken.setEntropy(entropy);
EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement, WSTrustConstants.ENTROPY );
+ StaxParserUtil.validate(endElement, WSTrustConstants.ENTROPY);
}
- else if( tag.equals( WSTrustConstants.USE_KEY ))
+ else if (tag.equals(WSTrustConstants.ISSUER))
{
- subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
- UseKeyType useKeyType = new UseKeyType();
- StaxParserUtil.validate( subEvent, WSTrustConstants.USE_KEY ) ;
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(subEvent, WSTrustConstants.ISSUER);
+ //Look for addressing
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ StaxParserUtil.validate(subEvent, WSAddressingConstants.ADDRESS);
+ String addressValue = StaxParserUtil.getElementText(xmlEventReader);
+
+ EndpointReferenceType endpointRef = new EndpointReferenceType();
+ AttributedURIType attrURI = new AttributedURIType();
+ attrURI.setValue(addressValue);
+ endpointRef.setAddress(new AttributedURIType());
+ requestToken.setIssuer(endpointRef);
+
+ EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
+ StaxParserUtil.validate(endElement, WSTrustConstants.ISSUER);
+ }
+ else if (tag.equals(WSTrustConstants.USE_KEY))
+ {
+ subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
+ UseKeyType useKeyType = new UseKeyType();
+ StaxParserUtil.validate(subEvent, WSTrustConstants.USE_KEY);
+
//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 ))
+ subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
+ if (StaxParserUtil.matches(subEvent, X509CERTIFICATE))
{
Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);
//Element domElement = getX509CertificateAsDomElement( subEvent,
xmlEventReader );
- useKeyType.setAny( domElement );
- requestToken.setUseKey( useKeyType );
- }
- else if( StaxParserUtil.matches(subEvent, KEYVALUE ))
+ useKeyType.setAny(domElement);
+ requestToken.setUseKey(useKeyType);
+ }
+ else if (StaxParserUtil.matches(subEvent, KEYVALUE))
{
//Element domElement = getKeyValueAsDomElement( subEvent,
xmlEventReader );
Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);//
- useKeyType.setAny( domElement );
- requestToken.setUseKey( useKeyType );
+ useKeyType.setAny(domElement);
+ requestToken.setUseKey(useKeyType);
EndElement endElement =
StaxParserUtil.getNextEndElement(xmlEventReader);
- StaxParserUtil.validate(endElement, WSTrustConstants.USE_KEY );
+ StaxParserUtil.validate(endElement, WSTrustConstants.USE_KEY);
}
- else throw new RuntimeException( "unsupported " +
StaxParserUtil.getStartElementName( subEvent ));
- }
+ else
+ throw new RuntimeException("unsupported " +
StaxParserUtil.getStartElementName(subEvent));
+ }
else
{
QName qname = subEvent.getName();
- ParserNamespaceSupport parser = ParserController.get( qname );
- if( parser == null )
- throw new RuntimeException( "Cannot parse " + qname );
+ ParserNamespaceSupport parser = ParserController.get(qname);
+ if (parser == null)
+ throw new RuntimeException("Cannot parse " + qname);
- Object parsedObject = parser.parse( xmlEventReader );
- if( parsedObject instanceof AppliesTo )
+ Object parsedObject = parser.parse(xmlEventReader);
+ if (parsedObject instanceof AppliesTo)
{
- requestToken.setAppliesTo( (AppliesTo) parsedObject );
+ requestToken.setAppliesTo((AppliesTo) parsedObject);
}
}
- }
+ }
catch (URISyntaxException e)
{
- throw new ParsingException( e );
- }
+ throw new ParsingException(e);
+ }
}
return requestToken;
@@ -298,11 +322,10 @@
* @see {@link ParserNamespaceSupport#supports(QName)}
*/
public boolean supports(QName qname)
- {
+ {
String nsURI = qname.getNamespaceURI();
String localPart = qname.getLocalPart();
- return WSTrustConstants.BASE_NAMESPACE.equals( nsURI )
- && WSTrustConstants.RST.equals( localPart );
- }
+ return WSTrustConstants.BASE_NAMESPACE.equals(nsURI) &&
WSTrustConstants.RST.equals(localPart);
+ }
}
\ No newline at end of file
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/writers/WSTrustRequestWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/writers/WSTrustRequestWriter.java 2011-05-17
04:57:46 UTC (rev 940)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/writers/WSTrustRequestWriter.java 2011-05-17
04:58:37 UTC (rev 941)
@@ -37,11 +37,13 @@
import org.picketlink.identity.federation.core.exceptions.ProcessingException;
import org.picketlink.identity.federation.core.saml.v2.writers.SAMLAssertionWriter;
import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.core.wsa.WSAddressingConstants;
import org.picketlink.identity.federation.core.wstrust.WSTrustConstants;
import org.picketlink.identity.federation.core.wstrust.wrappers.Lifetime;
import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken;
-import
org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityTokenCollection;
+import
org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityTokenCollection;
import org.picketlink.identity.federation.newmodel.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.ws.addressing.EndpointReferenceType;
import org.picketlink.identity.federation.ws.policy.AppliesTo;
import org.picketlink.identity.federation.ws.trust.BinarySecretType;
import org.picketlink.identity.federation.ws.trust.CancelTargetType;
@@ -62,8 +64,8 @@
*/
public class WSTrustRequestWriter
{
- private XMLStreamWriter writer;
-
+ private final XMLStreamWriter writer;
+
/**
* <p>
* Creates a {@code WSTrustRequestWriter} that writes {@code RequestSecurityToken}
instances to the specified
@@ -104,56 +106,68 @@
{
this.writer = writer;
}
-
+
/**
* Write the {@code RequestSecurityTokenCollection} into the {@code OutputStream}
* @param requestTokenCollection
* @param out
* @throws ProcessingException
*/
- public void write( RequestSecurityTokenCollection requestTokenCollection) throws
ProcessingException
+ public void write(RequestSecurityTokenCollection requestTokenCollection) throws
ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, RST_COLLECTION, BASE_NAMESPACE);
- StaxUtil.writeNameSpace( writer, PREFIX, BASE_NAMESPACE );
-
+ StaxUtil.writeStartElement(writer, PREFIX, RST_COLLECTION, BASE_NAMESPACE);
+ StaxUtil.writeNameSpace(writer, PREFIX, BASE_NAMESPACE);
+
List<RequestSecurityToken> tokenList =
requestTokenCollection.getRequestSecurityTokens();
- if( tokenList == null )
- throw new ProcessingException( "RST list is null" );
-
- for( RequestSecurityToken token: tokenList )
+ if (tokenList == null)
+ throw new ProcessingException("RST list is null");
+
+ for (RequestSecurityToken token : tokenList)
{
write(token);
}
- StaxUtil.writeEndElement( writer );
- StaxUtil.flush( writer );
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
-
+
/**
* Write the {@code RequestSecurityToken} into the {@code OutputStream}
* @param requestToken
* @param out
* @throws ProcessingException
*/
- public void write( RequestSecurityToken requestToken ) throws ProcessingException
+ public void write(RequestSecurityToken requestToken) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, RST, BASE_NAMESPACE);
- StaxUtil.writeNameSpace( writer, PREFIX, BASE_NAMESPACE );
+ StaxUtil.writeStartElement(writer, PREFIX, RST, BASE_NAMESPACE);
+ StaxUtil.writeNameSpace(writer, PREFIX, BASE_NAMESPACE);
String context = requestToken.getContext();
- StaxUtil.writeAttribute( writer, RST_CONTEXT, context );
-
+ StaxUtil.writeAttribute(writer, RST_CONTEXT, context);
+
URI requestType = requestToken.getRequestType();
- if( requestType != null )
+ if (requestType != null)
{
- writeRequestType( writer, requestType );
+ writeRequestType(writer, requestType);
}
-
+
URI tokenType = requestToken.getTokenType();
- if( tokenType != null )
+ if (tokenType != null)
{
- writeTokenType( writer, tokenType );
+ writeTokenType(writer, tokenType);
}
-
+
+ //Deal with Issuer
+ EndpointReferenceType endpoint = requestToken.getIssuer();
+ if (endpoint != null)
+ {
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.ISSUER,
BASE_NAMESPACE);
+ StaxUtil.writeStartElement(writer, WSAddressingConstants.WSA_PREFIX,
WSAddressingConstants.ADDRESS,
+ WSAddressingConstants.WSA_NS);
+ StaxUtil.writeCharacters(writer, endpoint.getAddress().getValue());
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.writeEndElement(writer);
+ }
+
// deal with the token lifetime.
if (requestToken.getLifetime() != null)
{
@@ -163,15 +177,15 @@
new WSSecurityWriter(this.writer).writeLifetime(lifetime.getCreated(),
lifetime.getExpires());
StaxUtil.writeEndElement(this.writer);
}
-
+
//Deal with AppliesTo
AppliesTo appliesTo = requestToken.getAppliesTo();
- if( appliesTo != null )
+ if (appliesTo != null)
{
WSPolicyWriter wsPolicyWriter = new WSPolicyWriter(this.writer);
- wsPolicyWriter.write( appliesTo );
+ wsPolicyWriter.write(appliesTo);
}
-
+
long keySize = requestToken.getKeySize();
if (keySize != 0)
{
@@ -179,52 +193,52 @@
StaxUtil.writeCharacters(writer, Long.toString(keySize));
StaxUtil.writeEndElement(writer);
}
-
+
URI keyType = requestToken.getKeyType();
- if( keyType != null )
+ if (keyType != null)
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.KEY_TYPE,
BASE_NAMESPACE);
- StaxUtil.writeCharacters(writer, keyType.toString() );
- StaxUtil.writeEndElement( writer );
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.KEY_TYPE,
BASE_NAMESPACE);
+ StaxUtil.writeCharacters(writer, keyType.toString());
+ StaxUtil.writeEndElement(writer);
}
EntropyType entropy = requestToken.getEntropy();
- if( entropy != null )
+ if (entropy != null)
{
- writeEntropyType(entropy);
+ writeEntropyType(entropy);
}
-
+
UseKeyType useKeyType = requestToken.getUseKey();
- if( useKeyType != null )
+ if (useKeyType != null)
{
writeUseKeyType(useKeyType);
}
-
+
OnBehalfOfType onBehalfOf = requestToken.getOnBehalfOf();
- if( onBehalfOf != null )
- {
- writeOnBehalfOfType(onBehalfOf);
+ if (onBehalfOf != null)
+ {
+ writeOnBehalfOfType(onBehalfOf);
}
-
+
ValidateTargetType validateTarget = requestToken.getValidateTarget();
- if( validateTarget != null )
+ if (validateTarget != null)
{
- writeValidateTargetType(validateTarget);
+ writeValidateTargetType(validateTarget);
}
-
+
CancelTargetType cancelTarget = requestToken.getCancelTarget();
- if( cancelTarget != null )
+ if (cancelTarget != null)
{
writeCancelTargetType(cancelTarget);
}
-
+
RenewTargetType renewTarget = requestToken.getRenewTarget();
if (renewTarget != null)
{
writeRenewTargetType(renewTarget);
}
-
- StaxUtil.writeEndElement( writer );
- StaxUtil.flush( writer );
+
+ StaxUtil.writeEndElement(writer);
+ StaxUtil.flush(writer);
}
/**
@@ -234,21 +248,21 @@
*/
private void writeEntropyType(EntropyType entropy) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.ENTROPY,
BASE_NAMESPACE);
-
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.ENTROPY,
BASE_NAMESPACE);
+
List<Object> entropyList = entropy.getAny();
- if( entropyList != null )
+ if (entropyList != null)
{
- for( Object entropyObj: entropyList )
+ for (Object entropyObj : entropyList)
{
- if( entropyObj instanceof BinarySecretType )
+ if (entropyObj instanceof BinarySecretType)
{
BinarySecretType binarySecret = (BinarySecretType) entropyObj;
- writeBinarySecretType( writer, binarySecret );
+ writeBinarySecretType(writer, binarySecret);
}
}
}
- StaxUtil.writeEndElement( writer );
+ StaxUtil.writeEndElement(writer);
}
/**
@@ -258,20 +272,20 @@
*/
private void writeUseKeyType(UseKeyType useKeyType) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.USE_KEY,
BASE_NAMESPACE);
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.USE_KEY,
BASE_NAMESPACE);
Object useKeyTypeValue = useKeyType.getAny();
- if( useKeyTypeValue instanceof Element )
+ if (useKeyTypeValue instanceof Element)
{
Element domElement = (Element) useKeyTypeValue;
- StaxUtil.writeDOMElement( writer, domElement );
+ StaxUtil.writeDOMElement(writer, domElement);
}
else if (useKeyTypeValue instanceof byte[])
{
byte[] certificate = (byte[]) useKeyTypeValue;
- StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX ,
WSTrustConstants.XMLDSig.X509CERT,
+ StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
WSTrustConstants.XMLDSig.X509CERT,
WSTrustConstants.DSIG_NS);
- StaxUtil.writeNameSpace( writer, WSTrustConstants.XMLDSig.DSIG_PREFIX ,
WSTrustConstants.DSIG_NS);
+ StaxUtil.writeNameSpace(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
WSTrustConstants.DSIG_NS);
StaxUtil.writeCharacters(writer, new String(certificate));
StaxUtil.writeEndElement(writer);
}
@@ -280,18 +294,19 @@
writeKeyValueType((KeyValueType) useKeyTypeValue);
}
else
- throw new RuntimeException( " Unknown use key type:" +
useKeyTypeValue.getClass().getName() );
-
+ throw new RuntimeException(" Unknown use key type:" +
useKeyTypeValue.getClass().getName());
+
StaxUtil.writeEndElement(writer);
}
private void writeKeyValueType(KeyValueType type) throws ProcessingException
{
- StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX ,
WSTrustConstants.XMLDSig.KEYVALUE, WSTrustConstants.DSIG_NS);
- StaxUtil.writeNameSpace(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX ,
WSTrustConstants.DSIG_NS);
+ StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
WSTrustConstants.XMLDSig.KEYVALUE,
+ WSTrustConstants.DSIG_NS);
+ StaxUtil.writeNameSpace(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX,
WSTrustConstants.DSIG_NS);
if (type.getContent().size() == 0)
throw new ProcessingException("KeyValueType must contain at least one
value");
-
+
for (Object obj : type.getContent())
{
if (obj instanceof RSAKeyValueType)
@@ -302,24 +317,25 @@
}
StaxUtil.writeEndElement(writer);
}
-
+
private void writeRSAKeyValueType(RSAKeyValueType type) throws ProcessingException
{
- StaxUtil.writeStartElement(writer, "dsig",
WSTrustConstants.XMLDSig.RSA_KEYVALUE , WSTrustConstants.DSIG_NS);
+ StaxUtil.writeStartElement(writer, "dsig",
WSTrustConstants.XMLDSig.RSA_KEYVALUE, WSTrustConstants.DSIG_NS);
// write the rsa key modulus.
byte[] modulus = type.getModulus();
- StaxUtil.writeStartElement(writer, "dsig",
WSTrustConstants.XMLDSig.MODULUS , WSTrustConstants.DSIG_NS);
+ StaxUtil.writeStartElement(writer, "dsig",
WSTrustConstants.XMLDSig.MODULUS, WSTrustConstants.DSIG_NS);
StaxUtil.writeCharacters(writer, new String(modulus));
StaxUtil.writeEndElement(writer);
-
+
// write the rsa key exponent.
byte[] exponent = type.getExponent();
- StaxUtil.writeStartElement(writer, "dsig",
WSTrustConstants.XMLDSig.EXPONENT , WSTrustConstants.DSIG_NS);
+ StaxUtil.writeStartElement(writer, "dsig",
WSTrustConstants.XMLDSig.EXPONENT, WSTrustConstants.DSIG_NS);
StaxUtil.writeCharacters(writer, new String(exponent));
StaxUtil.writeEndElement(writer);
-
+
StaxUtil.writeEndElement(writer);
}
+
/**
* Write an {@code OnBehalfOfType} to stream
* @param onBehalfOf
@@ -328,11 +344,11 @@
*/
private void writeOnBehalfOfType(OnBehalfOfType onBehalfOf) throws
ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.ON_BEHALF_OF,
BASE_NAMESPACE);
- UsernameTokenType usernameToken = (UsernameTokenType) onBehalfOf.getAny();
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.ON_BEHALF_OF,
BASE_NAMESPACE);
+ UsernameTokenType usernameToken = (UsernameTokenType) onBehalfOf.getAny();
WSSecurityWriter wsseWriter = new WSSecurityWriter(this.writer);
- wsseWriter.write( usernameToken );
- StaxUtil.writeEndElement( writer );
+ wsseWriter.write(usernameToken);
+ StaxUtil.writeEndElement(writer);
}
/**
@@ -343,8 +359,8 @@
*/
private void writeValidateTargetType(ValidateTargetType validateTarget) throws
ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.VALIDATE_TARGET,
BASE_NAMESPACE);
-
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.VALIDATE_TARGET,
BASE_NAMESPACE);
+
Object validateTargetObj = validateTarget.getAny();
if (validateTargetObj != null)
{
@@ -361,13 +377,13 @@
else
throw new ProcessingException("Unknown validate target type=" +
validateTargetObj.getClass().getName());
}
- StaxUtil.writeEndElement( writer );
+ StaxUtil.writeEndElement(writer);
}
private void writeRenewTargetType(RenewTargetType renewTarget) throws
ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.RENEW_TARGET,
BASE_NAMESPACE);
-
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.RENEW_TARGET,
BASE_NAMESPACE);
+
Object renewTargetObj = renewTarget.getAny();
if (renewTargetObj != null)
{
@@ -384,7 +400,7 @@
else
throw new ProcessingException("Unknown renew target type=" +
renewTargetObj.getClass().getName());
}
- StaxUtil.writeEndElement( writer );
+ StaxUtil.writeEndElement(writer);
}
/**
@@ -395,8 +411,8 @@
*/
private void writeCancelTargetType(CancelTargetType cancelTarget) throws
ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.CANCEL_TARGET,
BASE_NAMESPACE);
-
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.CANCEL_TARGET,
BASE_NAMESPACE);
+
Object cancelTargetObj = cancelTarget.getAny();
if (cancelTargetObj != null)
{
@@ -412,48 +428,48 @@
}
else
throw new ProcessingException("Unknown cancel target type=" +
cancelTargetObj.getClass().getName());
- }
- StaxUtil.writeEndElement( writer );
+ }
+ StaxUtil.writeEndElement(writer);
}
-
+
/**
* Write a {@code BinarySecretType} to stream
* @param writer
* @param binarySecret
* @throws ProcessingException
*/
- private void writeBinarySecretType( XMLStreamWriter writer, BinarySecretType
binarySecret ) throws ProcessingException
+ private void writeBinarySecretType(XMLStreamWriter writer, BinarySecretType
binarySecret) throws ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.BINARY_SECRET,
BASE_NAMESPACE );
- String type = binarySecret.getType();
- StaxUtil.writeAttribute(writer, WSTrustConstants.TYPE, type );
- StaxUtil.writeCharacters(writer, new String( binarySecret.getValue() ) );
- StaxUtil.writeEndElement(writer);
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.BINARY_SECRET,
BASE_NAMESPACE);
+ String type = binarySecret.getType();
+ StaxUtil.writeAttribute(writer, WSTrustConstants.TYPE, type);
+ StaxUtil.writeCharacters(writer, new String(binarySecret.getValue()));
+ StaxUtil.writeEndElement(writer);
}
-
+
/**
* Write a Request Type
* @param writer
* @param uri
* @throws ProcessingException
*/
- private void writeRequestType( XMLStreamWriter writer , URI uri ) throws
ProcessingException
+ private void writeRequestType(XMLStreamWriter writer, URI uri) throws
ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.REQUEST_TYPE,
BASE_NAMESPACE );
- StaxUtil.writeCharacters(writer, uri.toASCIIString() );
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.REQUEST_TYPE,
BASE_NAMESPACE);
+ StaxUtil.writeCharacters(writer, uri.toASCIIString());
StaxUtil.writeEndElement(writer);
}
-
+
/**
* Write Token Type
* @param writer
* @param uri
* @throws ProcessingException
*/
- private void writeTokenType( XMLStreamWriter writer , URI uri ) throws
ProcessingException
+ private void writeTokenType(XMLStreamWriter writer, URI uri) throws
ProcessingException
{
- StaxUtil.writeStartElement( writer, PREFIX, WSTrustConstants.TOKEN_TYPE,
BASE_NAMESPACE );
- StaxUtil.writeCharacters(writer, uri.toASCIIString() );
+ StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.TOKEN_TYPE,
BASE_NAMESPACE);
+ StaxUtil.writeCharacters(writer, uri.toASCIIString());
StaxUtil.writeEndElement(writer);
}
}
\ No newline at end of file