@Test
 public void testConfigurationChanges() throws Exception {
   final ModelNode listConfigurationChanges =
       Util.createOperation(ConfigurationChangeResourceDefinition.OPERATION_NAME, ADDRESS);
   List<ModelNode> changes =
       getManagementClient().executeForResult(listConfigurationChanges).asList();
   assertThat(changes.size(), is(3));
   for (ModelNode change : changes) {
     assertThat(change.hasDefined(OPERATION_DATE), is(true));
     assertThat(change.hasDefined(USER_ID), is(false));
     assertThat(change.hasDefined(DOMAIN_UUID), is(false));
     assertThat(change.hasDefined(ACCESS_MECHANISM), is(true));
     assertThat(change.get(ACCESS_MECHANISM).asString(), is("NATIVE"));
     assertThat(change.hasDefined(REMOTE_ADDRESS), is(true));
     assertThat(change.get(OUTCOME).asString(), is(SUCCESS));
     assertThat(change.get(OPERATIONS).asList().size(), is(1));
   }
   ModelNode currentChange = changes.get(0);
   ModelNode currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
   assertThat(currentChangeOp.get(OP).asString(), is(REMOVE));
   assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toString()));
   currentChange = changes.get(1);
   currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
   assertThat(currentChangeOp.get(OP).asString(), is(UNDEFINE_ATTRIBUTE_OPERATION));
   assertThat(
       currentChangeOp.get(OP_ADDR).asString(),
       is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
   currentChange = changes.get(2);
   currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
   assertThat(currentChangeOp.get(OP).asString(), is(ADD));
   assertThat(
       currentChangeOp.get(OP_ADDR).asString(),
       is(SYSTEM_PROPERTY_ADDRESS.toModelNode().asString()));
 }
  public void addDeploymentOverlays(final List<ModelNode> updates) {
    if (domainModel.hasDefined(DEPLOYMENT_OVERLAY)) {

      HostFileRepository remoteRepository = null;
      if (!domainController.getLocalHostInfo().isMasterDomainController()) {
        remoteRepository = domainController.getRemoteFileRepository();
      }

      for (Property deploymentOverlay : domainModel.get(DEPLOYMENT_OVERLAY).asPropertyList()) {
        String name = deploymentOverlay.getName();
        ModelNode details = deploymentOverlay.getValue();

        PathAddress addr =
            PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT_OVERLAY, name));
        ModelNode addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
        updates.add(addOp);

        if (details.hasDefined(CONTENT)) {

          for (Property content : details.get(CONTENT).asPropertyList()) {
            final String contentName = content.getName();
            final ModelNode contentDetails = content.getValue();
            byte[] hash = contentDetails.require(CONTENT).asBytes();
            File[] files = domainController.getLocalFileRepository().getDeploymentFiles(hash);
            if (files == null || files.length == 0) {
              if (remoteRepository != null) {
                remoteRepository.getDeploymentFiles(hash);
              }
            }
            addr =
                PathAddress.pathAddress(
                    PathElement.pathElement(DEPLOYMENT_OVERLAY, name),
                    PathElement.pathElement(CONTENT, contentName));
            addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
            addOp.get(CONTENT).get(HASH).set(contentDetails.get(CONTENT));
            updates.add(addOp);
          }
        }
        if (serverGroup.hasDefined(DEPLOYMENT_OVERLAY)) {
          final ModelNode groupOverlay = serverGroup.get(DEPLOYMENT_OVERLAY).asObject();
          if (groupOverlay.has(name)) {
            ModelNode deploymentsNode = groupOverlay.get(name);
            if (deploymentsNode.has(DEPLOYMENT)) {
              for (Property content : deploymentsNode.get(DEPLOYMENT).asPropertyList()) {
                final String deploymentName = content.getName();
                final ModelNode deploymentDetails = content.getValue();
                addr =
                    PathAddress.pathAddress(
                        PathElement.pathElement(DEPLOYMENT_OVERLAY, name),
                        PathElement.pathElement(DEPLOYMENT, deploymentName));
                addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
                updates.add(addOp);
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 3
0
    @Override
    public OperationResult execute(
        OperationContext context, ModelNode operation, ResultHandler resultHandler) {
      final ModelNode model = context.getSubModel();

      PathAddress rootAddress =
          PathAddress.pathAddress(
              PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement());
      final ModelNode result = new ModelNode();

      final ModelNode subsystem = new ModelNode();
      subsystem.get(OP).set(ADD);
      subsystem.get(OP_ADDR).set(rootAddress.toModelNode());
      if (model.has(ACTIVATION)) {
        subsystem.get(ACTIVATION).set(model.get(ACTIVATION));
      }
      if (model.has(CONFIGURATION)) {
        subsystem.get(CONFIGURATION).set(model.get(CONFIGURATION));
      }
      if (model.has(PROPERTIES)) {
        subsystem.get(PROPERTIES).set(model.get(PROPERTIES));
      }
      if (model.has(MODULES)) {
        subsystem.get(MODULES).set(model.get(MODULES));
      }
      result.add(subsystem);

      resultHandler.handleResultFragment(Util.NO_LOCATION, result);
      resultHandler.handleResultComplete();
      return new BasicOperationResult();
    }
Exemplo n.º 4
0
  private ModelNode removeServerGroups(final DomainClient client) throws Exception {
    final ModelNode op =
        Util.createEmptyOperation(
            READ_RESOURCE_OPERATION,
            PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP)));
    final ModelNode results = executeForResult(op, client);
    ModelNode group = null;
    for (ModelNode result : results.asList()) {
      String groupName = PathAddress.pathAddress(result.get(ADDRESS)).getLastElement().getValue();
      if (groupName.equals(OTHER_SERVER_GROUP)) {
        group = result.get(RESULT);
      } else {
        ModelNode remove = Util.createRemoveOperation(PathAddress.pathAddress(result.get(ADDRESS)));
        executeForResult(remove, client);
      }
    }
    Assert.assertNotNull(group);

    // Add main-server-group as a copy of other-server-group (cuts down on the amount of profiles
    // needed)
    final ModelNode addMain = group.clone();
    final PathAddress mainServerGroupAddress =
        PathAddress.pathAddress(SERVER_GROUP, MAIN_SERVER_GROUP);
    addMain.get(OP).set(ADD);
    addMain.get(OP_ADDR).set(mainServerGroupAddress.toModelNode());
    executeForResult(addMain, client);

    return group;
  }
  private Object getAttribute(
      final ResourceAndRegistration reg,
      final PathAddress address,
      final ObjectName name,
      final String attribute,
      final ResourceAccessControl accessControl)
      throws ReflectionException, AttributeNotFoundException, InstanceNotFoundException {
    final ImmutableManagementResourceRegistration registration = getMBeanRegistration(address, reg);
    final DescriptionProvider provider =
        registration.getModelDescription(PathAddress.EMPTY_ADDRESS);
    if (provider == null) {
      throw MESSAGES.descriptionProviderNotFound(address);
    }
    final ModelNode description = provider.getModelDescription(null);
    final String attributeName = findAttributeName(description.get(ATTRIBUTES), attribute);

    if (!accessControl.isReadableAttribute(attributeName)) {
      throw MESSAGES.notAuthorizedToReadAttribute(attributeName);
    }

    ModelNode op = new ModelNode();
    op.get(OP).set(READ_ATTRIBUTE_OPERATION);
    op.get(OP_ADDR).set(address.toModelNode());
    op.get(NAME).set(attributeName);
    ModelNode result = execute(op);
    String error = getFailureDescription(result);
    if (error != null) {
      throw new AttributeNotFoundException(error);
    }

    return converters.fromModelNode(
        description.require(ATTRIBUTES).require(attributeName), result.get(RESULT));
  }
 private void addCredential(
     PathAddress parent, KeycloakAdapterConfigService service, String key, String value) {
   PathAddress credAddr =
       PathAddress.pathAddress(parent, PathElement.pathElement("credential", key));
   ModelNode credOp = new ModelNode();
   credOp.get(ModelDescriptionConstants.OP_ADDR).set(credAddr.toModelNode());
   ModelNode credential = new ModelNode();
   credential.get("value").set(value);
   service.addCredential(credOp, credential);
 }
Exemplo n.º 7
0
 public static ModelNode createEmptyOperation(String operationName, final PathAddress address) {
   ModelNode op = new ModelNode();
   op.get(OP).set(operationName);
   if (address != null) {
     op.get(OP_ADDR).set(address.toModelNode());
   } else {
     // Just establish the standard structure; caller can fill in address later
     op.get(OP_ADDR);
   }
   return op;
 }
  private void addCacheNameToAddress(
      ModelNode cache, PathAddress containerAddress, String cacheType) {

    String name = cache.get(ModelKeys.NAME).asString();
    // setup the cache address
    PathAddress cacheAddress = containerAddress.append(cacheType, name);
    cache.get(ModelDescriptionConstants.OP_ADDR).set(cacheAddress.toModelNode());

    // get rid of NAME now that we are finished with it
    cache.remove(ModelKeys.NAME);
  }
  @Test
  public void testAllConfigurationChanges() throws Exception {
    final ModelNode update =
        Util.getWriteAttributeOperation(ADDRESS, "max-history", ALL_MAX_HISTORY_SIZE);
    getModelControllerClient().execute(update);
    final ModelNode listConfigurationChanges = Util.createOperation("list-changes", ADDRESS);
    List<ModelNode> changes =
        getManagementClient().executeForResult(listConfigurationChanges).asList();
    assertThat(changes.toString(), changes.size(), is(ALL_MAX_HISTORY_SIZE));
    for (ModelNode change : changes) {
      assertThat(change.hasDefined(OPERATION_DATE), is(true));
      assertThat(change.hasDefined(USER_ID), is(false));
      assertThat(change.hasDefined(DOMAIN_UUID), is(false));
      assertThat(change.hasDefined(ACCESS_MECHANISM), is(true));
      assertThat(change.get(ACCESS_MECHANISM).asString(), is("NATIVE"));
      // TODO Elytron - Restore capturing the Remote address.
      // assertThat(change.hasDefined(REMOTE_ADDRESS), is(true));
      assertThat(change.get(OPERATIONS).asList().size(), is(1));
    }

    ModelNode currentChange = changes.get(0);
    ModelNode currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION));
    assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
    currentChange = changes.get(1);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION));
    assertThat(
        currentChangeOp.get(OP_ADDR).asString(),
        is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(FAILED));
    currentChange = changes.get(2);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(REMOVE));
    assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
    currentChange = changes.get(3);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(UNDEFINE_ATTRIBUTE_OPERATION));
    assertThat(
        currentChangeOp.get(OP_ADDR).asString(),
        is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
    currentChange = changes.get(4);
    currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
    assertThat(currentChangeOp.get(OP).asString(), is(ADD));
    assertThat(
        currentChangeOp.get(OP_ADDR).asString(),
        is(SYSTEM_PROPERTY_ADDRESS.toModelNode().asString()));
    assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS));
  }
  private void setAttribute(
      final ResourceAndRegistration reg,
      final PathAddress address,
      final ObjectName name,
      final Attribute attribute,
      ResourceAccessControl accessControl)
      throws InvalidAttributeValueException, AttributeNotFoundException, InstanceNotFoundException {
    final ImmutableManagementResourceRegistration registration = getMBeanRegistration(address, reg);
    final DescriptionProvider provider =
        registration.getModelDescription(PathAddress.EMPTY_ADDRESS);
    if (provider == null) {
      throw MESSAGES.descriptionProviderNotFound(address);
    }
    final ModelNode description = provider.getModelDescription(null);
    final String attributeName =
        findAttributeName(description.get(ATTRIBUTES), attribute.getName());

    if (!standalone) {
      throw MESSAGES.attributeNotWritable(attribute);
    }

    if (!accessControl.isWritableAttribute(attributeName)) {
      throw MESSAGES.notAuthorizedToWriteAttribute(attributeName);
    }

    ModelNode op = new ModelNode();
    op.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
    op.get(OP_ADDR).set(address.toModelNode());
    op.get(NAME).set(attributeName);
    try {
      op.get(VALUE)
          .set(
              converters.toModelNode(
                  description.require(ATTRIBUTES).require(attributeName), attribute.getValue()));
    } catch (ClassCastException e) {
      throw MESSAGES.invalidAttributeType(e, attribute.getName());
    }
    ModelNode result = execute(op);
    String error = getFailureDescription(result);
    if (error != null) {
      // Since read-resource-description does not know the parameters of the operation, i.e. if a
      // vault expression is used or not,
      // check the error code
      // TODO add a separate authorize step where we check ourselves that the operation will pass
      // authorization?
      if (isVaultExpression(attribute.getValue()) && error.contains(AUTHORIZED_ERROR)) {
        throw MESSAGES.notAuthorizedToWriteAttribute(attributeName);
      }
      throw new InvalidAttributeValueException(error);
    }
  }
  @Override
  public List<ModelNode> getList(DatasourcesFraction fraction) {

    List<ModelNode> list = new ArrayList<>();

    ModelNode node = new ModelNode();
    node.get(OP_ADDR).set(datasourcesAddress.toModelNode());
    node.get(OP).set(ADD);
    list.add(node);

    addDrivers(fraction, list);
    addDatasources(fraction, list);

    return list;
  }
 /**
  * Creates an operations that targets this handler.
  *
  * @param operationToValidate the operation that this handler will validate
  * @return the validation operation
  */
 static ModelNode createOperation(final ModelNode operationToValidate) {
   PathAddress pa =
       PathAddress.pathAddress(operationToValidate.require(ModelDescriptionConstants.OP_ADDR));
   PathAddress realmPA = null;
   for (int i = pa.size() - 1; i > 0; i--) {
     PathElement pe = pa.getElement(i);
     if (ModelDescriptionConstants.SECURITY_REALM.equals(pe.getKey())) {
       realmPA = pa.subAddress(0, i + 1);
       break;
     }
   }
   assert realmPA != null
       : "operationToValidate did not have an address that included a "
           + ModelDescriptionConstants.SECURITY_REALM;
   return Util.getEmptyOperation("validate-authorization", realmPA.toModelNode());
 }
Exemplo n.º 13
0
  private String getHotRodCacheContainer(ModelControllerClient client) throws IOException {
    PathAddress pathAddress =
        PathAddress.pathAddress(SUBSYSTEM, INFINISPAN_ENDPOINT_SUBSYSTEM_NAME)
            .append("hotrod-connector", "hotrod-connector");

    ModelNode op = new ModelNode();
    op.get(OP).set(READ_ATTRIBUTE_OPERATION);
    op.get(OP_ADDR).set(pathAddress.toModelNode());
    op.get("name").set("cache-container");

    ModelNode resp = client.execute(op);
    if (!SUCCESS.equals(resp.get(OUTCOME).asString())) {
      throw new IllegalArgumentException(resp.asString());
    }
    return resp.get(RESULT).asString();
  }
  @Test
  public void testJsonFromSignedJWTCredentials() {
    KeycloakAdapterConfigService service = KeycloakAdapterConfigService.getInstance();

    PathAddress addr =
        PathAddress.pathAddress(
            PathElement.pathElement("subsystem", "keycloak"),
            PathElement.pathElement("secure-deployment", "foo"));
    ModelNode deploymentOp = new ModelNode();
    deploymentOp.get(ModelDescriptionConstants.OP_ADDR).set(addr.toModelNode());
    ModelNode deployment = new ModelNode();
    deployment.get("realm").set("demo");
    deployment.get("resource").set("customer-portal");
    service.addSecureDeployment(deploymentOp, deployment);

    addCredential(addr, service, "secret", "secret1");
    addCredential(addr, service, "jwt.client-keystore-file", "/tmp/foo.jks");
    addCredential(addr, service, "jwt.token-timeout", "10");

    System.out.println("Deployment: " + service.getJSON("foo"));
  }
Exemplo n.º 15
0
  /** {@inheritDoc} */
  @Override
  public OperationResult execute(
      final OperationContext context,
      final ModelNode operation,
      final ResultHandler resultHandler) {

    final ModelNode result = new ModelNode();
    final PathAddress rootAddress =
        PathAddress.pathAddress(
            PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement());
    final ModelNode subModel = context.getSubModel();

    final ModelNode subsystemAdd = new ModelNode();
    subsystemAdd.get(OP).set(ADD);
    subsystemAdd.get(OP_ADDR).set(rootAddress.toModelNode());

    if (subModel.hasDefined(MODIFY_WSDL_ADDRESS)) {
      subsystemAdd.get(MODIFY_WSDL_ADDRESS).set(subModel.get(MODIFY_WSDL_ADDRESS));
    }

    if (subModel.hasDefined(WSDL_HOST)) {
      subsystemAdd.get(WSDL_HOST).set(subModel.get(WSDL_HOST));
    }

    if (subModel.hasDefined(WSDL_PORT)) {
      subsystemAdd.get(WSDL_PORT).set(subModel.get(WSDL_PORT));
    }

    if (subModel.hasDefined(WSDL_SECURE_PORT)) {
      subsystemAdd.get(WSDL_SECURE_PORT).set(subModel.get(WSDL_SECURE_PORT));
    }

    result.add(subsystemAdd);

    resultHandler.handleResultFragment(Util.NO_LOCATION, result);
    resultHandler.handleResultComplete();
    return new BasicOperationResult();
  }
  private void addDeployments(List<ModelNode> updates) {
    if (serverGroup.hasDefined(DEPLOYMENT)) {

      HostFileRepository remoteRepository = null;
      if (!domainController.getLocalHostInfo().isMasterDomainController()) {
        remoteRepository = domainController.getRemoteFileRepository();
      }

      for (Property deployment : serverGroup.get(DEPLOYMENT).asPropertyList()) {
        String name = deployment.getName();
        ModelNode details = deployment.getValue();

        ModelNode domainDeployment = domainModel.require(DEPLOYMENT).require(name);
        ModelNode deploymentContent = domainDeployment.require(CONTENT).clone();

        if (remoteRepository != null) {
          // Make sure we have a copy of the deployment in the local repo
          for (ModelNode content : deploymentContent.asList()) {
            if ((content.hasDefined(HASH))) {
              byte[] hash = content.require(HASH).asBytes();
              File[] files = domainController.getLocalFileRepository().getDeploymentFiles(hash);
              if (files == null || files.length == 0) {
                remoteRepository.getDeploymentFiles(hash);
              }
            }
          }
        }

        PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, name));
        ModelNode addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
        addOp.get(RUNTIME_NAME).set(details.get(RUNTIME_NAME));
        addOp.get(CONTENT).set(deploymentContent);
        addOp.get(ENABLED).set(!details.hasDefined(ENABLED) || details.get(ENABLED).asBoolean());

        updates.add(addOp);
      }
    }
  }
  @Override
  public List<ModelNode> getList(EEFraction fraction) {

    List<ModelNode> list = new ArrayList<>();
    PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, "ee"));

    ModelNode node = new ModelNode();
    node.get(OP_ADDR).set(EXTENSION, "org.jboss.as.ee");
    node.get(OP).set(ADD);
    list.add(node);

    node = new ModelNode();
    node.get(OP_ADDR).set(address.toModelNode());
    node.get(OP).set(ADD);
    node.get("spec-descriptor-property-replacement").set(false);
    list.add(node);

    node = new ModelNode();
    node.get(OP_ADDR).set(address.append("context-service", "default").toModelNode());
    node.get(OP).set(ADD);
    node.get("jndi-name").set("java:jboss/ee/concurrency/context/default");
    node.get("use-transaction-setup-provider").set(false);
    list.add(node);

    node = new ModelNode();
    node.get(OP_ADDR).set(address.append("managed-thread-factory", "default").toModelNode());
    node.get(OP).set(ADD);
    node.get("jndi-name").set("java:jboss/ee/concurrency/factory/default");
    node.get("content-service").set("default");
    list.add(node);

    node = new ModelNode();
    node.get(OP_ADDR).set(address.append("managed-executor-service", "default").toModelNode());
    node.get(OP).set(ADD);
    node.get("jndi-name").set("java:jboss/ee/concurrency/executor/default");
    node.get("context-service").set("default");
    node.get("hung-task-threshold").set(60000L);
    node.get("core-threads").set(5);
    node.get("max-threads").set(25);
    node.get("keepalive-time").set(5000L);
    list.add(node);

    node = new ModelNode();
    node.get(OP_ADDR)
        .set(address.append("managed-scheduled-executor-service", "default").toModelNode());
    node.get(OP).set(ADD);
    node.get("jndi-name").set("java:jboss/ee/concurrency/scheduler/default");
    node.get("context-service").set("default");
    node.get("hung-task-threshold").set(60000L);
    node.get("core-threads").set(5);
    node.get("keepalive-time").set(3000L);
    list.add(node);

    /*
    node = new ModelNode();
    node.get(OP_ADDR).set(address.append("service", "default-bindings").toModelNode());
    node.get(OP).set(ADD);
    node.get( "context-service" ).set( "java:jboss/ee/concurrency/context/default" );
    node.get( "managed-executor-service" ).set( "java:jboss/ee/concurrency/executor/default" );
    node.get( "managed-scheduled-executor-service" ).set( "java:jboss/ee/concurrency/scheduler/default");
    node.get( "managed-thread-factory").set( "java:jboss/ee/concurrency/factory/default" );
    this.list.add( node );
    */

    return list;
  }
  @Test
  public void testTransformers_1_1() throws Exception {
    final String subsystemXml = getSubsystemXml();
    final ModelVersion modelVersion = ModelVersion.create(1, 1, 0);
    final KernelServicesBuilder builder =
        createKernelServicesBuilder(LoggingTestEnvironment.getManagementInstance())
            .setSubsystemXml(subsystemXml);

    // which is why we need to include the jboss-as-controller artifact.
    builder
        .createLegacyKernelServicesBuilder(
            LoggingTestEnvironment.getManagementInstance(), modelVersion)
        .addMavenResourceURL("org.jboss.as:jboss-as-logging:7.1.2.Final")
        .addMavenResourceURL("org.jboss.as:jboss-as-controller:7.1.2.Final")
        .addParentFirstClassPattern("org.jboss.as.controller.*");

    KernelServices mainServices = builder.build();
    Assert.assertTrue(mainServices.isSuccessfulBoot());
    Assert.assertTrue(mainServices.getLegacyServices(modelVersion).isSuccessfulBoot());

    final ModelNode legacyModel = checkSubsystemModelTransformation(mainServices, modelVersion);

    final PathAddress consoleAddress =
        PathAddress.pathAddress(
            LoggingTestEnvironment.SUBSYSTEM_PATH,
            PathElement.pathElement(CommonAttributes.CONSOLE_HANDLER, "CONSOLE"));
    // Get all the console handler
    final ModelNode consoleHandler =
        legacyModel.get(
            consoleAddress.getElement(0).getKey(),
            consoleAddress.getElement(0).getValue(),
            consoleAddress.getElement(1).getKey(),
            consoleAddress.getElement(1).getValue());
    String formatPattern = consoleHandler.get(CommonAttributes.FORMATTER.getName()).asString();
    Assert.assertFalse(
        "Pattern ("
            + formatPattern
            + ") contains a color attribute not supported in legacy models.",
        COLOR_PATTERN.matcher(formatPattern).find());

    // Write a pattern with a %K{level} to ensure it gets removed
    ModelNode op =
        Operations.createWriteAttributeOperation(
            consoleAddress.toModelNode(), CommonAttributes.FORMATTER, "%K{level}" + formatPattern);
    executeTransformOperation(mainServices, modelVersion, op);
    validateLegacyFormatter(mainServices, modelVersion, consoleAddress.toModelNode());

    // Test update properties
    op =
        Operations.createOperation(
            AbstractHandlerDefinition.UPDATE_OPERATION_NAME, consoleAddress.toModelNode());
    op.get(CommonAttributes.FORMATTER.getName()).set("%K{level}" + formatPattern);
    executeTransformOperation(mainServices, modelVersion, op);
    validateLegacyFormatter(mainServices, modelVersion, consoleAddress.toModelNode());

    // Write out a filter-spec
    final String filterExpression = "not(match(\"ARJUNA\\\\d\"))";
    op =
        Operations.createWriteAttributeOperation(
            consoleAddress.toModelNode(), CommonAttributes.FILTER_SPEC, filterExpression);
    executeTransformOperation(mainServices, modelVersion, op);
    validateLegacyFilter(
        mainServices, modelVersion, consoleAddress.toModelNode(), filterExpression);

    // update-propertes on a filter spec
    op =
        Operations.createOperation(
            AbstractHandlerDefinition.UPDATE_OPERATION_NAME, consoleAddress.toModelNode());
    op.get(CommonAttributes.FILTER_SPEC.getName()).set(filterExpression);
    executeTransformOperation(mainServices, modelVersion, op);
    validateLegacyFilter(
        mainServices, modelVersion, consoleAddress.toModelNode(), filterExpression);

    final PathAddress loggerAddress =
        PathAddress.pathAddress(
            LoggingTestEnvironment.SUBSYSTEM_PATH,
            PathElement.pathElement(CommonAttributes.LOGGER, "org.jboss.as.logging"));
    // Verify the logger exists, add if it doesn't
    op = Operations.createReadResourceOperation(loggerAddress.toModelNode());
    if (!Operations.successful(mainServices.executeOperation(op))) {
      op = Operations.createAddOperation(loggerAddress.toModelNode());
      executeTransformOperation(mainServices, modelVersion, op);
    }

    // write a filter-spec
    op =
        Operations.createWriteAttributeOperation(
            loggerAddress.toModelNode(), CommonAttributes.FILTER_SPEC, filterExpression);
    executeTransformOperation(mainServices, modelVersion, op);
    validateLegacyFilter(mainServices, modelVersion, loggerAddress.toModelNode(), filterExpression);
  }
  private void parseContainer(
      XMLExtendedStreamReader reader, PathAddress subsystemAddress, List<ModelNode> operations)
      throws XMLStreamException {

    ModelNode container = Util.getEmptyOperation(ADD, null);
    String name = null;
    final Set<Attribute> required = EnumSet.of(Attribute.NAME);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
      ParseUtils.requireNoNamespaceAttribute(reader, i);
      String value = reader.getAttributeValue(i);
      Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
      required.remove(attribute);
      switch (attribute) {
        case NAME:
          {
            name = value;
            break;
          }
        case ALIASES:
          {
            for (String alias : reader.getListAttributeValue(i)) {
              container.get(ModelKeys.ALIASES).add(alias);
            }
            break;
          }
        case DEFAULT_CACHE:
          {
            CacheContainerResource.DEFAULT_CACHE.parseAndSetParameter(value, container, reader);
            break;
          }
        case JNDI_NAME:
          {
            CacheContainerResource.JNDI_NAME.parseAndSetParameter(value, container, reader);
            break;
          }
        case START:
          {
            CacheContainerResource.START.parseAndSetParameter(value, container, reader);
            break;
          }
        case LISTENER_EXECUTOR:
          {
            CacheContainerResource.LISTENER_EXECUTOR.parseAndSetParameter(value, container, reader);
            break;
          }
        case EVICTION_EXECUTOR:
          {
            CacheContainerResource.EVICTION_EXECUTOR.parseAndSetParameter(value, container, reader);
            break;
          }
        case REPLICATION_QUEUE_EXECUTOR:
          {
            CacheContainerResource.REPLICATION_QUEUE_EXECUTOR.parseAndSetParameter(
                value, container, reader);
            break;
          }
        case MODULE:
          {
            CacheContainerResource.CACHE_CONTAINER_MODULE.parseAndSetParameter(
                value, container, reader);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedAttribute(reader, i);
          }
      }
    }

    if (!required.isEmpty()) {
      throw ParseUtils.missingRequired(reader, required);
    }

    PathAddress containerAddress = subsystemAddress.append(ModelKeys.CACHE_CONTAINER, name);
    container.get(OP_ADDR).set(containerAddress.toModelNode());

    // operation to add the container
    operations.add(container);

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case TRANSPORT:
          {
            parseTransport(reader, containerAddress, operations);
            break;
          }
        case LOCAL_CACHE:
          {
            parseLocalCache(reader, containerAddress, operations);
            break;
          }
        case INVALIDATION_CACHE:
          {
            parseInvalidationCache(reader, containerAddress, operations);
            break;
          }
        case REPLICATED_CACHE:
          {
            parseReplicatedCache(reader, containerAddress, operations);
            break;
          }
        case DISTRIBUTED_CACHE:
          {
            parseDistributedCache(reader, containerAddress, operations);
            break;
          }
        default:
          {
            throw ParseUtils.unexpectedElement(reader);
          }
      }
    }
  }
Exemplo n.º 20
0
 public static ModelNode createOperation(
     final OperationDefinition operationDefinition, final PathAddress address) {
   return getEmptyOperation(operationDefinition.getName(), address.toModelNode());
 }
Exemplo n.º 21
0
 ManagedServerProxy(final ManagedServer server, final PathAddress address) {
   this.server = server;
   this.address = address.toModelNode();
   this.remoteClient = DISCONNECTED;
 }
  private Object invoke(
      final OperationEntry entry, final String operationName, PathAddress address, Object[] params)
      throws InstanceNotFoundException, MBeanException, ReflectionException {
    if (!standalone && !entry.getFlags().contains(OperationEntry.Flag.READ_ONLY)) {
      throw MESSAGES.noOperationCalled(operationName);
    }

    ResourceAccessControl accessControl;
    if (operationName.equals("add")) {
      accessControl = accessControlUtil.getResourceAccess(address, true);
    } else {
      ObjectName objectName = ObjectNameAddressUtil.createObjectName(operationName, address);
      accessControl =
          accessControlUtil.getResourceAccessWithInstanceNotFoundExceptionIfNotAccessible(
              objectName, address, true);
    }

    if (!accessControl.isExecutableOperation(operationName)) {
      throw MESSAGES.notAuthorizedToExecuteOperation(operationName);
    }

    final ModelNode description = entry.getDescriptionProvider().getModelDescription(null);
    ModelNode op = new ModelNode();
    op.get(OP).set(operationName);
    op.get(OP_ADDR).set(address.toModelNode());
    if (params.length > 0) {
      ModelNode requestProperties = description.require(REQUEST_PROPERTIES);
      Set<String> keys = requestProperties.keys();
      if (keys.size() != params.length) {
        throw MESSAGES.differentLengths("params", "description");
      }
      Iterator<String> it = requestProperties.keys().iterator();
      for (int i = 0; i < params.length; i++) {
        String attributeName = it.next();
        ModelNode paramDescription = requestProperties.get(attributeName);
        op.get(attributeName).set(converters.toModelNode(paramDescription, params[i]));
      }
    }

    ModelNode result = execute(op);
    String error = getFailureDescription(result);
    if (error != null) {
      if (error.contains(AUTHORIZED_ERROR)) {
        for (Object param : params) {
          // Since read-resource-description does not know the parameters of the operation, i.e. if
          // a vault expression is used or not,
          // check the error code
          // TODO add a separate authorize step where we check ourselves that the operation will
          // pass authorization?
          if (isVaultExpression(param)) {
            throw MESSAGES.notAuthorizedToExecuteOperation(operationName);
          }
        }
      }
      throw new ReflectionException(null, error);
    }

    if (!description.hasDefined(REPLY_PROPERTIES)) {
      return null;
    }
    // TODO we could have more than one reply property
    return converters.fromModelNode(description.get(REPLY_PROPERTIES), result.get(RESULT));
  }
 public ModelNode build() {
   return pathAddress.toModelNode();
 }