use of org.keycloak.dom.saml.v2.assertion.NameIDType 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.NameIDType in project keycloak by keycloak.
the class BaseWriter method writeAttributeTypeWithoutRootTag.
public void writeAttributeTypeWithoutRootTag(AttributeType attributeType) throws ProcessingException {
String attributeName = attributeType.getName();
if (attributeName != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.NAME.get(), attributeName);
}
String friendlyName = attributeType.getFriendlyName();
if (StringUtil.isNotNull(friendlyName)) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.FRIENDLY_NAME.get(), friendlyName);
}
String nameFormat = attributeType.getNameFormat();
if (StringUtil.isNotNull(nameFormat)) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.NAME_FORMAT.get(), nameFormat);
}
// Take care of other attributes such as x500:encoding
Map<QName, String> otherAttribs = attributeType.getOtherAttributes();
if (otherAttribs != null) {
List<String> nameSpacesDealt = new ArrayList<>();
Iterator<QName> keySet = otherAttribs.keySet().iterator();
while (keySet != null && keySet.hasNext()) {
QName qname = keySet.next();
String ns = qname.getNamespaceURI();
if (!nameSpacesDealt.contains(ns)) {
StaxUtil.writeNameSpace(writer, qname.getPrefix(), ns);
nameSpacesDealt.add(ns);
}
String attribValue = otherAttribs.get(qname);
StaxUtil.writeAttribute(writer, qname, attribValue);
}
}
List<Object> attributeValues = attributeType.getAttributeValue();
if (attributeValues != null) {
for (Object attributeValue : attributeValues) {
if (attributeValue != null) {
if (attributeValue instanceof String) {
writeStringAttributeValue((String) attributeValue);
} else if (attributeValue instanceof NameIDType) {
writeNameIDTypeAttributeValue((NameIDType) attributeValue);
} else if (attributeValue instanceof XMLGregorianCalendar) {
writeDateAttributeValue((XMLGregorianCalendar) attributeValue);
} else if (attributeValue instanceof Element) {
writeElementAttributeValue((Element) attributeValue);
} else
throw logger.writerUnsupportedAttributeValueError(attributeValue.getClass().getName());
} else {
writeStringAttributeValue(null);
}
}
}
}
use of org.keycloak.dom.saml.v2.assertion.NameIDType in project keycloak by keycloak.
the class SAMLRequestWriter method write.
public void write(AttributeQueryType request) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.ATTRIBUTE_QUERY.get(), PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
// Attributes
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), request.getID());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), request.getVersion());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
URI destination = request.getDestination();
if (destination != null)
StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
String consent = request.getConsent();
if (StringUtil.isNotNull(consent))
StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
NameIDType issuer = request.getIssuer();
if (issuer != null) {
write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX));
}
Element sig = request.getSignature();
if (sig != null) {
StaxUtil.writeDOMElement(writer, sig);
}
ExtensionsType extensions = request.getExtensions();
if (extensions != null && !extensions.getAny().isEmpty()) {
write(extensions);
}
SubjectType subject = request.getSubject();
if (subject != null) {
write(subject);
}
List<AttributeType> attributes = request.getAttribute();
for (AttributeType attr : attributes) {
write(attr);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v2.assertion.NameIDType in project keycloak by keycloak.
the class SAMLRequestWriter method write.
public void write(ArtifactResolveType request) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.ARTIFACT_RESOLVE.get(), PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
// Attributes
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), request.getID());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), request.getVersion());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
URI destination = request.getDestination();
if (destination != null)
StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
String consent = request.getConsent();
if (StringUtil.isNotNull(consent))
StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
NameIDType issuer = request.getIssuer();
if (issuer != null) {
write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX));
}
Element sig = request.getSignature();
if (sig != null) {
StaxUtil.writeDOMElement(writer, sig);
}
ExtensionsType extensions = request.getExtensions();
if (extensions != null && !extensions.getAny().isEmpty()) {
write(extensions);
}
String artifact = request.getArtifact();
if (StringUtil.isNotNull(artifact)) {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.ARTIFACT.get(), PROTOCOL_NSURI.get());
StaxUtil.writeCharacters(writer, artifact);
StaxUtil.writeEndElement(writer);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
use of org.keycloak.dom.saml.v2.assertion.NameIDType in project keycloak by keycloak.
the class SAMLRequestWriter method write.
/**
* Write a {@code AuthnRequestType } to stream
*
* @param request
*
* @throws org.keycloak.saml.common.exceptions.ProcessingException
*/
public void write(AuthnRequestType request) throws ProcessingException {
StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.AUTHN_REQUEST.get(), PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
// Attributes
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), request.getID());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), request.getVersion());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
URI destination = request.getDestination();
if (destination != null)
StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
String consent = request.getConsent();
if (StringUtil.isNotNull(consent))
StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
URI assertionURL = request.getAssertionConsumerServiceURL();
if (assertionURL != null)
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_URL.get(), assertionURL.toASCIIString());
Boolean forceAuthn = request.isForceAuthn();
if (forceAuthn != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.FORCE_AUTHN.get(), forceAuthn.toString());
}
Boolean isPassive = request.isIsPassive();
// maximize compatibility we emit it only if it is set to true
if (isPassive != null && isPassive == true) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.IS_PASSIVE.get(), isPassive.toString());
}
URI protocolBinding = request.getProtocolBinding();
if (protocolBinding != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROTOCOL_BINDING.get(), protocolBinding.toString());
}
Integer assertionIndex = request.getAssertionConsumerServiceIndex();
if (assertionIndex != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ASSERTION_CONSUMER_SERVICE_INDEX.get(), assertionIndex.toString());
}
Integer attrIndex = request.getAttributeConsumingServiceIndex();
if (attrIndex != null) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.ATTRIBUTE_CONSUMING_SERVICE_INDEX.get(), attrIndex.toString());
}
String providerName = request.getProviderName();
if (StringUtil.isNotNull(providerName)) {
StaxUtil.writeAttribute(writer, JBossSAMLConstants.PROVIDER_NAME.get(), providerName);
}
NameIDType issuer = request.getIssuer();
if (issuer != null) {
write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX), false);
}
SubjectType subject = request.getSubject();
if (subject != null) {
write(subject);
}
Element sig = request.getSignature();
if (sig != null) {
StaxUtil.writeDOMElement(writer, sig);
}
ExtensionsType extensions = request.getExtensions();
if (extensions != null && !extensions.getAny().isEmpty()) {
write(extensions);
}
NameIDPolicyType nameIDPolicy = request.getNameIDPolicy();
if (nameIDPolicy != null) {
write(nameIDPolicy);
}
RequestedAuthnContextType requestedAuthnContext = request.getRequestedAuthnContext();
if (requestedAuthnContext != null) {
write(requestedAuthnContext);
}
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
Aggregations