Search in sources :

Example 1 with SubjectConfirmationType

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

the class SAMLParserTest method testSaml20AuthnResponseNonAsciiNameDefaultLatin2.

@Test
public void testSaml20AuthnResponseNonAsciiNameDefaultLatin2() throws Exception {
    ResponseType rt = assertParsed("KEYCLOAK-3971-8859-2-in-header-authnresponse.xml", ResponseType.class);
    assertThat(rt.getAssertions().size(), is(1));
    final AssertionType assertion = rt.getAssertions().get(0).getAssertion();
    final SubjectType subject = assertion.getSubject();
    assertThat(subject.getConfirmation(), hasSize(1));
    SubjectConfirmationType confirmation = subject.getConfirmation().get(0);
    assertThat(confirmation.getMethod(), is(JBossSAMLURIConstants.SUBJECT_CONFIRMATION_BEARER.get()));
    assertThat(confirmation.getSubjectConfirmationData(), notNullValue());
    assertThat(confirmation.getSubjectConfirmationData().getInResponseTo(), is("ID_cc0ff6f7-b481-4c98-9a79-481d50958290"));
    assertThat(confirmation.getSubjectConfirmationData().getRecipient(), is("http://localhost:8080/sales-post-sig/saml"));
    assertThat(subject.getSubType().getBaseID(), instanceOf(NameIDType.class));
    NameIDType nameId = (NameIDType) subject.getSubType().getBaseID();
    assertThat(nameId.getValue(), is("ročéíöüßäöü"));
}
Also used : SubjectType(org.keycloak.dom.saml.v2.assertion.SubjectType) SubjectConfirmationType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType) EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Test(org.junit.Test)

Example 2 with SubjectConfirmationType

use of org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType 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 3 with SubjectConfirmationType

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

the class SAML11ParserUtil method parseSAML11SubjectConfirmation.

/**
 * Parse the {@link org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType}
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
public static SAML11SubjectConfirmationType parseSAML11SubjectConfirmation(XMLEventReader xmlEventReader) throws ParsingException {
    SAML11SubjectConfirmationType subjectConfirmationType = new SAML11SubjectConfirmationType();
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    // There may be additional things under subject confirmation
    while (xmlEventReader.hasNext()) {
        XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
        if (xmlEvent instanceof EndElement) {
            EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
            StaxParserUtil.validate(endElement, JBossSAMLConstants.SUBJECT_CONFIRMATION.get());
            break;
        }
        if (xmlEvent instanceof StartElement) {
            startElement = (StartElement) xmlEvent;
            String startTag = StaxParserUtil.getElementName(startElement);
            if (startTag.equals(SAML11Constants.CONFIRMATION_METHOD)) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                String method = StaxParserUtil.getElementText(xmlEventReader);
                subjectConfirmationType.addConfirmationMethod(URI.create(method));
            } else if (startTag.equals(JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get())) {
                startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
                SubjectConfirmationDataType subjectConfirmationData = parseSubjectConfirmationData(xmlEventReader);
                subjectConfirmationType.setSubjectConfirmationData(subjectConfirmationData);
            } else if (startTag.equals(JBossSAMLConstants.KEY_INFO.get())) {
                Element keyInfo = StaxParserUtil.getDOMElement(xmlEventReader);
                subjectConfirmationType.setKeyInfo(keyInfo);
            } else
                throw logger.parserUnknownTag(startTag, startElement.getLocation());
        }
    }
    return subjectConfirmationType;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SubjectConfirmationDataType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationDataType) SAML11SubjectConfirmationType(org.keycloak.dom.saml.v1.assertion.SAML11SubjectConfirmationType) EndElement(javax.xml.stream.events.EndElement) EndElement(javax.xml.stream.events.EndElement) StartElement(javax.xml.stream.events.StartElement) Element(org.w3c.dom.Element) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 4 with SubjectConfirmationType

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

the class SAMLAssertionFactory method createSubject.

/**
 * <p>
 * Creates a {@code SubjectType} object with the specified values.
 * </p>
 *
 * @param nameID the identifier of the subject.
 * @param confirmation the {@code SubjectConfirmationType} that is used to establish the correspondence between the
 * subject
 * and claims of SAML statements.
 *
 * @return the constructed {@code SubjectType} instance.
 */
public static SubjectType createSubject(NameIDType nameID, SubjectConfirmationType confirmation) {
    SubjectType subject = new SubjectType();
    if (nameID != null) {
        SubjectType.STSubType subType = new SubjectType.STSubType();
        subType.addConfirmation(confirmation);
        subType.addBaseID(nameID);
        subject.setSubType(subType);
    }
    return subject;
}
Also used : SubjectType(org.keycloak.dom.saml.v2.assertion.SubjectType)

Example 5 with SubjectConfirmationType

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

the class SAMLAssertionFactory method createSubjectConfirmation.

/**
 * <p>
 * Creates a {@code SubjectConfirmationType} object with the specified values.
 * </p>
 *
 * @param nameID the identifier of the confirmation.
 * @param confirmationMethod a {@code String} representing the confirmation method.
 * @param keyInfoData the {@code KeyInfoConfirmationDataType} instance that contains the proof of possession key.
 *
 * @return the constructed {@code SubjectConfirmationType} instance.
 */
public static SubjectConfirmationType createSubjectConfirmation(NameIDType nameID, String confirmationMethod, KeyInfoConfirmationDataType keyInfoData) {
    SubjectConfirmationType subjectConfirmation = new SubjectConfirmationType();
    subjectConfirmation.setNameID(nameID);
    subjectConfirmation.setMethod(confirmationMethod);
    subjectConfirmation.setSubjectConfirmationData(keyInfoData);
    return subjectConfirmation;
}
Also used : SubjectConfirmationType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType)

Aggregations

SubjectConfirmationType (org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType)7 SubjectConfirmationDataType (org.keycloak.dom.saml.v2.assertion.SubjectConfirmationDataType)6 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)5 SubjectType (org.keycloak.dom.saml.v2.assertion.SubjectType)5 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)3 QName (javax.xml.namespace.QName)2 StartElement (javax.xml.stream.events.StartElement)2 Test (org.junit.Test)2 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)2 BaseIDAbstractType (org.keycloak.dom.saml.v2.assertion.BaseIDAbstractType)2 ConditionsType (org.keycloak.dom.saml.v2.assertion.ConditionsType)2 EncryptedAssertionType (org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType)2 EncryptedElementType (org.keycloak.dom.saml.v2.assertion.EncryptedElementType)2 StatementAbstractType (org.keycloak.dom.saml.v2.assertion.StatementAbstractType)2 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)2 Element (org.w3c.dom.Element)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1