Search in sources :

Example 6 with RSAKeyValueType

use of org.keycloak.dom.xmlsec.w3.xmldsig.RSAKeyValueType in project keycloak by keycloak.

the class StaxWriterUtil method writeKeyInfo.

/**
 * Write the {@link org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType}
 *
 * @param writer
 * @param keyInfo
 *
 * @throws org.keycloak.saml.common.exceptions.ProcessingException
 */
public static void writeKeyInfo(XMLStreamWriter writer, KeyInfoType keyInfo) throws ProcessingException {
    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);
    // write the keyInfo content.
    Object content = keyInfo.getContent().get(0);
    if (content instanceof Element) {
        Element element = (Element) keyInfo.getContent().get(0);
        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(), GeneralConstants.SAML_CHARSET));
            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);
        if (keyvalueType instanceof DSAKeyValueType) {
            writeDSAKeyValueType(writer, (DSAKeyValueType) keyvalueType);
        }
        if (keyvalueType instanceof RSAKeyValueType) {
            writeRSAKeyValueType(writer, (RSAKeyValueType) keyvalueType);
        }
        StaxUtil.writeEndElement(writer);
    } else
        throw new ProcessingException(ErrorCodes.UNSUPPORTED_TYPE + content);
    StaxUtil.writeEndElement(writer);
}
Also used : X509CertificateType(org.keycloak.dom.xmlsec.w3.xmldsig.X509CertificateType) X509DataType(org.keycloak.dom.xmlsec.w3.xmldsig.X509DataType) Element(org.w3c.dom.Element) DSAKeyValueType(org.keycloak.dom.xmlsec.w3.xmldsig.DSAKeyValueType) KeyValueType(org.keycloak.dom.xmlsec.w3.xmldsig.KeyValueType) RSAKeyValueType(org.keycloak.dom.xmlsec.w3.xmldsig.RSAKeyValueType) RSAKeyValueType(org.keycloak.dom.xmlsec.w3.xmldsig.RSAKeyValueType) DSAKeyValueType(org.keycloak.dom.xmlsec.w3.xmldsig.DSAKeyValueType) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Aggregations

RSAKeyValueType (org.keycloak.dom.xmlsec.w3.xmldsig.RSAKeyValueType)6 DSAKeyValueType (org.keycloak.dom.xmlsec.w3.xmldsig.DSAKeyValueType)3 DSAPublicKey (java.security.interfaces.DSAPublicKey)2 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 Element (org.w3c.dom.Element)2 EndElement (javax.xml.stream.events.EndElement)1 StartElement (javax.xml.stream.events.StartElement)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 Test (org.junit.Test)1 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)1 AuthnContextType (org.keycloak.dom.saml.v2.assertion.AuthnContextType)1 AuthnStatementType (org.keycloak.dom.saml.v2.assertion.AuthnStatementType)1 EncryptedAssertionType (org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType)1 StatementAbstractType (org.keycloak.dom.saml.v2.assertion.StatementAbstractType)1 KeyInfoType (org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType)1 KeyValueType (org.keycloak.dom.xmlsec.w3.xmldsig.KeyValueType)1 X509CertificateType (org.keycloak.dom.xmlsec.w3.xmldsig.X509CertificateType)1 X509DataType (org.keycloak.dom.xmlsec.w3.xmldsig.X509DataType)1 ProcessingException (org.keycloak.saml.common.exceptions.ProcessingException)1 Node (org.w3c.dom.Node)1