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čéíöüßäöü"));
}
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);
}
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;
}
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;
}
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;
}
Aggregations