use of javax.xml.stream.events.Attribute in project keycloak by keycloak.
the class SAMLAttributeValueParser method parse.
@Override
public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
StartElement element = StaxParserUtil.getNextStartElement(xmlEventReader);
StaxParserUtil.validate(element, SAMLAssertionQNames.ATTRIBUTE_VALUE.getQName());
Attribute nil = element.getAttributeByName(NIL);
if (nil != null) {
String nilValue = StaxParserUtil.getAttributeValue(nil);
if (nilValue != null && (nilValue.equalsIgnoreCase("true") || nilValue.equals("1"))) {
String elementText = StaxParserUtil.getElementText(xmlEventReader);
if (elementText == null || elementText.isEmpty()) {
return null;
} else {
throw logger.nullValueError("nil attribute is not in SAML20 format");
}
} else {
throw logger.parserRequiredAttribute(JBossSAMLURIConstants.XSI_PREFIX.get() + ":nil");
}
}
Attribute type = element.getAttributeByName(XSI_TYPE);
if (type == null) {
if (StaxParserUtil.hasTextAhead(xmlEventReader)) {
return StaxParserUtil.getElementText(xmlEventReader);
}
// Else we may have Child Element
XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
if (xmlEvent instanceof StartElement) {
element = (StartElement) xmlEvent;
final QName qName = element.getName();
if (Objects.equals(qName, SAMLAssertionQNames.NAMEID.getQName())) {
return SAMLParserUtil.parseNameIDType(xmlEventReader);
}
} else if (xmlEvent instanceof EndElement) {
return "";
}
// when no type attribute assigned -> assume anyType
return parseAnyTypeAsString(xmlEventReader);
}
// RK Added an additional type check for base64Binary type as calheers is passing this type
String typeValue = StaxParserUtil.getAttributeValue(type);
if (typeValue.contains(":string")) {
return StaxParserUtil.getElementText(xmlEventReader);
} else if (typeValue.contains(":anyType")) {
return parseAnyTypeAsString(xmlEventReader);
} else if (typeValue.contains(":base64Binary")) {
return StaxParserUtil.getElementText(xmlEventReader);
} else if (typeValue.contains(":date")) {
return XMLTimeUtil.parse(StaxParserUtil.getElementText(xmlEventReader));
} else if (typeValue.contains(":boolean")) {
return StaxParserUtil.getElementText(xmlEventReader);
}
// KEYCLOAK-18417: Simply ignore unknown types
logger.debug("Skipping attribute value of unsupported type " + typeValue);
StaxParserUtil.bypassElementBlock(xmlEventReader);
return null;
}
use of javax.xml.stream.events.Attribute in project keycloak by keycloak.
the class StaxParserUtil method getUriAttributeValue.
/**
* Get the Attribute value
*
* @param startElement
* @param tag localpart of the qname of the attribute
*
* @return
*/
public static URI getUriAttributeValue(StartElement startElement, HasQName attrName) {
Attribute attr = startElement.getAttributeByName(attrName.getQName());
String value = getAttributeValue(attr);
return value == null ? null : URI.create(value);
}
use of javax.xml.stream.events.Attribute in project keycloak by keycloak.
the class StaxParserUtil method getXmlTimeAttributeValue.
/**
* Get the Attribute value
*
* @param startElement
* @param tag localpart of the qname of the attribute
*
* @return
*/
public static XMLGregorianCalendar getXmlTimeAttributeValue(StartElement startElement, HasQName attrName) throws ParsingException {
Attribute attr = startElement.getAttributeByName(attrName.getQName());
String value = getAttributeValue(attr);
return value == null ? null : XMLTimeUtil.parse(value);
}
use of javax.xml.stream.events.Attribute in project hibernate-orm by hibernate.
the class JpaOrmXmlEventReader method wrap.
private StartElement wrap(StartElement startElement) {
List<Attribute> newElementAttributeList = mapAttributes(startElement);
List<Namespace> newNamespaceList = mapNamespaces(startElement);
// Transfer the location info from the incoming event to the event factory
// so that the event we ask it to generate for us has the same location info
xmlEventFactory.setLocation(startElement.getLocation());
return xmlEventFactory.createStartElement(new QName(MappingXsdSupport.INSTANCE.latestJpaDescriptor().getNamespaceUri(), startElement.getName().getLocalPart()), newElementAttributeList.iterator(), newNamespaceList.iterator());
}
use of javax.xml.stream.events.Attribute in project sirix by sirixdb.
the class AbstractTraverseModel method fillAttributes.
/**
* Fill an attribute list with entries.
*
* @param rtx
* Sirix {@link NodeReadTrx}
* @return {@link List} of {@link Attribute}s
*/
protected List<Attribute> fillAttributes(final NodeReadTrx rtx) {
assert rtx != null;
final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
// attributes in the axis.
assert rtx.getKind() == Kind.ELEMENT;
final int attNumber = rtx.getAttributeCount();
final List<Attribute> attributes = new ArrayList<>(attNumber);
for (int i = 0; i < attNumber; i++) {
rtx.moveToAttribute(i);
final QNm name = rtx.getName();
attributes.add(eventFactory.createAttribute(new QName(name.getNamespaceURI(), name.getLocalName(), name.getPrefix()), rtx.getValue()));
rtx.moveToParent();
}
return attributes;
}
Aggregations