예제 #1
0
  /** @see {@link ParserNamespaceSupport#parse(XMLEventReader)} */
  public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
    // Get the startelement
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, RESPONSE);

    ResponseType response = (ResponseType) parseBaseAttributes(startElement);

    while (xmlEventReader.hasNext()) {
      // Let us peek at the next start element
      startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (startElement == null) break;
      String elementName = StaxParserUtil.getStartElementName(startElement);

      if (JBossSAMLConstants.ISSUER.get().equals(elementName)) {
        startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
        NameIDType issuer = new NameIDType();
        issuer.setValue(StaxParserUtil.getElementText(xmlEventReader));
        response.setIssuer(issuer);
      } else if (JBossSAMLConstants.SIGNATURE.get().equals(elementName)) {
        Element sig = StaxParserUtil.getDOMElement(xmlEventReader);
        response.setSignature(sig);
      } else if (JBossSAMLConstants.ASSERTION.get().equals(elementName)) {
        SAMLAssertionParser assertionParser = new SAMLAssertionParser();
        response.addAssertion(
            new RTChoiceType((AssertionType) assertionParser.parse(xmlEventReader)));
      } else if (JBossSAMLConstants.STATUS.get().equals(elementName)) {
        response.setStatus(parseStatus(xmlEventReader));
      } else if (JBossSAMLConstants.ENCRYPTED_ASSERTION.get().equals(elementName)) {
        Element encryptedAssertion = StaxParserUtil.getDOMElement(xmlEventReader);
        response.addAssertion(new RTChoiceType(new EncryptedAssertionType(encryptedAssertion)));
      } else throw logger.parserUnknownTag(elementName, startElement.getLocation());
    }

    return response;
  }
 /**
  * Creates a {@code NameIDType} instance with the specified values.
  *
  * @param format a {@code String} representing the name format.
  * @param qualifier a {@code String} representing the name qualifier.
  * @param value a {@code String} representing the name value.
  * @return the constructed {@code NameIDType} instance.
  */
 public static NameIDType createNameID(String format, String qualifier, String value) {
   NameIDType nameID = new NameIDType();
   if (format != null) nameID.setFormat(URI.create(format));
   nameID.setNameQualifier(qualifier);
   nameID.setValue(value);
   return nameID;
 }
  protected void parseCommonElements(
      StartElement startElement, XMLEventReader xmlEventReader, RequestAbstractType request)
      throws ParsingException {
    if (startElement == null) throw new IllegalArgumentException(ErrorCodes.NULL_START_ELEMENT);
    String elementName = StaxParserUtil.getStartElementName(startElement);

    if (JBossSAMLConstants.ISSUER.get().equals(elementName)) {
      startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
      NameIDType issuer = new NameIDType();
      issuer.setValue(StaxParserUtil.getElementText(xmlEventReader));
      request.setIssuer(issuer);
    } else if (JBossSAMLConstants.SIGNATURE.get().equals(elementName)) {
      request.setSignature(StaxParserUtil.getDOMElement(xmlEventReader));
    }
  }