예제 #1
0
  /**
   * Parse an {@code AttributeType}
   *
   * @param xmlEventReader
   * @return
   * @throws ParsingException
   */
  public static AttributeType parseAttribute(XMLEventReader xmlEventReader)
      throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, JBossSAMLConstants.ATTRIBUTE.get());
    AttributeType attributeType = null;

    Attribute name = startElement.getAttributeByName(new QName(JBossSAMLConstants.NAME.get()));
    if (name == null) throw logger.parserRequiredAttribute("Name");
    attributeType = new AttributeType(StaxParserUtil.getAttributeValue(name));

    parseAttributeType(
        xmlEventReader, startElement, JBossSAMLConstants.ATTRIBUTE.get(), attributeType);

    return attributeType;
  }
예제 #2
0
  /**
   * Parse an {@code AttributeStatementType}
   *
   * @param xmlEventReader
   * @return
   * @throws ParsingException
   */
  public static AttributeStatementType parseAttributeStatement(XMLEventReader xmlEventReader)
      throws ParsingException {
    AttributeStatementType attributeStatementType = new AttributeStatementType();

    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    String ATTRIBSTATEMT = JBossSAMLConstants.ATTRIBUTE_STATEMENT.get();
    StaxParserUtil.validate(startElement, ATTRIBSTATEMT);

    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent instanceof EndElement) {
        EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
        StaxParserUtil.validate(endElement, JBossSAMLConstants.ATTRIBUTE_STATEMENT.get());
        break;
      }
      // Get the next start element
      startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
      String tag = startElement.getName().getLocalPart();
      if (JBossSAMLConstants.ATTRIBUTE.get().equals(tag)) {
        AttributeType attribute = parseAttribute(xmlEventReader);
        attributeStatementType.addAttribute(new ASTChoiceType(attribute));
      } else throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
    return attributeStatementType;
  }
예제 #3
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;
  }
예제 #4
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());
    }
  }
예제 #5
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());
    }
  }