Skip to content

Commit

Permalink
Merge pull request #24898 from OndroMih/ondromih-new-admin-console
Browse files Browse the repository at this point in the history
Command recorder Admin Console plugin to configure admin command logging (with plain facelets, no JSF templating)
  • Loading branch information
arjantijms authored Jul 17, 2024
2 parents b0c9e93 + dc5613f commit 2205e74
Show file tree
Hide file tree
Showing 20 changed files with 579 additions and 99 deletions.
66 changes: 66 additions & 0 deletions appserver/admingui/commandrecorder/pom.xml
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>
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;
}
}
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;
}
}
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>
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>
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>
10 changes: 10 additions & 0 deletions appserver/admingui/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
<name>Admin Console Core Jar</name>

<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.woodstock</groupId>
<artifactId>woodstock-webui-jsf</artifactId>
Expand Down
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);
}
}
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());
}

}
Loading

0 comments on commit 2205e74

Please sign in to comment.