Esempio n. 1
0
  /**
   * Parse a {@link SAML11AttributeType}
   *
   * @param xmlEventReader
   * @return
   * @throws ParsingException
   */
  public static SAML11AttributeType parseSAML11Attribute(XMLEventReader xmlEventReader)
      throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE.get());
    SAML11AttributeType attributeType = null;

    Attribute name = startElement.getAttributeByName(new QName(SAML11Constants.ATTRIBUTE_NAME));
    if (name == null) throw logger.parserRequiredAttribute("Name");
    String attribName = StaxParserUtil.getAttributeValue(name);

    Attribute namesp =
        startElement.getAttributeByName(new QName(SAML11Constants.ATTRIBUTE_NAMESPACE));
    if (namesp == null) throw logger.parserRequiredAttribute("Namespace");
    String attribNamespace = StaxParserUtil.getAttributeValue(namesp);

    attributeType = new SAML11AttributeType(attribName, URI.create(attribNamespace));

    attributeType.add(parseAttributeValue(xmlEventReader));

    parseAttributeType(
        xmlEventReader, startElement, JBossSAMLConstants.ATTRIBUTE.get(), attributeType);
    return attributeType;
  }
Esempio n. 2
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());
    }
  }