/** * <p> * Creates a {@code WSTrustRequestWriter} that writes {@code RequestSecurityToken} instances to the specified * {@code OutputStream}. * </p> * * @param out the stream where the request is to be written. * @throws ProcessingException if an error occurs while processing the request. */ public WSTrustRequestWriter(OutputStream out) throws ProcessingException { this.writer = StaxUtil.getXMLStreamWriter(out); }
public void writeLifetime(XMLGregorianCalendar created, XMLGregorianCalendar expires) throws ProcessingException { // write the created element. StaxUtil.writeStartElement(this.writer, WSU_PREFIX, WSTrustConstants.CREATED, WSU_NS); StaxUtil.writeNameSpace(this.writer, WSU_PREFIX, WSU_NS); StaxUtil.writeCharacters(this.writer, created.toXMLFormat()); StaxUtil.writeEndElement(this.writer); // write the expires element. StaxUtil.writeStartElement(this.writer, WSU_PREFIX, WSTrustConstants.EXPIRES, WSU_NS); StaxUtil.writeNameSpace(this.writer, WSU_PREFIX, WSU_NS); StaxUtil.writeCharacters(this.writer, expires.toXMLFormat()); StaxUtil.writeEndElement(this.writer); StaxUtil.flush(this.writer); }
/** * Write an {@code UseKeyType} to stream * * @param useKeyType * @throws ProcessingException */ private void writeUseKeyType(UseKeyType useKeyType) throws ProcessingException { StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.USE_KEY, BASE_NAMESPACE); List<Object> theList = useKeyType.getAny(); for (Object useKeyTypeValue : theList) { if (useKeyTypeValue instanceof Element) { Element domElement = (Element) useKeyTypeValue; StaxUtil.writeDOMElement(writer, domElement); } else if (useKeyTypeValue instanceof byte[]) { byte[] certificate = (byte[]) useKeyTypeValue; StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.X509CERT, WSTrustConstants.DSIG_NS); StaxUtil.writeNameSpace(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.DSIG_NS); StaxUtil.writeCharacters(writer, new String(certificate)); StaxUtil.writeEndElement(writer); } else if (useKeyTypeValue instanceof KeyValueType) { writeKeyValueType((KeyValueType) useKeyTypeValue); } else if (useKeyTypeValue instanceof KeyInfoType) { StaxUtil.writeKeyInfo(writer, (KeyInfoType) useKeyTypeValue); } else throw logger.writerUnknownTypeError(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); if (type instanceof RSAKeyValueType) { RSAKeyValueType rsaKeyValue = (RSAKeyValueType) type; StaxUtil.writeRSAKeyValueType(writer,rsaKeyValue); } else if(type instanceof DSAKeyValueType) { DSAKeyValueType dsaKeyValue = (DSAKeyValueType)type; StaxUtil.writeDSAKeyValueType(writer, dsaKeyValue); } StaxUtil.writeEndElement(writer); }
/** * Write a Request Type * * @param writer * @param 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.writeEndElement(writer); }
/** * Write a {@code StatusDetailType} to stream * * @param statusDetailType * @param out * @throws ProcessingException */ public void write(StatusDetailType statusDetailType) throws ProcessingException { StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_CODE.get(), PROTOCOL_NSURI.get()); StaxUtil.writeEndElement(writer); StaxUtil.flush(writer); }
public void write(SAML11SubjectConfirmationType confirmation) throws ProcessingException { StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION.get(), SAML11Constants.ASSERTION_11_NSURI); List<URI> confirmationMethods = confirmation.getConfirmationMethod(); if (confirmationMethods != null) { for (URI confirmationMethod : confirmationMethods) { StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.CONFIRMATION_METHOD, SAML11Constants.ASSERTION_11_NSURI); StaxUtil.writeCharacters(writer, confirmationMethod.toString()); StaxUtil.writeEndElement(writer); } } Element keyInfo = confirmation.getKeyInfo(); if (keyInfo != null) { StaxUtil.writeDOMElement(writer, keyInfo); } Object subjectConfirmationData = confirmation.getSubjectConfirmationData(); if (subjectConfirmationData != null) { writeSubjectConfirmationData(subjectConfirmationData); } StaxUtil.writeEndElement(writer); StaxUtil.flush(writer); }
writeStartElement(writer, domElementPrefix, domElement.getLocalName(), domElementNS); writeNameSpace(writer, "xmlns", domElementNS); writeAttribute(writer, attribLocalName, attribValue); writeNameSpace(writer, attribLocalName, attribValue); } else { writeAttribute(writer, new QName(attr.getNamespaceURI(), attribLocalName, attributePrefix), attribValue); writeDOMNode(writer, child); writeEndElement(writer);
if (keyInfo.getContent() == null || keyInfo.getContent().size() == 0) throw logger.writerInvalidKeyInfoNullContentError(); StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.KEYINFO, WSTrustConstants.XMLDSig.DSIG_NS); StaxUtil.writeNameSpace(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.DSIG_NS); StaxUtil.writeDOMNode(writer, element); } else if (content instanceof X509DataType) { X509DataType type = (X509DataType) content; if (type.getDataObjects().size() == 0) throw logger.writerNullValueError("X509Data"); StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.X509DATA, WSTrustConstants.XMLDSig.DSIG_NS); Object obj = type.getDataObjects().get(0); if (obj instanceof Element) { Element element = (Element) obj; StaxUtil.writeDOMElement(writer, element); } else if (obj instanceof X509CertificateType) { X509CertificateType cert = (X509CertificateType) obj; StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.X509CERT, WSTrustConstants.XMLDSig.DSIG_NS); StaxUtil.writeCharacters(writer, new String(cert.getEncodedCertificate())); StaxUtil.writeEndElement(writer); StaxUtil.writeEndElement(writer); } else if( content instanceof KeyValueType){ KeyValueType keyvalueType = (KeyValueType) content; StaxUtil.writeStartElement(writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.KEYVALUE, WSTrustConstants.XMLDSig.DSIG_NS);
private void writeLocalizedType(LocalizedNameType localName) throws ProcessingException { String lang = localName.getLang(); String val = localName.getValue(); StaxUtil.writeAttribute(writer, new QName(JBossSAMLURIConstants.XML.get(), JBossSAMLConstants.LANG.get(), "xml"), lang); StaxUtil.writeCharacters(writer, val); StaxUtil.writeEndElement(writer); }
public void writeIndexedEndpointType(IndexedEndpointType indexedEndpoint) throws ProcessingException { writeEndpointType(indexedEndpoint); if (indexedEndpoint.isIsDefault() != null) StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISDEFAULT.get(), "" + indexedEndpoint.isIsDefault()); StaxUtil.writeAttribute(writer, JBossSAMLConstants.INDEX.get(), "" + indexedEndpoint.getIndex()); StaxUtil.writeEndElement(writer); StaxUtil.flush(writer); }
private void writeRenewTargetType(RenewTargetType renewTarget) throws ProcessingException { StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.RENEW_TARGET, BASE_NAMESPACE); List<Object> list = renewTarget.getAny(); for (Object renewTargetObj : list) { if (renewTargetObj instanceof AssertionType) { AssertionType assertion = (AssertionType) renewTargetObj; SAMLAssertionWriter samlAssertionWriter = new SAMLAssertionWriter(this.writer); samlAssertionWriter.write(assertion); } else if (renewTargetObj instanceof Element) { StaxUtil.writeDOMElement(writer, (Element) renewTargetObj); } else throw logger.writerUnknownTypeError(renewTargetObj.getClass().getName()); } /* * Object renewTargetObj = renewTarget.getAny(); if (renewTargetObj != null) { if (renewTargetObj instanceof * AssertionType) { AssertionType assertion = (AssertionType) renewTargetObj; SAMLAssertionWriter samlAssertionWriter = * new SAMLAssertionWriter(this.writer); samlAssertionWriter.write(assertion); } else if (renewTargetObj instanceof * Element) { StaxUtil.writeDOMElement(writer, (Element) renewTargetObj); } else throw new * ProcessingException("Unknown renew target type=" + renewTargetObj.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); if (type.getContent().size() == 0) throw new ProcessingException(ErrorCodes.NULL_VALUE + "KeyValueType must contain at least one value"); for (Object obj : type.getContent()) { if (obj instanceof RSAKeyValueType) { RSAKeyValueType rsaKeyValue = (RSAKeyValueType) obj; writeRSAKeyValueType(rsaKeyValue); } } StaxUtil.writeEndElement(writer); }
/** * Write a {@code StatusDetailType} to stream * @param statusDetailType * @param out * @throws ProcessingException */ public void write(StatusDetailType statusDetailType) throws ProcessingException { StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_CODE.get(), PROTOCOL_NSURI.get()); StaxUtil.writeEndElement(writer); StaxUtil.flush(writer); }
public void write(SAML11SubjectConfirmationType confirmation) throws ProcessingException { StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION.get(), SAML11Constants.ASSERTION_11_NSURI); List<URI> confirmationMethods = confirmation.getConfirmationMethod(); if (confirmationMethods != null) { for (URI confirmationMethod : confirmationMethods) { StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, SAML11Constants.CONFIRMATION_METHOD, SAML11Constants.ASSERTION_11_NSURI); StaxUtil.writeCharacters(writer, confirmationMethod.toString()); StaxUtil.writeEndElement(writer); } } Element keyInfo = confirmation.getKeyInfo(); if (keyInfo != null) { StaxUtil.writeDOMElement(writer, keyInfo); } Object subjectConfirmationData = confirmation.getSubjectConfirmationData(); if (subjectConfirmationData != null) { writeSubjectConfirmationData(subjectConfirmationData); } StaxUtil.writeEndElement(writer); StaxUtil.flush(writer); }
writeStartElement(writer, domElementPrefix, domElement.getLocalName(), domElementNS); writeNameSpace(writer, "xmlns", domElementNS); writeAttribute(writer, attribLocalName, attribValue); writeNameSpace(writer, attribLocalName, attribValue); writeAttribute(writer, new QName(attr.getNamespaceURI(), attribLocalName, attributePrefix), attribValue); writeDOMNode(writer, child); writeEndElement(writer);
/** * Write a Request Type * @param writer * @param 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.writeEndElement(writer); }
private void writeLocalizedType(LocalizedNameType localName) throws ProcessingException { String lang = localName.getLang(); String val = localName.getValue(); StaxUtil.writeAttribute(writer, new QName(JBossSAMLURIConstants.XML.get(), JBossSAMLConstants.LANG.get(), "xml"), lang); StaxUtil.writeCharacters(writer, val); StaxUtil.writeEndElement(writer); }
public void writeIndexedEndpointType(IndexedEndpointType indexedEndpoint) throws ProcessingException { writeEndpointType(indexedEndpoint); if (indexedEndpoint.isIsDefault() != null) StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISDEFAULT.get(), "" + indexedEndpoint.isIsDefault()); StaxUtil.writeAttribute(writer, JBossSAMLConstants.INDEX.get(), "" + indexedEndpoint.getIndex()); StaxUtil.writeEndElement(writer); StaxUtil.flush(writer); }
/** * Write an {@code ValidateTargetType} to stream * * @param validateTarget * @param out * @throws ProcessingException */ private void writeValidateTargetType(ValidateTargetType validateTarget) throws ProcessingException { StaxUtil.writeStartElement(writer, PREFIX, WSTrustConstants.VALIDATE_TARGET, BASE_NAMESPACE); List<Object> list = validateTarget.getAny(); for (Object validateTargetObj : list) { if (validateTargetObj instanceof AssertionType) { AssertionType assertion = (AssertionType) validateTargetObj; SAMLAssertionWriter samlAssertionWriter = new SAMLAssertionWriter(this.writer); samlAssertionWriter.write(assertion); } else if (validateTargetObj instanceof Element) { StaxUtil.writeDOMElement(writer, (Element) validateTargetObj); } else throw logger.writerUnknownTypeError(validateTargetObj.getClass().getName()); } /* * Object validateTargetObj = validateTarget.getAny(); if (validateTargetObj != null) { if (validateTargetObj instanceof * AssertionType) { AssertionType assertion = (AssertionType) validateTargetObj; SAMLAssertionWriter samlAssertionWriter * = new SAMLAssertionWriter(this.writer); samlAssertionWriter.write(assertion); } else if (validateTargetObj instanceof * Element) { StaxUtil.writeDOMElement(writer, (Element) validateTargetObj); } else throw new * ProcessingException("Unknown validate target type=" + validateTargetObj.getClass().getName()); } */ StaxUtil.writeEndElement(writer); }