コード例 #1
0
 static Collection<SaslQop> asQopSet(final ModelNode node) {
   final Set<SaslQop> set = new HashSet<SaslQop>();
   for (final ModelNode element : node.asList()) {
     set.add(SaslQop.valueOf(element.asString()));
   }
   return set;
 }
コード例 #2
0
  void parseSaslElement(
      final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list)
      throws XMLStreamException {
    final ModelNode saslElement = new ModelNode();
    saslElement.get(OP).set(ADD);
    saslElement
        .get(OP_ADDR)
        .set(address)
        .add(SaslResource.SASL_CONFIG_PATH.getKey(), SaslResource.SASL_CONFIG_PATH.getValue());
    list.add(saslElement);

    // No attributes
    final int count = reader.getAttributeCount();
    if (count > 0) {
      throw unexpectedAttribute(reader, 0);
    }
    // Nested elements
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
      final Element element = Element.forName(reader.getLocalName());
      if (visited.contains(element)) {
        throw unexpectedElement(reader);
      }
      visited.add(element);
      switch (element) {
        case INCLUDE_MECHANISMS:
          {
            final ModelNode includes = saslElement.get(INCLUDE_MECHANISMS);
            for (final String s : readArrayAttributeElement(reader, "value", String.class)) {
              includes.add().set(s);
            }
            break;
          }
        case POLICY:
          {
            parsePolicyElement(reader, saslElement.get(OP_ADDR), list);
            break;
          }
        case PROPERTIES:
          {
            parseProperties(reader, saslElement.get(OP_ADDR), list);
            break;
          }
        case QOP:
          {
            String[] qop = readArrayAttributeElement(reader, "value", String.class);
            for (String q : qop) {
              try {
                saslElement.get(QOP).add(SaslQop.fromString(q).getString().toLowerCase());
              } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException("Invalid QOP value: " + q);
              }
            }
            break;
          }
        case REUSE_SESSION:
          {
            saslElement.get(REUSE_SESSION).set(readBooleanAttributeElement(reader, "value"));
            break;
          }
        case SERVER_AUTH:
          {
            saslElement.get(SERVER_AUTH).set(readBooleanAttributeElement(reader, "value"));
            break;
          }
        case STRENGTH:
          {
            // FIXME is this really an xml attribute?
            String[] strength = readArrayAttributeElement(reader, "value", String.class);
            for (String s : strength) {
              try {
                saslElement
                    .get(STRENGTH)
                    .add(SaslStrength.valueOf(s.toUpperCase()).name().toLowerCase());
              } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException("Invalid Strength value: " + s);
              }
            }
            break;
          }
        default:
          {
            throw unexpectedElement(reader);
          }
      }
    }
  }