Exemplo n.º 1
0
  /**
   * Parses the {@code KeyProvider} section of the STS configuration file. This section is used to
   * setup the keystore \ that will be used to sign and encrypt security tokens.
   *
   * @param xmlEventReader the reader used to parse the XML configuration file.
   * @return a {@code KeyProviderType} instance that contains the parsed data.
   * @throws ParsingException if an error occurs while parsing the XML file.
   */
  private KeyProviderType parseKeyProvider(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, KEY_PROVIDER_ELEMENT);

    KeyProviderType keyProvider = new KeyProviderType();
    // get the key provider class name attribute.
    QName attributeQName = new QName("", CLASS_NAME_ATTRIB);
    Attribute attribute = startElement.getAttributeByName(attributeQName);
    if (attribute == null) throw logger.parserRequiredAttribute("ClassName");
    keyProvider.setClassName(StaxParserUtil.getAttributeValue(attribute));

    // parse the inner elements.
    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent == null) break;
      if (xmlEvent instanceof EndElement) {
        EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
        String endElementName = StaxParserUtil.getEndElementName(endElement);
        if (endElementName.equals(KEY_PROVIDER_ELEMENT)) break;
        else throw logger.parserUnknownEndElement(endElementName);
      }

      StartElement subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (subEvent == null) break;
      String elementName = StaxParserUtil.getStartElementName(subEvent);

      if (SIGNING_ALIAS_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        if (!StaxParserUtil.hasTextAhead(xmlEventReader))
          throw logger.parserExpectedTextValue("SigningAlias");
        keyProvider.setSigningAlias(StaxParserUtil.getElementText(xmlEventReader));
      } else if (VALIDATING_ALIAS_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        KeyValueType keyValue = new KeyValueType();
        // parse the key and value attributes.
        attributeQName = new QName("", KEY_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) keyValue.setKey(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", VALUE_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) keyValue.setValue(StaxParserUtil.getAttributeValue(attribute));

        EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
        StaxParserUtil.validate(endElement, VALIDATING_ALIAS_ELEMENT);
        keyProvider.add(keyValue);
      } else if (AUTH_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        AuthPropertyType authProperty = new AuthPropertyType();
        // parse the key and value attributes.
        attributeQName = new QName("", KEY_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) authProperty.setKey(StaxParserUtil.getAttributeValue(attribute));
        attributeQName = new QName("", VALUE_ATTRIB);
        attribute = subEvent.getAttributeByName(attributeQName);
        if (attribute != null) authProperty.setValue(StaxParserUtil.getAttributeValue(attribute));

        EndElement endElement = StaxParserUtil.getNextEndElement(xmlEventReader);
        StaxParserUtil.validate(endElement, AUTH_ELEMENT);
        keyProvider.add(authProperty);
      } else throw logger.parserUnknownTag(elementName, subEvent.getLocation());
    }
    return keyProvider;
  }
Exemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see org.picketlink.identity.federation.core.parsers.ParserNamespaceSupport#parse(javax.xml.stream.XMLEventReader)
   */
  public Object parse(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, ROOT_ELEMENT);
    STSType configType = new STSType();

    // parse and set the root element attributes.
    QName attributeQName = new QName("", STS_NAME_ATTRIB);
    Attribute attribute = startElement.getAttributeByName(attributeQName);
    if (attribute != null) configType.setSTSName(StaxParserUtil.getAttributeValue(attribute));

    attributeQName = new QName("", TOKEN_TIMEOUT_ATTRIB);
    attribute = startElement.getAttributeByName(attributeQName);
    if (attribute != null)
      configType.setTokenTimeout(Integer.valueOf(StaxParserUtil.getAttributeValue(attribute)));

    attributeQName = new QName("", CLOCK_SKEW_ATTRIB);
    attribute = startElement.getAttributeByName(attributeQName);
    if (attribute != null)
      configType.setClockSkew(Integer.valueOf(StaxParserUtil.getAttributeValue(attribute)));

    attributeQName = new QName("", SIGN_TOKEN_ATTRIB);
    attribute = startElement.getAttributeByName(attributeQName);
    if (attribute != null)
      configType.setSignToken(Boolean.valueOf(StaxParserUtil.getAttributeValue(attribute)));

    attributeQName = new QName("", ENCRYPT_TOKEN_ATTRIB);
    attribute = startElement.getAttributeByName(attributeQName);
    if (attribute != null)
      configType.setEncryptToken(Boolean.valueOf(StaxParserUtil.getAttributeValue(attribute)));

    attributeQName = new QName("", CANON_METHOD_ATTRIB);
    attribute = startElement.getAttributeByName(attributeQName);
    if (attribute != null)
      configType.setCanonicalizationMethod(StaxParserUtil.getAttributeValue(attribute));

    // parse the inner elements.
    while (xmlEventReader.hasNext()) {
      XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
      if (xmlEvent == null) break;
      if (xmlEvent instanceof EndElement) {
        EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
        String endElementName = StaxParserUtil.getEndElementName(endElement);
        if (endElementName.equals(ROOT_ELEMENT)) break;
        else throw logger.parserUnknownEndElement(endElementName);
      }

      StartElement subEvent = StaxParserUtil.peekNextStartElement(xmlEventReader);
      if (subEvent == null) break;
      String elementName = StaxParserUtil.getStartElementName(subEvent);
      if (KEY_PROVIDER_ELEMENT.equalsIgnoreCase(elementName)) {
        configType.setKeyProvider(this.parseKeyProvider(xmlEventReader));
      } else if (REQUEST_HANDLER_ELEMENT.equalsIgnoreCase(elementName)) {
        subEvent = StaxParserUtil.getNextStartElement(xmlEventReader);
        if (!StaxParserUtil.hasTextAhead(xmlEventReader))
          throw new ParsingException(ErrorCodes.EXPECTED_TEXT_VALUE + "RequestHandler");
        configType.setRequestHandler(StaxParserUtil.getElementText(xmlEventReader));
      } else if (CLAIMS_PROCESSORS_ELEMENT.equalsIgnoreCase(elementName)) {
        configType.setClaimsProcessors(this.parseClaimsProcessors(xmlEventReader));
      } else if (TOKEN_PROVIDERS_ELEMENT.equalsIgnoreCase(elementName)) {
        configType.setTokenProviders(this.parseTokenProviders(xmlEventReader));
      } else if (SERVICE_PROVIDERS_ELEMENT.equalsIgnoreCase(elementName)) {
        configType.setServiceProviders(this.parseServiceProviders(xmlEventReader));
      } else throw logger.parserUnknownTag(elementName, subEvent.getLocation());
    }
    return configType;
  }