コード例 #1
0
  @Override
  protected void addBootOperations(List<ModelNode> bootOperations) {
    if (enableRbac) {
      for (StandardRole standardRole : EnumSet.allOf(StandardRole.class)) {
        ModelNode addRoleMappingOp =
            Util.createAddOperation(
                PathAddress.pathAddress(
                    CoreManagementResourceDefinition.PATH_ELEMENT,
                    AccessAuthorizationResourceDefinition.PATH_ELEMENT,
                    PathElement.pathElement(
                        RoleMappingResourceDefinition.PATH_KEY, standardRole.getFormalName())));
        bootOperations.add(addRoleMappingOp);

        ModelNode addIncludeUserOp =
            Util.createAddOperation(
                PathAddress.pathAddress(
                    CoreManagementResourceDefinition.PATH_ELEMENT,
                    AccessAuthorizationResourceDefinition.PATH_ELEMENT,
                    PathElement.pathElement(
                        RoleMappingResourceDefinition.PATH_KEY, standardRole.getFormalName()),
                    PathElement.pathElement(
                        ModelDescriptionConstants.INCLUDE,
                        "user-" + roleToUserName(standardRole))));
        addIncludeUserOp
            .get(PrincipalResourceDefinition.NAME.getName())
            .set(roleToUserName(standardRole));
        addIncludeUserOp
            .get(PrincipalResourceDefinition.TYPE.getName())
            .set(PrincipalResourceDefinition.Type.USER.toString());
        bootOperations.add(addIncludeUserOp);
      }

      ModelNode enableRbacOp =
          Util.getWriteAttributeOperation(
              PathAddress.pathAddress(
                  CoreManagementResourceDefinition.PATH_ELEMENT,
                  AccessAuthorizationResourceDefinition.PATH_ELEMENT),
              AccessAuthorizationResourceDefinition.PROVIDER.getName(),
              new ModelNode(AccessAuthorizationResourceDefinition.Provider.RBAC.toString()));
      bootOperations.add(enableRbacOp);
    }

    ModelNode addOp =
        Util.createAddOperation(
            PathAddress.pathAddress(
                ModelDescriptionConstants.SUBSYSTEM, JMXExtension.SUBSYSTEM_NAME));
    bootOperations.add(addOp);
  }
コード例 #2
0
  protected void initModel(ManagementModel managementModel) {
    ManagementResourceRegistration registration = managementModel.getRootResourceRegistration();
    PathManagerService pathManagerService = new PathManagerService() {};
    GlobalOperationHandlers.registerGlobalOperations(registration, processType);
    registration.registerOperationHandler(
        CompositeOperationHandler.DEFINITION, CompositeOperationHandler.INSTANCE);

    GlobalNotifications.registerGlobalNotifications(registration, processType);

    registration.registerReadOnlyAttribute(
        LAUNCH_TYPE,
        new OperationStepHandler() {

          @Override
          public void execute(OperationContext context, ModelNode operation)
              throws OperationFailedException {
            context.getResult().set(TYPE_STANDALONE);
          }
        });

    TestServiceListener listener = new TestServiceListener();
    listener.reset(1);
    getContainer()
        .addService(PathManagerService.SERVICE_NAME, pathManagerService)
        .addListener(listener)
        .install();

    try {
      listener.latch.await(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new RuntimeException(e);
    }

    registration.registerSubModel(PathResourceDefinition.createSpecified(pathManagerService));
    registration.registerSubModel(
        CoreManagementResourceDefinition.forStandaloneServer(
            getAuthorizer(),
            getAuditLogger(),
            pathManagerService,
            new EnvironmentNameReader() {
              public boolean isServer() {
                return true;
              }

              public String getServerName() {
                return "Test";
              }

              public String getHostName() {
                return null;
              }

              public String getProductName() {
                return null;
              }
            },
            null,
            new ResourceDefinition[0]));

    Resource rootResource = managementModel.getRootResource();
    pathManagerService.addPathManagerResources(rootResource);

    ExtensionRegistry extensionRegistry =
        new ExtensionRegistry(
            ProcessType.STANDALONE_SERVER,
            new RunningModeControl(RunningMode.NORMAL),
            AuditLogger.NO_OP_LOGGER,
            getAuthorizer(),
            RuntimeHostControllerInfoAccessor.SERVER);
    extensionRegistry.setPathManager(pathManagerService);
    extensionRegistry.setWriterRegistry(new NullConfigurationPersister());
    JMXExtension extension = new JMXExtension();
    extension.initialize(
        extensionRegistry.getExtensionContext(
            "org.jboss.as.jmx", registration, ExtensionRegistryType.SLAVE));

    Resource coreManagementResource = Resource.Factory.create();
    rootResource.registerChild(
        CoreManagementResourceDefinition.PATH_ELEMENT, coreManagementResource);

    Resource accessAuthorizationResource = Resource.Factory.create();
    accessAuthorizationResource
        .getModel()
        .get(AccessAuthorizationResourceDefinition.PROVIDER.getName())
        .set(AccessAuthorizationResourceDefinition.Provider.SIMPLE.toString());
    coreManagementResource.registerChild(
        AccessAuthorizationResourceDefinition.PATH_ELEMENT, accessAuthorizationResource);
  }