Ejemplo n.º 1
0
  private KeyPair addFileKeystoreService(
      OperationContext context,
      ModelNode ssl,
      ServiceName serviceName,
      ServiceTarget serviceTarget,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    char[] keystorePassword =
        KeystoreAttributes.KEYSTORE_PASSWORD
            .resolveModelAttribute(context, ssl)
            .asString()
            .toCharArray();
    char[] keyPassword = null;
    ModelNode pwordNode = KeystoreAttributes.KEY_PASSWORD.resolveModelAttribute(context, ssl);
    if (pwordNode.isDefined()) {
      keyPassword = pwordNode.asString().toCharArray();
    }

    String path = KeystoreAttributes.KEYSTORE_PATH.resolveModelAttribute(context, ssl).asString();
    ModelNode aliasNode = KeystoreAttributes.ALIAS.resolveModelAttribute(context, ssl);
    String alias = aliasNode.isDefined() ? aliasNode.asString() : null;
    FileKeystoreService fileKeystoreService =
        new FileKeystoreService(path, keystorePassword, alias, keyPassword);

    ServiceBuilder<?> serviceBuilder = serviceTarget.addService(serviceName, fileKeystoreService);
    ModelNode relativeTo =
        KeystoreAttributes.KEYSTORE_RELATIVE_TO.resolveModelAttribute(context, ssl);
    if (relativeTo.isDefined()) {
      serviceBuilder.addDependency(
          pathName(relativeTo.asString()),
          String.class,
          fileKeystoreService.getRelativeToInjector());
    }

    final ServiceController<?> serviceController =
        serviceBuilder.setInitialMode(ON_DEMAND).install();
    if (newControllers != null) {
      newControllers.add(serviceController);
    }

    KeyPair pair = new KeyPair();
    pair.keystorePassword = keystorePassword;
    pair.keyPassword = keyPassword;
    return pair;
  }