Search in sources :

Example 1 with SubjectConfirmationType

use of xmlbeans.org.oasis.saml2.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 2 with SubjectConfirmationType

use of xmlbeans.org.oasis.saml2.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 3 with SubjectConfirmationType

use of xmlbeans.org.oasis.saml2.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)

Example 4 with SubjectConfirmationType

use of xmlbeans.org.oasis.saml2.assertion.SubjectConfirmationType in project keycloak by keycloak.

the class SAMLSubjectConfirmationParser method instantiateElement.

@Override
protected SubjectConfirmationType instantiateElement(XMLEventReader xmlEventReader, StartElement element) throws ParsingException {
    final SubjectConfirmationType res = new SubjectConfirmationType();
    res.setMethod(StaxParserUtil.getAttributeValue(element, SAMLAssertionQNames.ATTR_METHOD));
    return res;
}
Also used : SubjectConfirmationType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType)

Example 5 with SubjectConfirmationType

use of xmlbeans.org.oasis.saml2.assertion.SubjectConfirmationType in project keycloak by keycloak.

the class SAMLEndpoint method validateInResponseToAttribute.

private boolean validateInResponseToAttribute(ResponseType responseType, String expectedRequestId) {
    // If we are not expecting a request ID, don't bother
    if (expectedRequestId == null || expectedRequestId.isEmpty())
        return true;
    // We are expecting a request ID so we are in SP-initiated login, attribute InResponseTo must be present
    if (responseType.getInResponseTo() == null) {
        logger.error("Response Validation Error: InResponseTo attribute was expected but not present in received response");
        return false;
    }
    // Attribute is present, proceed with validation
    // 1) Attribute Response > InResponseTo must not be empty
    String responseInResponseToValue = responseType.getInResponseTo();
    if (responseInResponseToValue.isEmpty()) {
        logger.error("Response Validation Error: InResponseTo attribute was expected but it is empty in received response");
        return false;
    }
    // 2) Attribute Response > InResponseTo must match request ID
    if (!responseInResponseToValue.equals(expectedRequestId)) {
        logger.error("Response Validation Error: received InResponseTo attribute does not match the expected request ID");
        return false;
    }
    // If present, Assertion > Subject > Confirmation > SubjectConfirmationData > InResponseTo must also be validated
    if (responseType.getAssertions().isEmpty())
        return true;
    SubjectType subjectElement = responseType.getAssertions().get(0).getAssertion().getSubject();
    if (subjectElement != null) {
        if (subjectElement.getConfirmation() != null && !subjectElement.getConfirmation().isEmpty()) {
            SubjectConfirmationType subjectConfirmationElement = subjectElement.getConfirmation().get(0);
            if (subjectConfirmationElement != null) {
                SubjectConfirmationDataType subjectConfirmationDataElement = subjectConfirmationElement.getSubjectConfirmationData();
                if (subjectConfirmationDataElement != null) {
                    if (subjectConfirmationDataElement.getInResponseTo() != null) {
                        // 3) Assertion > Subject > Confirmation > SubjectConfirmationData > InResponseTo is empty
                        String subjectConfirmationDataInResponseToValue = subjectConfirmationDataElement.getInResponseTo();
                        if (subjectConfirmationDataInResponseToValue.isEmpty()) {
                            logger.error("Response Validation Error: SubjectConfirmationData InResponseTo attribute was expected but it is empty in received response");
                            return false;
                        }
                        // 4) Assertion > Subject > Confirmation > SubjectConfirmationData > InResponseTo does not match request ID
                        if (!subjectConfirmationDataInResponseToValue.equals(expectedRequestId)) {
                            logger.error("Response Validation Error: received SubjectConfirmationData InResponseTo attribute does not match the expected request ID");
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : SubjectType(org.keycloak.dom.saml.v2.assertion.SubjectType) SubjectConfirmationDataType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationDataType) SubjectConfirmationType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType)

Aggregations

SubjectConfirmationType (org.keycloak.dom.saml.v2.assertion.SubjectConfirmationType)7 SubjectType (org.keycloak.dom.saml.v2.assertion.SubjectType)4 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)3 SubjectConfirmationDataType (org.keycloak.dom.saml.v2.assertion.SubjectConfirmationDataType)3 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)3 Test (org.junit.Test)2 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)2 ConditionsType (org.keycloak.dom.saml.v2.assertion.ConditionsType)2 EncryptedAssertionType (org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType)2 StatementAbstractType (org.keycloak.dom.saml.v2.assertion.StatementAbstractType)2 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 QName (javax.xml.namespace.QName)1 Matchers.greaterThan (org.hamcrest.Matchers.greaterThan)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)1 Assert (org.junit.Assert)1