Java Code Examples for javax.xml.stream.XMLStreamWriter#setPrefix()

The following examples show how to use javax.xml.stream.XMLStreamWriter#setPrefix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NSWriter.java    From softwarecave with GNU General Public License v3.0 5 votes vote down vote up
private void writeBooksElem(XMLStreamWriter writer, List<Book> books) throws XMLStreamException {
    writer.writeStartDocument("utf-8", "1.0");
    writer.writeComment("Describes list of books");
    
    writer.setPrefix("b", NS);
    writer.writeStartElement(NS, "books");
    writer.writeNamespace("b", NS);
    for (Book book : books)
        writeBookElem(writer, book);
    writer.writeEndElement();

    writer.writeEndDocument();
}
 
Example 2
Source File: RecipientToken.java    From steady with Apache License 2.0 5 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:RecipientToken>
    writer.writeStartElement(prefix, localName, namespaceURI);

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
        pPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
        .getNamespaceURI());

    Token token = getRecipientToken();
    if (token == null) {
        throw new RuntimeException("RecipientToken doesn't contain any token assertions");
    }
    token.serialize(writer);

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:RecipientToken>
    writer.writeEndElement();
}
 
Example 3
Source File: SourceUtils.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * sets undeclared prefixes on the writer
 * @param prefix
 * @param writer
 * @throws XMLStreamException
 */
private static void setUndeclaredPrefix(String prefix, String readerURI, XMLStreamWriter writer) throws XMLStreamException {
    String writerURI = null;
    if (writer.getNamespaceContext() != null) {
        writerURI = writer.getNamespaceContext().getNamespaceURI(prefix);
    }

    if (writerURI == null) {
        writer.setPrefix(prefix, readerURI != null ? readerURI : "");
        writer.writeNamespace(prefix, readerURI != null ? readerURI : "");
    }
}
 
Example 4
Source File: KerberosToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getSamlToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:KerberosToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
        pPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
                             .getNamespaceURI());

    if (isRequireKeyIdentifierReference()) {
        // <sp:RequireKeyIdentifierReference />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_KEY_IDENTIFIER_REFERENCE, namespaceURI);
        writer.writeEndElement();
    }

    if (isV5ApReqToken11()) {
        // <sp:WssKerberosV5ApReqToken11 />
        writer.writeStartElement(prefix, SPConstants.KERBEROS_V5_AP_REQ_TOKEN_11, namespaceURI);
        writer.writeEndElement();
    } else if (isGssV5ApReqToken11()) {
        // <sp:WssGssKerberosV5ApReqToken11 />
        writer.writeStartElement(prefix, SPConstants.KERBEROS_GSS_V5_AP_REQ_TOKEN_11, namespaceURI);
        writer.writeEndElement();
    }
    
    if (isDerivedKeys()) {
        // <sp:RequireDerivedKeys />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
        writer.writeEndElement();
    }

    // </wsp:Policy>
    writer.writeEndElement();


    writer.writeEndElement();
    // </sp:KerberosToken>

}
 
Example 5
Source File: UsernameToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getUserNameToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:UsernameToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (isUseUTProfile10() || isUseUTProfile11()) {
        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
        if (pPrefix == null) {
            pPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
        }

        // <wsp:Policy>
        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
            .getNamespaceURI());

        // CHECKME
        if (isUseUTProfile10()) {
            // <sp:WssUsernameToken10 />
            writer.writeStartElement(prefix, SPConstants.USERNAME_TOKEN10, namespaceURI);
        } else {
            // <sp:WssUsernameToken11 />
            writer.writeStartElement(prefix, SPConstants.USERNAME_TOKEN11, namespaceURI);
        }

        if (constants.getVersion() == SPConstants.Version.SP_V12) {

            if (isNoPassword()) {
                writer.writeStartElement(prefix, SPConstants.NO_PASSWORD, namespaceURI);
                writer.writeEndElement();
            } else if (isHashPassword()) {
                writer.writeStartElement(prefix, SPConstants.HASH_PASSWORD, namespaceURI);
                writer.writeEndElement();
            }

            if (isDerivedKeys()) {
                writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
                writer.writeEndElement();
            } else if (isExplicitDerivedKeys()) {
                writer.writeStartElement(prefix, SPConstants.REQUIRE_EXPLICIT_DERIVED_KEYS, namespaceURI);
                writer.writeEndElement();
            } else if (isImpliedDerivedKeys()) {
                writer.writeStartElement(prefix, SPConstants.REQUIRE_IMPLIED_DERIVED_KEYS, namespaceURI);
                writer.writeEndElement();
            }
            
            if (isRequireCreated()) {
                writer.writeStartElement(SP13Constants.SP_PREFIX, "Created", SP13Constants.SP_NS);
                writer.writeNamespace(SP13Constants.SP_PREFIX, SP13Constants.SP_NS);
                writer.writeEndElement();
            }
            if (isRequireNonce()) {
                writer.writeStartElement(SP13Constants.SP_PREFIX, "Nonce", SP13Constants.SP_NS);
                writer.writeNamespace(SP13Constants.SP_PREFIX, SP13Constants.SP_NS);
                writer.writeEndElement();
            }

        }
        writer.writeEndElement();

        // </wsp:Policy>
        writer.writeEndElement();

    }

    writer.writeEndElement();
    // </sp:UsernameToken>

}
 
Example 6
Source File: Trust10.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {

        String localname = getRealName().getLocalPart();
        String namespaceURI = getRealName().getNamespaceURI();

        String prefix = writer.getPrefix(namespaceURI);
        if (prefix == null) {
            prefix = getRealName().getPrefix();
            writer.setPrefix(prefix, namespaceURI);
        }

        // <sp:Trust10>
        writer.writeStartElement(prefix, localname, namespaceURI);
        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);

        String wspPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
        if (wspPrefix == null) {
            wspPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(wspPrefix, SPConstants.POLICY.getNamespaceURI());
        }

        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(),
                                 SPConstants.POLICY.getNamespaceURI());

        if (isMustSupportClientChallenge()) {
            // <sp:MustSupportClientChallenge />
            writer.writeStartElement(prefix, SPConstants.MUST_SUPPORT_CLIENT_CHALLENGE, namespaceURI);
            writer.writeEndElement();
        }

        if (isMustSupportServerChallenge()) {
            // <sp:MustSupportServerChallenge />
            writer.writeStartElement(prefix, SPConstants.MUST_SUPPORT_SERVER_CHALLENGE, namespaceURI);
            writer.writeEndElement();
        }

        if (isRequireClientEntropy()) {
            // <sp:RequireClientEntropy />
            writer.writeStartElement(prefix, SPConstants.REQUIRE_CLIENT_ENTROPY, namespaceURI);
            writer.writeEndElement();
        }

        if (isRequireServerEntropy()) {
            // <sp:RequireServerEntropy />
            writer.writeStartElement(prefix, SPConstants.REQUIRE_SERVER_ENTROPY, namespaceURI);
            writer.writeEndElement();
        }

        if (isMustSupportIssuedTokens()) {
            // <sp:MustSupportIssuedTokens />
            writer.writeStartElement(prefix, SPConstants.MUST_SUPPORT_ISSUED_TOKENS, namespaceURI);
            writer.writeEndElement();
        }

        // </wsp:Policy>
        writer.writeEndElement();

        // </sp:Trust10>
        writer.writeEndElement();

    }
 
Example 7
Source File: SpnegoContextToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getSpnegoContextToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();
    String prefix;

    String writerPrefix = writer.getPrefix(namespaceURI);

    if (writerPrefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    } else {
        prefix = writerPrefix;
    }

    // <sp:SpnegoContextToken>
    writer.writeStartElement(prefix, localname, namespaceURI);

    if (writerPrefix == null) {
        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);
    }

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (issuerEpr != null) {
        // <sp:Issuer>
        writer.writeStartElement(prefix, SPConstants.ISSUER, namespaceURI);

        StaxUtils.copy(issuerEpr, writer);

        writer.writeEndElement();
    }

    if (isDerivedKeys()) {

        String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

        String wspPrefix;

        String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

        if (wspWriterPrefix == null) {
            wspPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(wspPrefix, wspNamespaceURI);

        } else {
            wspPrefix = wspWriterPrefix;
        }

        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

        if (wspWriterPrefix == null) {
            // xmlns:wsp=".."
            writer.writeNamespace(wspPrefix, wspNamespaceURI);
        }

        if (isDerivedKeys()) {
            // <sp:RequireDerivedKeys />
            writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
        }

        // </wsp:Policy>
        writer.writeEndElement();
    }

    // </sp:SpnegoContextToken>
    writer.writeEndElement();
}
 
Example 8
Source File: Wss10.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localname = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:Wss10>
    writer.writeStartElement(prefix, localname, namespaceURI);

    // xmlns:sp=".."
    writer.writeNamespace(prefix, namespaceURI);

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
        pPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
        .getNamespaceURI());

    if (isMustSupportRefKeyIdentifier()) {
        // <sp:MustSupportRefKeyIdentifier />
        writer.writeStartElement(prefix, SPConstants.MUST_SUPPORT_REF_KEY_IDENTIFIER, namespaceURI);
        writer.writeEndElement();
    }

    if (isMustSupportRefIssuerSerial()) {
        // <sp:MustSupportRefIssuerSerial />
        writer.writeStartElement(prefix, SPConstants.MUST_SUPPORT_REF_ISSUER_SERIAL, namespaceURI);
        writer.writeEndElement();
    }

    if (isMustSupportRefExternalURI()) {
        // <sp:MustSupportRefExternalURI />
        writer.writeStartElement(prefix, SPConstants.MUST_SUPPORT_REF_EXTERNAL_URI, namespaceURI);
        writer.writeEndElement();
    }

    if (isMustSupportRefEmbeddedToken()) {
        // <sp:MustSupportRefEmbeddedToken />
        writer.writeStartElement(prefix, SPConstants.MUST_SUPPORT_REF_EMBEDDED_TOKEN, namespaceURI);
        writer.writeEndElement();

    }
    
    
    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:Wss10>
    writer.writeEndElement();

}
 
Example 9
Source File: RequiredElements.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {

        String localName = getRealName().getLocalPart();
        String namespaceURI = getRealName().getNamespaceURI();

        String prefix;
        String writerPrefix = writer.getPrefix(namespaceURI);

        if (writerPrefix == null) {
            prefix = getRealName().getPrefix();
            writer.setPrefix(prefix, namespaceURI);
        } else {
            prefix = writerPrefix;
        }

        // <sp:RequiredElements>
        writer.writeStartElement(prefix, localName, namespaceURI);

        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);

        if (writerPrefix == null) {
            // xmlns:sp=".."
            writer.writeNamespace(prefix, namespaceURI);
        }

        if (xPathVersion != null) {
            writer.writeAttribute(prefix, namespaceURI, SPConstants.XPATH_VERSION, xPathVersion);
        }

        String xpathExpression;

        for (Iterator<String> iterator = xPathExpressions.iterator(); iterator.hasNext();) {
            xpathExpression = iterator.next();
            // <sp:XPath ..>
            writer.writeStartElement(prefix, SPConstants.XPATH_EXPR, namespaceURI);
            writer.writeCharacters(xpathExpression);
            writer.writeEndElement();
        }

        // </sp:RequiredElements>
        writer.writeEndElement();
    }
 
Example 10
Source File: KeyValueToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getUserNameToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:KeyValueToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }


    if (forceRsaKeyValue) {
        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
        if (pPrefix == null) {
            writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
        }

        // <wsp:Policy>
        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
            .getNamespaceURI());
        
        writer.writeEmptyElement(prefix, "RsaKeyValue", namespaceURI);

        // </wsp:Policy>
        writer.writeEndElement();

    }
    writer.writeEndElement();
    // </sp:KeyValueToken>

}
 
Example 11
Source File: EncryptionToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localname = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();
    String prefix;

    String writerPrefix = writer.getPrefix(namespaceURI);

    if (writerPrefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    } else {
        prefix = writerPrefix;
    }

    // <sp:EncryptionToken>
    writer.writeStartElement(prefix, localname, namespaceURI);

    if (writerPrefix == null) {
        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);
    }

    String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

    String wspPrefix;

    String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

    if (wspWriterPrefix == null) {
        wspPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(wspPrefix, wspNamespaceURI);

    } else {
        wspPrefix = wspWriterPrefix;
    }

    // <wsp:Policy>
    writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

    if (wspWriterPrefix == null) {
        // xmlns:wsp=".."
        writer.writeNamespace(wspPrefix, wspNamespaceURI);
    }

    if (token == null) {
        throw new RuntimeException("EncryptionToken is not set");
    }

    token.serialize(writer);

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:EncryptionToken>
    writer.writeEndElement();
}
 
Example 12
Source File: EncryptionToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localname = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();
    String prefix;

    String writerPrefix = writer.getPrefix(namespaceURI);

    if (writerPrefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    } else {
        prefix = writerPrefix;
    }

    // <sp:EncryptionToken>
    writer.writeStartElement(prefix, localname, namespaceURI);

    if (writerPrefix == null) {
        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);
    }

    String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

    String wspPrefix;

    String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

    if (wspWriterPrefix == null) {
        wspPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(wspPrefix, wspNamespaceURI);

    } else {
        wspPrefix = wspWriterPrefix;
    }

    // <wsp:Policy>
    writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

    if (wspWriterPrefix == null) {
        // xmlns:wsp=".."
        writer.writeNamespace(wspPrefix, wspNamespaceURI);
    }

    if (token == null) {
        throw new RuntimeException("EncryptionToken is not set");
    }

    token.serialize(writer);

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:EncryptionToken>
    writer.writeEndElement();
}
 
Example 13
Source File: KeyValueToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getUserNameToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:KeyValueToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }


    if (forceRsaKeyValue) {
        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
        if (pPrefix == null) {
            writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
        }

        // <wsp:Policy>
        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
            .getNamespaceURI());
        
        writer.writeEmptyElement(prefix, "RsaKeyValue", namespaceURI);

        // </wsp:Policy>
        writer.writeEndElement();

    }
    writer.writeEndElement();
    // </sp:KeyValueToken>

}
 
Example 14
Source File: ContentEncryptedElements.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {

        String localName = getRealName().getLocalPart();
        String namespaceURI = getRealName().getNamespaceURI();

        String prefix;
        String writerPrefix = writer.getPrefix(namespaceURI);

        if (writerPrefix == null) {
            prefix = getRealName().getPrefix();
            writer.setPrefix(prefix, namespaceURI);
        } else {
            prefix = writerPrefix;
        }

        // <sp:ContentEncryptedElements>
        writer.writeStartElement(prefix, localName, namespaceURI);

        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);

        if (writerPrefix == null) {
            // xmlns:sp=".."
            writer.writeNamespace(prefix, namespaceURI);
        }

        if (xPathVersion != null) {
            writer.writeAttribute(prefix, namespaceURI, SPConstants.XPATH_VERSION, xPathVersion);
        }

        String xpathExpression;

        for (Iterator<String> iterator = xPathExpressions.iterator(); iterator.hasNext();) {
            xpathExpression = iterator.next();
            // <sp:XPath ..>
            writer.writeStartElement(prefix, SPConstants.XPATH_EXPR, namespaceURI);
            writer.writeCharacters(xpathExpression);
            writer.writeEndElement();
        }

        // </sp:ContentEncryptedElements>
        writer.writeEndElement();
    }
 
Example 15
Source File: SignatureToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {

        String localname = getRealName().getLocalPart();
        String namespaceURI = getRealName().getNamespaceURI();

        String prefix;
        String writerPrefix = writer.getPrefix(namespaceURI);

        if (writerPrefix == null) {
            prefix = getRealName().getPrefix();
            writer.setPrefix(prefix, namespaceURI);

        } else {
            prefix = writerPrefix;
        }

        // <sp:SignatureToken>
        writer.writeStartElement(prefix, localname, namespaceURI);

        if (writerPrefix == null) {
            // xmlns:sp=".."
            writer.writeNamespace(prefix, namespaceURI);
        }

        String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

        String wspPrefix;

        String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

        if (wspWriterPrefix == null) {
            wspPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(wspPrefix, wspNamespaceURI);

        } else {
            wspPrefix = wspWriterPrefix;
        }

        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

        if (wspWriterPrefix == null) {
            // xmlns:wsp=".."
            writer.writeNamespace(wspPrefix, wspNamespaceURI);
        }

        if (token == null) {
            throw new RuntimeException("EncryptionToken is not set");
        }

        token.serialize(writer);

        // </wsp:Policy>
        writer.writeEndElement();

        // </sp:SignatureToken>
        writer.writeEndElement();
    }
 
Example 16
Source File: SamlToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getSamlToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:SamlToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (isUseSamlVersion11Profile10() || isUseSamlVersion11Profile11()
        || isUseSamlVersion20Profile11()) {
        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
        if (pPrefix == null) {
            pPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
        }

        // <wsp:Policy>
        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
            .getNamespaceURI());

        // CHECKME
        if (isUseSamlVersion11Profile10()) {
            // <sp:WssSamlV11Token10 />
            writer.writeStartElement(prefix, SPConstants.SAML_11_TOKEN_10, namespaceURI);
        } else if (isUseSamlVersion11Profile11()) {
            // <sp:WssSamlV11Token11 />
            writer.writeStartElement(prefix, SPConstants.SAML_11_TOKEN_11, namespaceURI);
        } else {
            // <sp:WssSamlV20Token11 />
            writer.writeStartElement(prefix, SPConstants.SAML_20_TOKEN_11, namespaceURI);
        }
        
        if (isDerivedKeys()) {
            writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
            writer.writeEndElement();
        } else if (isExplicitDerivedKeys()) {
            writer.writeStartElement(prefix, SPConstants.REQUIRE_EXPLICIT_DERIVED_KEYS, namespaceURI);
            writer.writeEndElement();
        } else if (isImpliedDerivedKeys()) {
            writer.writeStartElement(prefix, SPConstants.REQUIRE_IMPLIED_DERIVED_KEYS, namespaceURI);
            writer.writeEndElement();
        }
        
        if (isRequireKeyIdentifierReference()) {
            writer.writeStartElement(prefix, SPConstants.REQUIRE_KEY_IDENTIFIER_REFERENCE, namespaceURI);
            writer.writeEndElement();
        }

        writer.writeEndElement();

        // </wsp:Policy>
        writer.writeEndElement();

    }

    writer.writeEndElement();
    // </sp:SamlToken>

}
 
Example 17
Source File: X509Token.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:X509Token>
    writer.writeStartElement(prefix, localName, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
        pPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
        .getNamespaceURI());

    if (isRequireKeyIdentifierReference()) {
        // <sp:RequireKeyIdentifierReference />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_KEY_IDENTIFIER_REFERENCE, namespaceURI);
        writer.writeEndElement();
    }

    if (isRequireIssuerSerialReference()) {
        // <sp:RequireIssuerSerialReference />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_ISSUER_SERIAL_REFERENCE, namespaceURI);
        writer.writeEndElement();
    }

    if (isRequireEmbeddedTokenReference()) {
        // <sp:RequireEmbeddedTokenReference />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_EMBEDDED_TOKEN_REFERENCE, namespaceURI);
        writer.writeEndElement();
    }

    if (isRequireThumbprintReference()) {
        // <sp:RequireThumbprintReference />
        writer.writeStartElement(prefix, SPConstants.REQUIRE_THUMBPRINT_REFERENCE, namespaceURI);
        writer.writeEndElement();
    }

    if (tokenVersionAndType != null) {
        // <sp:WssX509V1Token10 /> | ..
        writer.writeStartElement(prefix, tokenVersionAndType, namespaceURI);
        writer.writeEndElement();
    }

    if (isDerivedKeys()) {
        // <sp:RequireDerivedKeys/>
        writer.writeStartElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
        writer.writeEndElement();
    }

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:X509Token>
    writer.writeEndElement();
}
 
Example 18
Source File: KeyValueToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    QName name = constants.getUserNameToken();
    String localname = name.getLocalPart();
    String namespaceURI = name.getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);
    if (prefix == null) {
        prefix = name.getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:KeyValueToken
    writer.writeStartElement(prefix, localname, namespaceURI);

    writer.writeNamespace(prefix, namespaceURI);

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }


    if (forceRsaKeyValue) {
        String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
        if (pPrefix == null) {
            writer.setPrefix(SPConstants.POLICY.getPrefix(), SPConstants.POLICY.getNamespaceURI());
        }

        // <wsp:Policy>
        writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
            .getNamespaceURI());
        
        writer.writeEmptyElement(prefix, "RsaKeyValue", namespaceURI);

        // </wsp:Policy>
        writer.writeEndElement();

    }
    writer.writeEndElement();
    // </sp:KeyValueToken>

}
 
Example 19
Source File: SignatureToken.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {

        String localname = getRealName().getLocalPart();
        String namespaceURI = getRealName().getNamespaceURI();

        String prefix;
        String writerPrefix = writer.getPrefix(namespaceURI);

        if (writerPrefix == null) {
            prefix = getRealName().getPrefix();
            writer.setPrefix(prefix, namespaceURI);

        } else {
            prefix = writerPrefix;
        }

        // <sp:SignatureToken>
        writer.writeStartElement(prefix, localname, namespaceURI);

        if (writerPrefix == null) {
            // xmlns:sp=".."
            writer.writeNamespace(prefix, namespaceURI);
        }

        String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

        String wspPrefix;

        String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

        if (wspWriterPrefix == null) {
            wspPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(wspPrefix, wspNamespaceURI);

        } else {
            wspPrefix = wspWriterPrefix;
        }

        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

        if (wspWriterPrefix == null) {
            // xmlns:wsp=".."
            writer.writeNamespace(wspPrefix, wspNamespaceURI);
        }

        if (token == null) {
            throw new RuntimeException("EncryptionToken is not set");
        }

        token.serialize(writer);

        // </wsp:Policy>
        writer.writeEndElement();

        // </sp:SignatureToken>
        writer.writeEndElement();
    }
 
Example 20
Source File: SignedEncryptedParts.java    From steady with Apache License 2.0 4 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:SignedParts> | <sp:EncryptedParts>
    writer.writeStartElement(prefix, localName, namespaceURI);

    // xmlns:sp=".."
    writer.writeNamespace(prefix, namespaceURI);

    if (isBody()) {
        // <sp:Body />
        writer.writeStartElement(prefix, SPConstants.BODY, namespaceURI);
        writer.writeEndElement();
    }

    Header header;
    for (Iterator<Header> iterator = headers.iterator(); iterator.hasNext();) {
        header = iterator.next();
        // <sp:Header Name=".." Namespace=".." />
        writer.writeStartElement(prefix, SPConstants.HEADER, namespaceURI);
        // Name attribute is optional
        if (!StringUtils.isEmpty(header.getName())) {
            writer.writeAttribute("Name", header.getName());
        }
        writer.writeAttribute("Namespace", header.getNamespace());

        writer.writeEndElement();
    }

    if (isAttachments() && constants.getVersion() == SPConstants.Version.SP_V12) {
        // <sp:Attachments />
        writer.writeStartElement(prefix, SPConstants.ATTACHMENTS, namespaceURI);
        writer.writeEndElement();
    }

    // </sp:SignedParts> | </sp:EncryptedParts>
    writer.writeEndElement();
}