-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24898 from OndroMih/ondromih-new-admin-console
Command recorder Admin Console plugin to configure admin command logging (with plain facelets, no JSF templating)
- Loading branch information
Showing
20 changed files
with
579 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.glassfish.main.admingui</groupId> | ||
<artifactId>admingui</artifactId> | ||
<version>7.0.16-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>console-commandrecorder-plugin</artifactId> | ||
<packaging>glassfish-jar</packaging> | ||
|
||
<name>Admin Console Command Recorder Plugin</name> | ||
<description>Command Recorder plugin bundle for GlassFish Admin Console</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.enterprise</groupId> | ||
<artifactId>jakarta.enterprise.cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.security.enterprise</groupId> | ||
<artifactId>jakarta.security.enterprise-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.main.admingui</groupId> | ||
<artifactId>console-common</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.main.extras</groupId> | ||
<artifactId>command-logger</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.main.admin</groupId> | ||
<artifactId>rest-service</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
75 changes: 75 additions & 0 deletions
75
...commandrecorder/src/main/java/org/glassfish/commandrecorder/admingui/CommandRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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 | ||
*/ | ||
package org.glassfish.commandrecorder.admingui; | ||
|
||
import static org.glassfish.extras.commandlogger.AdminCommandLogger.LogMode.NO_COMMAND; | ||
import static org.glassfish.extras.commandlogger.AdminCommandLogger.LogMode.WRITE_COMMANDS; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.enterprise.inject.Instance; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import javax.security.auth.Subject; | ||
import org.glassfish.api.ActionReport; | ||
import org.glassfish.api.admin.CommandRunner; | ||
import org.glassfish.api.admin.ParameterMap; | ||
import org.glassfish.extras.commandlogger.AdminCommandLogger; | ||
|
||
@Named | ||
@RequestScoped | ||
public class CommandRecorder { | ||
|
||
@Inject | ||
Instance<CommandRunner> commandRunnerProvider; | ||
|
||
@Inject | ||
Instance<ActionReport> actionReportProvider; | ||
|
||
@Inject | ||
Instance<Subject> subjectProvider; | ||
|
||
public boolean isEnabled() { | ||
return !NO_COMMAND.equals(AdminCommandLogger.LogMode.get()); | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
if (enabled) { | ||
setSystemProperty(WRITE_COMMANDS); | ||
} else { | ||
setSystemProperty(NO_COMMAND); | ||
} | ||
} | ||
|
||
private void setSystemProperty(AdminCommandLogger.LogMode propertyValue) { | ||
final CommandRunner.CommandInvocation commandInvocation = commandRunnerProvider.get().getCommandInvocation("create-system-properties", actionReportProvider.get(), subjectProvider.get()); | ||
commandInvocation.parameters(parameters(propertyValue)).execute(); | ||
} | ||
|
||
public void toggle() { | ||
setEnabled(!isEnabled()); | ||
} | ||
|
||
public String getToggleButtonTitle() { | ||
return (isEnabled() ? "Disable" : "Enable") + " logging commands"; | ||
} | ||
|
||
private ParameterMap parameters(AdminCommandLogger.LogMode propertyValue) { | ||
ParameterMap data = new ParameterMap(); | ||
data.add("target", "server"); | ||
data.add("DEFAULT", AdminCommandLogger.LogMode.PROPERTY_NAME + "=" + propertyValue.name()); | ||
return data; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...main/java/org/glassfish/commandrecorder/admingui/plugin/CommandRecorderConsolePlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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 | ||
*/ | ||
package org.glassfish.commandrecorder.admingui.plugin; | ||
|
||
import java.net.URL; | ||
import org.glassfish.api.admingui.ConsoleProvider; | ||
import org.jvnet.hk2.annotations.Service; | ||
|
||
@Service | ||
public class CommandRecorderConsolePlugin implements ConsoleProvider { | ||
|
||
@Override | ||
public URL getConfiguration() { | ||
return null; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
appserver/admingui/commandrecorder/src/main/resources/META-INF/admingui/console-config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
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 | ||
--> | ||
|
||
<console-config id="commandrecorder"> | ||
|
||
<integration-point | ||
id="commandrecorder_mastheadStatusArea" | ||
type="org.glassfish.admingui:mastheadStatusArea" | ||
priority="600" | ||
content="plugin/mastheadStatusArea.jsf" | ||
/> | ||
|
||
</console-config> |
38 changes: 38 additions & 0 deletions
38
...admingui/commandrecorder/src/main/resources/META-INF/resources/commandrecorder/menu.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version='1.0' encoding='UTF-8' ?> | ||
<!-- | ||
Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
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 | ||
--> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:h="jakarta.faces.html"> | ||
<h:head> | ||
<title>Command Recorder</title> | ||
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/theme/com/sun/webui/jsf/suntheme/css/css_master.css"/> | ||
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/yui/reset-fonts-grids.css"/> | ||
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/yui/assets/skins/sam/resize.css"/> | ||
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/yui/assets/skins/sam/layout.css"/> | ||
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resource/common/css/style.css"/> | ||
</h:head> | ||
<h:body> | ||
<h:form> | ||
<div style="text-align: left; height: 20px; background-color: #5b87a4"> | ||
<div class="mastheadButton_4_sun4" style="margin: 5px;"> | ||
<h:commandLink actionListener="#{commandRecorder.toggle()}">#{commandRecorder.toggleButtonTitle}</h:commandLink></div> | ||
</div> | ||
</h:form> | ||
</h:body> | ||
</html> |
20 changes: 20 additions & 0 deletions
20
...order/src/main/resources/META-INF/resources/commandrecorder/plugin/mastheadStatusArea.jsf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!-- | ||
Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
|
||
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 | ||
--> | ||
|
||
<f:verbatim> | ||
<iframe src="/commandrecorder/menu.xhtml" style="overflow:auto; width:600px; height:18px; border:0px;"> | ||
</iframe> | ||
</f:verbatim> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
appserver/admingui/core/src/main/java/org/glassfish/admingui/cdi/Hk2ServicesProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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 | ||
*/ | ||
package org.glassfish.admingui.cdi; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
import org.glassfish.api.ActionReport; | ||
import org.glassfish.api.admin.CommandRunner; | ||
import org.glassfish.internal.api.Globals; | ||
|
||
@ApplicationScoped | ||
public class Hk2ServicesProducer { | ||
|
||
@Produces | ||
CommandRunner getCommandRunner() { | ||
return getGlobalService(CommandRunner.class); | ||
} | ||
|
||
@Produces | ||
ActionReport getActionReport() { | ||
return getGlobalService(ActionReport.class); | ||
} | ||
|
||
private static <T> T getGlobalService(Class<T> aClass) { | ||
return Globals.getDefaultHabitat().getService(aClass); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
appserver/admingui/core/src/main/java/org/glassfish/admingui/cdi/SecurityProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* 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 | ||
*/ | ||
package org.glassfish.admingui.cdi; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.security.enterprise.SecurityContext; | ||
import java.security.Principal; | ||
import java.util.Set; | ||
import javax.security.auth.Subject; | ||
|
||
@ApplicationScoped | ||
public class SecurityProducer { | ||
|
||
@Produces | ||
Subject getSubject(SecurityContext securityContext) { | ||
return new Subject(true, securityContext.getPrincipalsByType(Principal.class), Set.of(), Set.of()); | ||
} | ||
|
||
} |
Oops, something went wrong.