Search in sources :

Example 1 with EncryptedElementType

use of org.keycloak.dom.saml.v2.assertion.EncryptedElementType in project keycloak by keycloak.

the class BaseWriter method write.

/**
 * write an {@code SubjectType} to stream
 *
 * @param subject
 * @param out
 *
 * @throws ProcessingException
 */
public void write(SubjectType subject) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT.get(), ASSERTION_NSURI.get());
    SubjectType.STSubType subType = subject.getSubType();
    if (subType != null) {
        BaseIDAbstractType baseID = subType.getBaseID();
        if (baseID instanceof NameIDType) {
            NameIDType nameIDType = (NameIDType) baseID;
            write(nameIDType, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.NAMEID.get(), ASSERTION_PREFIX));
        }
        EncryptedElementType enc = subType.getEncryptedID();
        if (enc != null)
            throw new RuntimeException("NYI");
        List<SubjectConfirmationType> confirmations = subType.getConfirmation();
        if (confirmations != null) {
            for (SubjectConfirmationType confirmation : confirmations) {
                write(confirmation);
            }
        }
    }
    List<SubjectConfirmationType> subjectConfirmations = subject.getConfirmation();
    if (subjectConfirmations != null) {
        for (SubjectConfirmationType subjectConfirmationType : subjectConfirmations) {
            write(subjectConfirmationType);
        }
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SubjectType(org.keycloak.dom.saml.v2.assertion.SubjectType) SubjectConfirmationType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType) QName(javax.xml.namespace.QName) BaseIDAbstractType(org.keycloak.dom.saml.v2.assertion.BaseIDAbstractType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) EncryptedElementType(org.keycloak.dom.saml.v2.assertion.EncryptedElementType)

Example 2 with EncryptedElementType

use of org.keycloak.dom.saml.v2.assertion.EncryptedElementType in project keycloak by keycloak.

the class SAMLAssertionWriter method write.

public void write(AttributeStatementType statement) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get(), ASSERTION_NSURI.get());
    List<ASTChoiceType> attributes = statement.getAttributes();
    if (attributes != null) {
        for (ASTChoiceType attr : attributes) {
            AttributeType attributeType = attr.getAttribute();
            if (attributeType != null) {
                write(attributeType);
            }
            EncryptedElementType encType = attr.getEncryptedAssertion();
            if (encType != null)
                throw logger.notImplementedYet("EncryptedElementType");
        }
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) ASTChoiceType(org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType) EncryptedElementType(org.keycloak.dom.saml.v2.assertion.EncryptedElementType)

Example 3 with EncryptedElementType

use of org.keycloak.dom.saml.v2.assertion.EncryptedElementType in project keycloak by keycloak.

the class AssertionUtil method decryptId.

public static void decryptId(final ResponseType responseType, final PrivateKey privateKey) throws ConfigurationException, ProcessingException, ParsingException {
    final STSubType subTypeElement = getSubTypeElement(responseType);
    if (subTypeElement == null) {
        return;
    }
    final EncryptedElementType encryptedID = subTypeElement.getEncryptedID();
    if (encryptedID == null) {
        return;
    }
    Element encryptedElement = encryptedID.getEncryptedElement();
    Document newDoc = DocumentUtil.createDocument();
    Node importedNode = newDoc.importNode(encryptedElement, true);
    newDoc.appendChild(importedNode);
    Element decryptedNameIdElement = XMLEncryptionUtil.decryptElementInDocument(newDoc, privateKey);
    final XMLEventReader xmlEventReader = StaxParserUtil.getXMLEventReader(DocumentUtil.getNodeAsStream(decryptedNameIdElement));
    NameIDType nameIDType = SAMLParserUtil.parseNameIDType(xmlEventReader);
    // Add unencrypted id, remove encrypted
    subTypeElement.addBaseID(nameIDType);
    subTypeElement.setEncryptedID(null);
}
Also used : STSubType(org.keycloak.dom.saml.v2.assertion.SubjectType.STSubType) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) XMLEventReader(javax.xml.stream.XMLEventReader) EncryptedElementType(org.keycloak.dom.saml.v2.assertion.EncryptedElementType) Document(org.w3c.dom.Document) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType)

Example 4 with EncryptedElementType

use of org.keycloak.dom.saml.v2.assertion.EncryptedElementType in project keycloak by keycloak.

the class SAMLSubjectParser method processSubElement.

@Override
protected void processSubElement(XMLEventReader xmlEventReader, SubjectType target, SAMLAssertionQNames element, StartElement elementDetail) throws ParsingException {
    SubjectType.STSubType subType;
    switch(element) {
        case NAMEID:
            NameIDType nameID = SAMLParserUtil.parseNameIDType(xmlEventReader);
            subType = new SubjectType.STSubType();
            subType.addBaseID(nameID);
            target.setSubType(subType);
            break;
        case ENCRYPTED_ID:
            Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);
            subType = new SubjectType.STSubType();
            subType.setEncryptedID(new EncryptedElementType(domElement));
            target.setSubType(subType);
            break;
        case SUBJECT_CONFIRMATION:
            target.addConfirmation(SAMLSubjectConfirmationParser.INSTANCE.parse(xmlEventReader));
            break;
        default:
            throw LOGGER.parserUnknownTag(StaxParserUtil.getElementName(elementDetail), elementDetail.getLocation());
    }
}
Also used : SubjectType(org.keycloak.dom.saml.v2.assertion.SubjectType) Element(org.w3c.dom.Element) StartElement(javax.xml.stream.events.StartElement) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) EncryptedElementType(org.keycloak.dom.saml.v2.assertion.EncryptedElementType)

Example 5 with EncryptedElementType

use of org.keycloak.dom.saml.v2.assertion.EncryptedElementType in project keycloak by keycloak.

the class SAMLSloRequestParser method processSubElement.

@Override
protected void processSubElement(XMLEventReader xmlEventReader, LogoutRequestType target, SAMLProtocolQNames element, StartElement elementDetail) throws ParsingException {
    switch(element) {
        case ISSUER:
        case SIGNATURE:
        case EXTENSIONS:
            parseCommonElements(element, elementDetail, xmlEventReader, target);
            break;
        case NAMEID:
            NameIDType nameID = SAMLParserUtil.parseNameIDType(xmlEventReader);
            target.setNameID(nameID);
            break;
        case ENCRYPTED_ID:
            Element domElement = StaxParserUtil.getDOMElement(xmlEventReader);
            target.setEncryptedID(new EncryptedElementType(domElement));
            break;
        case SESSION_INDEX:
            StaxParserUtil.getNextStartElement(xmlEventReader);
            target.addSessionIndex(StaxParserUtil.getElementText(xmlEventReader));
            break;
        default:
            throw LOGGER.parserUnknownTag(StaxParserUtil.getElementName(elementDetail), elementDetail.getLocation());
    }
}
Also used : Element(org.w3c.dom.Element) StartElement(javax.xml.stream.events.StartElement) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) EncryptedElementType(org.keycloak.dom.saml.v2.assertion.EncryptedElementType)

Aggregations

EncryptedElementType (org.keycloak.dom.saml.v2.assertion.EncryptedElementType)6 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)5 Element (org.w3c.dom.Element)4 StartElement (javax.xml.stream.events.StartElement)3 SubjectType (org.keycloak.dom.saml.v2.assertion.SubjectType)2 QName (javax.xml.namespace.QName)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 ASTChoiceType (org.keycloak.dom.saml.v2.assertion.AttributeStatementType.ASTChoiceType)1 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)1 BaseIDAbstractType (org.keycloak.dom.saml.v2.assertion.BaseIDAbstractType)1 SubjectConfirmationDataType (org.keycloak.dom.saml.v2.assertion.SubjectConfirmationDataType)1 SubjectConfirmationType (org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType)1 STSubType (org.keycloak.dom.saml.v2.assertion.SubjectType.STSubType)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1