Skip to content

Commit

Permalink
GH24992 Admin Logger: Moved command logger into a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
OndroMih committed Jun 22, 2024
1 parent e969cab commit 0b3e32e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3164,19 +3164,18 @@ specify the type through the `-H` option as follows:

It's possible to log admin commands executed either using the asadmin CLI, Admin Console, or the REST interface.

To enable this logging, set the system property `glassfish.commandrecorder.logmode` on the DAS server to one of the following values:
To enable this logging, set the system property `glassfish.commandlogger.logmode` on the DAS server to one of the following values:

* `ALL_COMMANDS` - will log all commands
* `WRITE_COMMANDS` - will log all commands that modify server configuration
* `INTERNAL_COMMANDS` - will log all commands that modify server configuration and also those that start with `_` (internal commands)
* `READ_WRITE_COMMANDS` - will log all commands that modify server configuration or return info about the configuration
* `NO_COMMAND` - do not log any command, this is the default value if the property not specified

The log message will contain:
The log message will be logged using `org.glassfish.extras.commandlogger.AdminCommandLogger` logger with `INFO` level, and will contain:

* name of the admin user that executed the command
* name of the command
* arguments to the command

The name and arguments can be copied and pasted to the asadmin CLI to repeat running the same command from the command line.

The name and arguments can be copied and pasted to the asadmin CLI to repeat running the same command from the command line.
45 changes: 45 additions & 0 deletions nucleus/extras/command-logger/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>nucleus-extras</artifactId>
<version>7.0.16-SNAPSHOT</version>
</parent>

<artifactId>command-logger</artifactId>
<packaging>glassfish-jar</packaging>

<name>Admin Command Logger</name>

<dependencies>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>internal-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.admin.rest.commandrecorder;
package org.glassfish.extras.commandlogger;

import static java.lang.System.Logger.Level.INFO;
import static java.lang.System.Logger.Level.WARNING;
Expand Down Expand Up @@ -41,9 +41,9 @@
@Service
@RunLevel(value = StartupRunLevel.VAL, mode = RunLevel.RUNLEVEL_MODE_NON_VALIDATING)
@MessageReceiver({CommandInvokedEvent.class})
public class AdminCommandRecorder {
public class AdminCommandLogger {

private static final System.Logger logger = System.getLogger(AdminCommandRecorder.class.getName());
private static final System.Logger logger = System.getLogger(AdminCommandLogger.class.getName());

public void receiveCommandInvokedEvent(@SubscribeTo CommandInvokedEvent event) {
logCommand(event.getCommandName(), event.getParameters(), event.getSubject());
Expand All @@ -64,7 +64,6 @@ public void logCommand(String commandName, ParameterMap parameters, Subject subj

private String constructCommandLine(String commandName, ParameterMap parameters) {
final String DEFAULT_PARAM_KEY = "DEFAULT";
final StringBuilder commandLineBuilder = new StringBuilder();
final Stream<String> namedParamsStream = parameters.entrySet().stream()
.filter(param -> !"userpassword".equals(param.getKey()))
.filter(param -> !DEFAULT_PARAM_KEY.equals(param.getKey()))
Expand All @@ -82,7 +81,7 @@ private static enum LogMode {
ALL_COMMANDS, INTERNAL_COMMANDS, WRITE_COMMANDS, READ_WRITE_COMMANDS, NO_COMMAND;

public static final LogMode DEFAULT = LogMode.WRITE_COMMANDS;
public static final String PROPERTY_NAME = "glassfish.commandrecorder.logmode";
public static final String PROPERTY_NAME = "glassfish.commandlogger.logmode";

public static LogMode get() {
final String logModeValue = TranslatedConfigView.expandValue("${" + LogMode.PROPERTY_NAME + "}");
Expand Down
38 changes: 38 additions & 0 deletions nucleus/extras/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glassfish.main</groupId>
<artifactId>glassfish-nucleus-parent</artifactId>
<version>7.0.16-SNAPSHOT</version>
</parent>

<groupId>org.glassfish.main.extras</groupId>
<artifactId>nucleus-extras</artifactId>
<packaging>pom</packaging>

<name>Nucleus extras</name>

<modules>
<module>command-logger</module>
</modules>
</project>
14 changes: 14 additions & 0 deletions nucleus/featuresets/nucleus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,19 @@
</exclusion>
</exclusions>
</dependency>

<!-- Nuclues extras -->
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>command-logger</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
</project>

0 comments on commit 0b3e32e

Please sign in to comment.