コード例 #1
0
  @After
  public void afterTest() throws Exception {
    // stop syslog server
    SyslogServer.shutdown();
    server.setThread(null);
    server.getConfig().removeAllEventHandlers();

    final ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient();
    ModelNode op =
        Util.getWriteAttributeOperation(
            auditLogConfigAddress,
            AuditLogLoggerResourceDefinition.ENABLED.getName(),
            new ModelNode(false));
    client.execute(op);
    op =
        Util.getWriteAttributeOperation(
            mgmtRealmConfigAddress, "default-user", new ModelNode("$local"));
    client.execute(op);

    op = Util.getResourceRemoveOperation(addSyslogHandler);
    client.execute(op);
    op = Util.getResourceRemoveOperation(syslogHandlerAddress);
    client.execute(op);

    if (file.exists()) {
      file.delete();
    }
    if (syslogFile.exists()) {
      syslogFile.delete();
    }
    try {
      // Stop the container
      container.stop(CONTAINER);
    } finally {
      IoUtils.safeClose(client);
    }
  }
コード例 #2
0
  @Before
  public void beforeTest() throws Exception {
    file = new File(System.getProperty("jboss.home"));
    file = new File(file, "standalone");
    file = new File(file, "data");
    file = new File(file, "audit-log.log");
    if (file.exists()) {
      file.delete();
    }

    syslogFile = new File(System.getProperty("jboss.home"));
    syslogFile = new File(syslogFile, "standalone");
    syslogFile = new File(syslogFile, "data");
    syslogFile = new File(syslogFile, "syslog-audit-log.log");
    if (syslogFile.exists()) {
      syslogFile.delete();
    }

    // start and set syslog server
    server = SyslogServer.getInstance("udp");
    server.getConfig().setPort(PORT);
    queue = new LinkedBlockingQueue<String>();
    server
        .getConfig()
        .addEventHandler(
            new BlockedFileSyslogServerEventHandler(queue, syslogFile.getAbsolutePath(), false));
    SyslogServer.getThreadedInstance("udp");

    // Start the server
    container.start(CONTAINER);
    final ModelControllerClient client = TestSuiteEnvironment.getModelControllerClient();
    managementClient =
        new ManagementClient(
            client,
            TestSuiteEnvironment.getServerAddress(),
            TestSuiteEnvironment.getServerPort(),
            "http-remoting");

    ModelNode op;
    ModelNode result;

    mgmtRealmConfigAddress =
        PathAddress.pathAddress(
            PathElement.pathElement(CORE_SERVICE, MANAGEMENT),
            PathElement.pathElement(SECURITY_REALM, "ManagementRealm"),
            PathElement.pathElement(AUTHENTICATION, LOCAL));
    op =
        Util.getWriteAttributeOperation(
            mgmtRealmConfigAddress, "default-user", new ModelNode("IAmAdmin"));
    result = client.execute(op);

    auditLogConfigAddress =
        PathAddress.pathAddress(
            CoreManagementResourceDefinition.PATH_ELEMENT,
            AccessAuditResourceDefinition.PATH_ELEMENT,
            AuditLogLoggerResourceDefinition.PATH_ELEMENT);

    op =
        Util.getWriteAttributeOperation(
            auditLogConfigAddress,
            AuditLogLoggerResourceDefinition.ENABLED.getName(),
            new ModelNode(true));
    result = client.execute(op);
    Assert.assertEquals(
        result.get("failure-description").asString(), SUCCESS, result.get(OUTCOME).asString());

    ModelNode compositeOp = new ModelNode();
    compositeOp.get(OP).set(COMPOSITE);
    compositeOp.get(OP_ADDR).setEmptyList();
    ModelNode steps = compositeOp.get(STEPS);
    syslogHandlerAddress =
        PathAddress.pathAddress(
            PathElement.pathElement(CORE_SERVICE, MANAGEMENT),
            PathElement.pathElement(ACCESS, AUDIT),
            PathElement.pathElement(SYSLOG_HANDLER, SYSLOG_HANDLER_NAME));
    op = Util.createAddOperation(syslogHandlerAddress);
    op.get(FORMATTER).set(JSON_FORMATTER);
    op.get(SYSLOG_FORMAT).set("RFC5424");
    steps.add(op);
    op = new ModelNode();
    PathAddress syslogProtocol =
        PathAddress.pathAddress(syslogHandlerAddress, PathElement.pathElement(PROTOCOL, UDP));
    op = Util.createAddOperation(syslogProtocol);
    op.get("port").set(PORT);
    op.get("host").set("localhost");
    steps.add(op);
    result = client.execute(compositeOp);
    Assert.assertEquals(
        result.get("failure-description").asString(), SUCCESS, result.get(OUTCOME).asString());

    addSyslogHandler =
        PathAddress.pathAddress(
            auditLogConfigAddress, PathElement.pathElement(HANDLER, SYSLOG_HANDLER_NAME));
    op = Util.createAddOperation(addSyslogHandler);
    result = client.execute(op);
    Assert.assertEquals(
        result.get("failure-description").asString(), SUCCESS, result.get(OUTCOME).asString());

    container.stop(CONTAINER);
    Thread.sleep(1000);
    while (managementClient.isServerInRunningState()) {
      Thread.sleep(50);
    }
  }