Пример #1
0
  /**
   * Parse an {@code AttributeType}
   *
   * @param xmlEventReader
   * @throws ParsingException
   */
  public static void parseAttributeType(
      XMLEventReader xmlEventReader,
      StartElement startElement,
      String rootTag,
      AttributeType attributeType)
      throws ParsingException {
    // Look for X500 Encoding
    QName x500EncodingName =
        new QName(
            JBossSAMLURIConstants.X500_NSURI.get(),
            JBossSAMLConstants.ENCODING.get(),
            JBossSAMLURIConstants.X500_PREFIX.get());
    Attribute x500EncodingAttr = startElement.getAttributeByName(x500EncodingName);

    if (x500EncodingAttr != null) {
      attributeType
          .getOtherAttributes()
          .put(x500EncodingAttr.getName(), StaxParserUtil.getAttributeValue(x500EncodingAttr));
    }

    Attribute friendlyName =
        startElement.getAttributeByName(new QName(JBossSAMLConstants.FRIENDLY_NAME.get()));
    if (friendlyName != null)
      attributeType.setFriendlyName(StaxParserUtil.getAttributeValue(friendlyName));

    Attribute nameFormat =
        startElement.getAttributeByName(new QName(JBossSAMLConstants.NAME_FORMAT.get()));
    if (nameFormat != null)
      attributeType.setNameFormat(StaxParserUtil.getAttributeValue(nameFormat));

    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent instanceof EndElement) {
        EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader);
        if (StaxParserUtil.matches(end, rootTag)) break;
      }
      startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (startElement == null) break;
      String tag = StaxParserUtil.getStartElementName(startElement);

      if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag)) break;

      if (JBossSAMLConstants.ATTRIBUTE_VALUE.get().equals(tag)) {
        Object attributeValue = parseAttributeValue(xmlEventReader);
        attributeType.addAttributeValue(attributeValue);
      } else throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
  }
Пример #2
0
  /**
   * Parse Attribute value
   *
   * @param xmlEventReader
   * @return
   * @throws ParsingException
   */
  public static Object parseAttributeValue(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE_VALUE.get());

    Attribute type =
        startElement.getAttributeByName(
            new QName(JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xsi"));
    if (type == null) {
      return StaxParserUtil.getElementText(xmlEventReader);
    }

    String typeValue = StaxParserUtil.getAttributeValue(type);
    if (typeValue.contains(":string")) {
      return StaxParserUtil.getElementText(xmlEventReader);
    }

    throw logger.parserUnknownXSI(typeValue);
  }
Пример #3
0
  /**
   * Parse Attribute value
   *
   * @param xmlEventReader
   * @return
   * @throws ParsingException
   */
  public static Object parseAttributeValue(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE_VALUE.get());

    Attribute type =
        startElement.getAttributeByName(
            new QName(JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xsi"));
    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) {
        startElement = (StartElement) xmlEvent;
        String tag = StaxParserUtil.getStartElementName(startElement);
        if (tag.equals(JBossSAMLConstants.NAMEID.get())) {
          return parseNameIDType(xmlEventReader);
        }
      } else if (xmlEvent instanceof EndElement) {
        return "";
      }

      throw logger.unsupportedType(StaxParserUtil.getStartElementName(startElement));
    }
    //      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")) {
      // TODO: for now assume that it is a text value that can be parsed and set as the attribute
      // value
      return StaxParserUtil.getElementText(xmlEventReader);
    } else if (typeValue.contains(":base64Binary")) {
      return StaxParserUtil.getElementText(xmlEventReader);
    }

    throw logger.parserUnknownXSI(typeValue);
  }
Пример #4
0
  /**
   * Parse an {@code SAML11AttributeType}
   *
   * @param xmlEventReader
   * @throws ParsingException
   */
  public static void parseAttributeType(
      XMLEventReader xmlEventReader,
      StartElement startElement,
      String rootTag,
      SAML11AttributeType attributeType)
      throws ParsingException {
    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent instanceof EndElement) {
        EndElement end = StaxParserUtil.getNextEndElement(xmlEventReader);
        if (StaxParserUtil.matches(end, rootTag)) break;
      }
      startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (startElement == null) break;
      String tag = StaxParserUtil.getStartElementName(startElement);

      if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag)) break;

      if (JBossSAMLConstants.ATTRIBUTE_VALUE.get().equals(tag)) {
        Object attributeValue = parseAttributeValue(xmlEventReader);
        attributeType.add(attributeValue);
      } else throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
  }