From 6127a281c53a3876bdf712f6099b91e418482b75 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 28 Mar 2019 13:55:15 +0000 Subject: [PATCH 01/14] PAYARA-3540 added admin audit service --- nucleus/admin/rest/rest-service/pom.xml | 5 + .../admin/rest/utils/ResourceUtil.java | 15 +- .../packager/asadmin-recorder-package/pom.xml | 54 +++-- nucleus/payara-modules/asadmin-audit/pom.xml | 79 +++++++ .../payara/audit/AdminAuditConfiguration.java | 94 ++++++++ .../fish/payara/audit/AdminAuditService.java | 201 ++++++++++++++++ .../java/fish/payara/audit/AuditLevel.java | 80 +++++++ .../admin/SetAdminAuditConfiguration.java | 137 +++++++++++ ...dminAuditServiceNotifierConfiguration.java | 222 ++++++++++++++++++ .../notification/domain/EventSource.java | 5 +- .../domain/NotificationEventFactory.java | 20 +- nucleus/payara-modules/pom.xml | 3 +- 12 files changed, 893 insertions(+), 22 deletions(-) create mode 100644 nucleus/payara-modules/asadmin-audit/pom.xml create mode 100644 nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java create mode 100644 nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java create mode 100644 nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AuditLevel.java create mode 100644 nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java create mode 100644 nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java diff --git a/nucleus/admin/rest/rest-service/pom.xml b/nucleus/admin/rest/rest-service/pom.xml index 0bb706a5d40..b6ad9ca750b 100644 --- a/nucleus/admin/rest/rest-service/pom.xml +++ b/nucleus/admin/rest/rest-service/pom.xml @@ -153,6 +153,11 @@ provided + + fish.payara.payara-modules + asadmin-audit + ${project.version} + fish.payara.payara-modules asadmin-recorder diff --git a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java index 5e8c155db63..99dd6ca4dc2 100644 --- a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java +++ b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java @@ -38,11 +38,14 @@ * holder. */ -// Portions Copyright [2016] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2019] [Payara Foundation and/or its affiliates] + package org.glassfish.admin.rest.utils; import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.config.serverbeans.Domain; + +import fish.payara.audit.AdminAuditService; import fish.payara.asadmin.recorder.AsadminRecorderService; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -251,12 +254,16 @@ public static RestActionReporter runCommand(String commandName, if (asadminRecorderService.isEnabled()) { asadminRecorderService.recordAsadminCommand(commandName, parameters); - } + } + + AdminAuditService auditService = Globals.getDefaultHabitat().getService(AdminAuditService.class); + if (auditService != null && auditService.isEnabled()) { + auditService.recordAsadminCommand(commandName, parameters, subject); + } CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class); RestActionReporter ar = new RestActionReporter(); - final CommandInvocation commandInvocation = - cr.getCommandInvocation(commandName, ar, subject); + final CommandInvocation commandInvocation = cr.getCommandInvocation(commandName, ar, subject); if (managedJob) { commandInvocation.managedJob(); } diff --git a/nucleus/packager/asadmin-recorder-package/pom.xml b/nucleus/packager/asadmin-recorder-package/pom.xml index 358b209f932..7e6caed0db0 100644 --- a/nucleus/packager/asadmin-recorder-package/pom.xml +++ b/nucleus/packager/asadmin-recorder-package/pom.xml @@ -1,22 +1,43 @@ + GPL Classpath Exception: + Oracle designates this particular file as subject to the "Classpath" + exception as provided by Oracle in the GPL Version 2 section of the License + file that accompanied this code. + + Modifications: + If applicable, add the following below the License Header, with the fields + enclosed by brackets [] replaced by your own identifying information: + "Portions Copyright [year] [name of copyright owner]" + + Contributor(s): + If you wish your version of this file to be governed by only the CDDL or + only the GPL Version 2, indicate your decision by adding "[Contributor] + elects to include this software in this distribution under the [CDDL or GPL + Version 2] license." If you don't indicate a single choice of license, a + recipient has the option to distribute your version of this file under + either the CDDL, the GPL Version 2 or to extend the choice of license to + its licensees as provided above. However, if you add GPL Version 2 code + and therefore, elected the GPL Version 2 license, then the option applies + only if the new code is made subject to such option by the copyright + holder. +--> 4.0.0 @@ -29,7 +50,7 @@ asadmin-recorder-package Nucleus Payara Asadmin Recorder Package distribution-fragment - This pom describes how to assemble the Nucleus Payara Asadmin Recorder package + This pom describes how to assemble the Nucleus Payara Asadmin Recorder and Audit package @@ -37,6 +58,11 @@ asadmin-recorder ${project.version} + + fish.payara.payara-modules + asadmin-audit + ${project.version} + diff --git a/nucleus/payara-modules/asadmin-audit/pom.xml b/nucleus/payara-modules/asadmin-audit/pom.xml new file mode 100644 index 00000000000..ee244aa7447 --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + fish.payara.payara-modules + payara-nucleus-modules + 5.192-SNAPSHOT + ../pom.xml + + asadmin-audit + glassfish-jar + Payara Asadmin Auditor + + + + org.glassfish.hk2 + hk2-core + + + org.glassfish.main.common + glassfish-api + ${project.version} + + + org.glassfish.main.common + internal-api + ${project.version} + + + fish.payara.payara-modules + notification-core + ${project.version} + + + fish.payara.payara-modules + notification-core + ${project.version} + + + diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java new file mode 100644 index 00000000000..65600a6d308 --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java @@ -0,0 +1,94 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.audit; + +import fish.payara.nucleus.notification.configuration.Notifier; + +import java.beans.PropertyVetoException; +import java.util.List; +import javax.validation.constraints.Pattern; + +import org.glassfish.api.admin.config.ConfigExtension; +import org.jvnet.hk2.config.Attribute; +import org.jvnet.hk2.config.ConfigBeanProxy; +import org.jvnet.hk2.config.Configured; +import org.jvnet.hk2.config.DuckTyped; +import org.jvnet.hk2.config.Element; + +/** + * + * @author jonathan + */ +@Configured +public interface AdminAuditConfiguration extends ConfigBeanProxy, ConfigExtension { + + @Attribute(defaultValue="false",dataType=Boolean.class) + String getEnabled(); + void enabled(String value) throws PropertyVetoException; + + @Attribute(defaultValue="MODIFIERS") + @Pattern(regexp = "MODIFIERS|ACCESSORS|INTERNAL", message = "Invalid audit level. Value must be one of: MODIFIERS, ACCESSORS or INTERNAL.") + String getAuditLevel(); + void setAuditLevel(String value) throws PropertyVetoException; + + @Element("*") + List getNotifierList(); + + @DuckTyped + T getNotifierByType(Class type); + + class Duck { + public static T getNotifierByType(AdminAuditConfiguration config, Class type) { + for (Notifier notifier : config.getNotifierList()) { + try { + return type.cast(notifier); + } catch (Exception e) { + // ignore, not the right type. + } + } + return null; + } + + } + +} diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java new file mode 100644 index 00000000000..292dae60f89 --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java @@ -0,0 +1,201 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.audit; + +import fish.payara.nucleus.notification.NotificationService; +import fish.payara.nucleus.notification.configuration.Notifier; +import fish.payara.nucleus.notification.configuration.NotifierConfigurationType; +import fish.payara.nucleus.notification.domain.EventSource; +import fish.payara.nucleus.notification.domain.NotificationEvent; +import fish.payara.nucleus.notification.domain.NotificationEventFactory; +import fish.payara.nucleus.notification.domain.NotifierExecutionOptions; +import fish.payara.nucleus.notification.domain.NotifierExecutionOptionsFactory; +import fish.payara.nucleus.notification.domain.NotifierExecutionOptionsFactoryStore; +import fish.payara.nucleus.notification.log.LogNotifierExecutionOptions; +import fish.payara.nucleus.notification.service.NotificationEventFactoryStore; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.security.auth.Subject; +import org.glassfish.api.StartupRunLevel; +import org.glassfish.api.admin.ParameterMap; +import org.glassfish.hk2.runlevel.RunLevel; +import org.glassfish.security.common.PrincipalImpl; +import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.ConfigView; + +/** + * Audit Admin commands and sends them to the notification services. + * + * Currently only for commands sent via the admin console. + * @author jonathan coustick + * @since 5.192 + */ +@Service(name = "asadmin-audit") +@RunLevel(StartupRunLevel.VAL) +public class AdminAuditService { + + private static final String AUDIT_MESSAGE = "AUDIT"; + private static final List ACCESSOR_COMMAND_START = Arrays.asList("_", "get", "list", "help", "version"); + + private boolean enabled; + private AuditLevel auditLevel = AuditLevel.MODIFIERS; + + @Inject + NotificationService notificationSevice; + + @Inject + private NotificationEventFactoryStore eventFactoryStore; + + @Inject + private NotifierExecutionOptionsFactoryStore executionOptionsFactoryStore; + + @Inject + AdminAuditConfiguration configuration; + + + private List notifierExecutionOptionsList; + + @PostConstruct + public void postConstruct() { + enabled = Boolean.valueOf(configuration.getEnabled()); + auditLevel = AuditLevel.valueOf(configuration.getAuditLevel()); + if (enabled) { + bootstrapNotifierList(); + } + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + if (!this.enabled && enabled) { + Logger.getLogger("fish.payara.audit").log(Level.INFO, "Admin Audit Service Started"); + bootstrapNotifierList(); + } + this.enabled = enabled; + } + + public AuditLevel getAuditLevel() { + return auditLevel; + } + + public void setAuditLevel(AuditLevel level){ + auditLevel = level; + } + + /** + * Starts all notifiers that have been enable with the admin audit service. + */ + public synchronized void bootstrapNotifierList() { + notifierExecutionOptionsList = new ArrayList<>(); + if (configuration.getNotifierList() != null) { + for (Notifier notifier : configuration.getNotifierList()) { + ConfigView view = ConfigSupport.getImpl(notifier); + NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class); + NotifierExecutionOptionsFactory factory = executionOptionsFactoryStore.get(annotation.type()); + if (factory != null) { + notifierExecutionOptionsList.add(factory.build(notifier)); + } + } + } + if (notifierExecutionOptionsList.isEmpty()) { + // Add logging execution options by default + LogNotifierExecutionOptions logNotifierExecutionOptions = new LogNotifierExecutionOptions(); + logNotifierExecutionOptions.setEnabled(true); + notifierExecutionOptionsList.add(logNotifierExecutionOptions); + } + } + + /** + * Gets a list of all the options of all notifiers configured with the asadmin audit service. + * @return + */ + public List getNotifierExecutionOptionsList() { + return notifierExecutionOptionsList; + } + + + public void recordAsadminCommand(String command, ParameterMap parameters, Subject subject) { + if (enabled && notifierExecutionOptionsList != null && checkAuditLevel(command)) { + + Set principals = subject.getPrincipals(PrincipalImpl.class); + String name = principals.iterator().next().getName(); + for (NotifierExecutionOptions notifierExecutionOptions : notifierExecutionOptionsList) { + + NotificationEventFactory notificationEventFactory = eventFactoryStore.get(notifierExecutionOptions.getNotifierType()); + NotificationEvent notificationEvent = notificationEventFactory + .buildNotificationEvent(Level.WARNING, AUDIT_MESSAGE, name + " issued command " + command + " with parameters " + parameters.toString(), null); + notificationSevice.notify(EventSource.AUDIT, notificationEvent); + } + } + } + + private boolean checkAuditLevel(String command) { + switch (auditLevel) { + case INTERNAL: + return true; + case ACCESSORS: + if (!command.startsWith("_")) { + return true; + } + break; + default: + for (String start: ACCESSOR_COMMAND_START) { + if (command.startsWith(start)) { + return false; + } + } + return true; + } + return false; + } + +} diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AuditLevel.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AuditLevel.java new file mode 100644 index 00000000000..99025f15b0e --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AuditLevel.java @@ -0,0 +1,80 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.audit; + +/** + * An enum for the levels of audit logging + * @author jonathan coustick + * @since 5.192 + */ +public enum AuditLevel { + + /** + * Admin commands that change + */ + MODIFIERS("Modifiers"), + /** + * {@code Modifiers} plus commands that retrieve information + */ + ACCESSORS("Accessors"), + /** + * All admin commands, including internal ones + */ + INTERNAL("Internal"); + + private final String value; + + AuditLevel(String value) { + this.value = value; + } + + /** + * Gets a {@link String} representation of the value + * of the enum. + * @return value + */ + public String getValue() { + return value; + } + +} diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java new file mode 100644 index 00000000000..54ca93695ae --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java @@ -0,0 +1,137 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.audit.admin; + +import org.glassfish.api.Param; +import org.glassfish.api.admin.AdminCommand; +import org.glassfish.api.admin.AdminCommandContext; + +import fish.payara.audit.AuditLevel; +import fish.payara.audit.AdminAuditConfiguration; +import fish.payara.audit.AdminAuditService; +import java.beans.PropertyVetoException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.inject.Inject; +import org.glassfish.api.ActionReport; +import org.glassfish.api.admin.ExecuteOn; +import org.glassfish.api.admin.RestEndpoint; +import org.glassfish.api.admin.RestEndpoints; +import org.glassfish.api.admin.RuntimeType; +import org.glassfish.config.support.CommandTarget; +import org.glassfish.config.support.TargetType; +import org.glassfish.hk2.api.PerLookup; +import org.glassfish.internal.api.Target; +import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.SingleConfigCode; +import org.jvnet.hk2.config.TransactionFailure; + +/** + * Sets the Admin Audit Configuration + * + * @author jonathan coustick + * @since 5.192 + */ +@Service(name = "set-admin-audit-configuration") +@PerLookup +@ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@RestEndpoints({ + @RestEndpoint(configBean = AdminAuditConfiguration.class, + opType = RestEndpoint.OpType.POST, + path = "set-admin-audit-configuration", + description = "Sets the Configuration for the Admin Audit Service") +}) +public class SetAdminAuditConfiguration implements AdminCommand { + + private static final Logger LOGGER = Logger.getLogger(SetAdminAuditConfiguration.class.getPackage().toString()); + + @Param(name = "dynamic", optional = true, defaultValue = "false") + private Boolean dynamic; + + @Param(name = "enabled") + private Boolean enabled; + + @Param(name = "auditLevel", optional = true, acceptableValues = "MODIFIERS, ACCESSORS, INTERNAL") + private String auditLevel; + + @Inject + private AdminAuditService auditService; + + @Inject + private AdminAuditConfiguration configuration; + + @Inject + private Target targetUtil; + + @Override + public void execute(AdminCommandContext context) { + ActionReport report = context.getActionReport(); + + try { + ConfigSupport.apply(new SingleConfigCode() { + @Override + public Object run(AdminAuditConfiguration configurationProxy) throws PropertyVetoException, TransactionFailure { + + configurationProxy.enabled(enabled.toString()); + configurationProxy.setAuditLevel(auditLevel); + return null; + } + }, configuration); + + if (dynamic) { + auditService.setEnabled(enabled); + auditService.setAuditLevel(AuditLevel.valueOf(auditLevel)); + } + } catch (TransactionFailure ex) { + LOGGER.log(Level.SEVERE, null, ex); + report.setMessage(ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage()); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + } + + report.setActionExitCode(ActionReport.ExitCode.SUCCESS); + + } + +} diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java new file mode 100644 index 00000000000..1de4fb8c4e9 --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java @@ -0,0 +1,222 @@ +/* + * + * Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.audit.admin; + +import java.beans.PropertyVetoException; +import java.lang.reflect.Proxy; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +import javax.inject.Inject; + +import org.glassfish.api.ActionReport; +import org.glassfish.api.Param; +import org.glassfish.api.admin.AdminCommand; +import org.glassfish.api.admin.AdminCommandContext; +import org.glassfish.api.admin.ExecuteOn; +import org.glassfish.api.admin.RestEndpoint; +import org.glassfish.api.admin.RestEndpoints; +import org.glassfish.api.admin.RuntimeType; +import org.glassfish.api.admin.ServerEnvironment; +import org.glassfish.config.support.CommandTarget; +import org.glassfish.config.support.TargetType; +import org.glassfish.hk2.api.PerLookup; +import org.glassfish.internal.api.Target; +import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.SingleConfigCode; +import org.jvnet.hk2.config.TransactionFailure; + +import com.sun.enterprise.config.modularity.ConfigModularityUtils; +import com.sun.enterprise.config.serverbeans.Config; +import com.sun.enterprise.util.SystemPropertyConstants; + +import fish.payara.audit.AdminAuditConfiguration; +import fish.payara.audit.AdminAuditService; + +import fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration; +import fish.payara.nucleus.notification.configuration.Notifier; +import fish.payara.nucleus.notification.configuration.NotifierConfiguration; +import fish.payara.nucleus.notification.configuration.NotifierConfigurationType; +import fish.payara.nucleus.notification.configuration.NotifierType; + +/** + * Admin command to set enabled and noisy flags for a specific {@link Notifier} configuration as part of the + * {@link AdminAuditConfiguration}. + * + * This should not be confused with the {@link NotifierConfiguration} itself for that specific {@link Notifier} that + * exists as part of {@link NotificationServiceConfiguration}. + * + * When {@link #noisy} parameter is not specified the according {@link NotifierConfiguration} is loaded from the + * {@link NotificationServiceConfiguration} to use its {@link NotifierConfiguration#getNoisy()} as automatic fallback + * setting. + * + * @author jonathan coustick + * @since 5.191 + */ +@Service(name = "set-admin-audit-service-notifier-configuration") +@PerLookup +@ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@RestEndpoints({ + @RestEndpoint(configBean = AdminAuditConfiguration.class, + opType = RestEndpoint.OpType.POST, + path = "set-admin-audit-service-notifier-configuration", + description = "Sets the Configuration for specific Notifier for the Admin Audit Service") +}) +public class SetAdminAuditServiceNotifierConfiguration implements AdminCommand { + + @Inject + private Target targetUtil; + + @Inject + private ServerEnvironment server; + + @Inject + private ConfigModularityUtils configModularityUtils; + + @Inject + private AdminAuditService auditService; + + @Param(name = "dynamic", optional = true, defaultValue = "false") + private Boolean dynamic; + + @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) + private String target; + private Config targetConfig; + + @Param(name = "enabled") + private Boolean enabled; + + @Param(name = "noisy", optional = true) + private Boolean noisy; + + @Param(name = "notifier") + private String notifierName; + private NotifierType notifierType; + + private ActionReport report; + + private static final Logger LOGGER = Logger.getLogger(SetAdminAuditServiceNotifierConfiguration.class.getPackage().toString()); + + @Override + public void execute(AdminCommandContext context) { + report = context.getActionReport(); + Properties extraProperties = report.getExtraProperties(); + if (extraProperties == null) { + extraProperties = new Properties(); + report.setExtraProperties(extraProperties); + } + try { + notifierType = NotifierType.valueOf(notifierName.toUpperCase()); + } catch (IllegalArgumentException e) { + String values = Arrays.asList(NotifierType.values()) + .stream().map(t -> t.name().toLowerCase()).collect(Collectors.joining(",")); + report.setMessage("Unknown notifier `" + notifierName + "`. Known are: " + values); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + return; + } + targetConfig = targetUtil.getConfig(target); + + final AdminAuditConfiguration config = targetConfig.getExtensionByType(AdminAuditConfiguration.class); + final Notifier notifier = selectByType(Notifier.class, config.getNotifierList()); + try { + if (notifier == null) { + ConfigSupport.apply((SingleConfigCode) configProxy -> { + @SuppressWarnings("unchecked") + Notifier newNotifier = configProxy.createChild(selectByType(Class.class, configModularityUtils.getInstalledExtensions(Notifier.class))); + configProxy.getNotifierList().add(newNotifier); + applyValues(newNotifier); + return configProxy; + }, config); + } else { + ConfigSupport.apply(notifierProxy -> { + applyValues(notifierProxy); + return notifierProxy; + }, notifier); + } + } catch (TransactionFailure ex) { + LOGGER.log(Level.WARNING, "Exception during command ", ex); + report.setMessage(ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage()); + report.setActionExitCode(ActionReport.ExitCode.FAILURE); + } + } + + private void applyValues(Notifier notifier) throws PropertyVetoException { + if (Boolean.parseBoolean(notifier.getEnabled()) != enabled) { + report.appendMessage(notifierName + ".enabled was " + notifier.getEnabled() + " set to " + enabled + "\n"); + notifier.enabled(enabled); + } + if (this.noisy == null) { + // inherit setting from the notifier's configuration + NotifierConfiguration config = selectByType(NotifierConfiguration.class, targetConfig + .getExtensionByType(NotificationServiceConfiguration.class).getNotifierConfigurationList()); + if (config != null) { + noisy = "true".equalsIgnoreCase("" + config.getNoisy()); + } + } + if (noisy != null && Boolean.parseBoolean(notifier.getNoisy()) != noisy) { + report.appendMessage(notifierName + ".noisy was " + notifier.getNoisy() + " set to " + noisy + "\n"); + notifier.noisy(noisy); + } + report.setActionExitCode(ActionReport.ExitCode.SUCCESS); + } + + private T selectByType(Class commonInterface, List candidates) { + for (T candidate : candidates) { + Class annotatedType = candidate instanceof Class ? (Class) candidate : candidate.getClass(); + if (Proxy.isProxyClass(annotatedType)) { + for (Class i : annotatedType.getInterfaces()) { + if (commonInterface.isAssignableFrom(i)) { + annotatedType = i; + } + } + } + NotifierConfigurationType type = annotatedType.getAnnotation(NotifierConfigurationType.class); + if (type != null && type.type() == notifierType) { + return candidate; + } + } + return null; + } +} diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/EventSource.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/EventSource.java index a154955cdb9..04639548876 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/EventSource.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/EventSource.java @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2017 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2017-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -44,7 +44,8 @@ public enum EventSource { HEALTHCHECK("HealthCheck"), REQUESTTRACING("RequestTracing"), - MONITORING("Monitoring"); + MONITORING("Monitoring"), + AUDIT("Audit"); private final String value; diff --git a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/NotificationEventFactory.java b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/NotificationEventFactory.java index 792ed1d4c89..d3cca7dfefc 100644 --- a/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/NotificationEventFactory.java +++ b/nucleus/payara-modules/notification-core/src/main/java/fish/payara/nucleus/notification/domain/NotificationEventFactory.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016-2018 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -56,7 +56,9 @@ import java.util.logging.Level; /** + * Factory for building {@link NotificationEvent} * @author mertcaliskan + * @since 4.1.2.171 */ @Contract public abstract class NotificationEventFactory { @@ -90,6 +92,13 @@ protected E initializeEvent(E e) { protected abstract E createEventInstance(); + /** + * Creates a {@link NotificationEvent} + * @param subject Subject of the message + * i.e. what the subject line is if the event is sent to the Javamail notifier + * @param message The message text of the event + * @return the resulting {@link NotificationEvent} + */ public E buildNotificationEvent(String subject, String message) { E event = initializeEvent(createEventInstance()); event.setSubject(subject); @@ -117,6 +126,15 @@ public E buildNotificationEvent(String name, List entrie return event; } + /** + * Creates a {@link NotificationEvent} + * @param level Severity level of notification. This is unused in the base factory + * @param subject Subject of the message + * i.e. what the subject line is if the event is sent to the Javamail notifier + * @param message The message text of the event + * @param parameters An additional parameters to be formatted as part of the message + * @return the resulting {@link NotificationEvent} + */ public E buildNotificationEvent(Level level, String subject, String message, Object[] parameters) { E event = initializeEvent(createEventInstance()); event.setSubject(subject); diff --git a/nucleus/payara-modules/pom.xml b/nucleus/payara-modules/pom.xml index 132c64e050d..0e2903f9654 100755 --- a/nucleus/payara-modules/pom.xml +++ b/nucleus/payara-modules/pom.xml @@ -2,7 +2,7 @@ + @@ -83,6 +88,14 @@ removeEmptyProps(props="#{pageSession.tableList}" modifiedProps="#{pageSession.tableList}"); javaToJSON(obj="#{pageSession.tableList}" json="#{requestScope.tmpJSON}"); gf.restRequest(endpoint="#{pageSession.selfUrl}/property.json", method="POST", data="#{requestScope.tmpJSON}", result="#{requestScope.restResponse}"); + + gf.createEntity(endpoint="#{pageSession.adminAuditUrl}" + attrs="#{pageSession.adminAudit}" + skipAttrs="#{pageSession.skipAttrsList}" + convertToFalse="#{pageSession.convertToFalseList}" + ); + + prepareSuccessfulMsg(); gf.redirect(page="#{pageSession.selfPage}&alertType=${alertType}&alertSummary=${alertSummary}&alertDetail=${alertDetail}"); /> diff --git a/appserver/admingui/common/src/main/resources/security/securityAttrs.inc b/appserver/admingui/common/src/main/resources/security/securityAttrs.inc index f506d5cc30a..7c92b52934a 100644 --- a/appserver/admingui/common/src/main/resources/security/securityAttrs.inc +++ b/appserver/admingui/common/src/main/resources/security/securityAttrs.inc @@ -39,6 +39,7 @@ holder. --> + @@ -54,6 +55,9 @@ /> + + + diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java new file mode 100644 index 00000000000..5b8e30dba38 --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java @@ -0,0 +1,120 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.audit.admin; + +import com.sun.enterprise.util.ColumnFormatter; +import fish.payara.audit.AdminAuditConfiguration; +import fish.payara.nucleus.notification.configuration.Notifier; +import java.util.Properties; +import javax.inject.Inject; +import org.glassfish.api.ActionReport; +import org.glassfish.api.admin.AdminCommand; +import org.glassfish.api.admin.AdminCommandContext; +import org.glassfish.api.admin.CommandLock; +import org.glassfish.api.admin.ExecuteOn; +import org.glassfish.api.admin.RestEndpoint; +import org.glassfish.api.admin.RestEndpoints; +import org.glassfish.api.admin.RuntimeType; +import org.glassfish.config.support.CommandTarget; +import org.glassfish.config.support.TargetType; +import org.glassfish.hk2.api.PerLookup; +import org.jvnet.hk2.annotations.Service; + +/** + * Gets the current configuration of the admin audit service + * @author jonathan coustick + * @since 5.192 + */ +@Service(name = "get-admin-audit-configuration") +@PerLookup +@CommandLock(CommandLock.LockType.NONE) +@ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@RestEndpoints({ + @RestEndpoint(configBean = AdminAuditConfiguration.class, + opType = RestEndpoint.OpType.GET, + path = "get-admin-audit-configuration", + description = "Gets the current configuration settings of the admin audit Service") +}) +public class GetAdminAuditServiceConfiguration implements AdminCommand { + + private final static String[] headers = {"Enabled", "Audit Level"}; + private final static String[] notifierHeaders= {"Name", "Notifier Enabled"}; + + @Inject + private AdminAuditConfiguration config; + + @Override + public void execute(AdminCommandContext context) { + + final ActionReport actionReport = context.getActionReport(); + + ColumnFormatter columnFormatter = new ColumnFormatter(headers); + ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(notifierHeaders); + + Object[] values = {config.getEnabled(), config.getAuditLevel()}; + columnFormatter.addRow(values); + + Properties extraProperties = new Properties(); + extraProperties.put(headers[0], config.getEnabled()); + extraProperties.put(headers[1], config.getAuditLevel()); + + ActionReport notifiersReport = actionReport.addSubActionsReport(); + + Properties notifierProps = new Properties(); + for (Notifier notifier: config.getNotifierList()) { + Object[] notifierValues = { notifier.toString(), notifier.getEnabled()}; + notifiersColumnFormatter.addRow(notifierValues); + notifierProps.put(notifier.toString(), notifier.getEnabled()); + } + notifiersReport.setMessage(notifiersColumnFormatter.toString()); + extraProperties.put("notifiers", notifierProps); + + + actionReport.setExtraProperties(extraProperties); + + actionReport.setMessage(columnFormatter.toString()); + actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); + } + +} diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java index 54ca93695ae..6b4842f9068 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java @@ -61,7 +61,6 @@ import org.glassfish.config.support.CommandTarget; import org.glassfish.config.support.TargetType; import org.glassfish.hk2.api.PerLookup; -import org.glassfish.internal.api.Target; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.config.ConfigSupport; import org.jvnet.hk2.config.SingleConfigCode; @@ -102,9 +101,6 @@ public class SetAdminAuditConfiguration implements AdminCommand { @Inject private AdminAuditConfiguration configuration; - @Inject - private Target targetUtil; - @Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); From a605bda3f10cddd79551fba3a6a3c2ea661638c0 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Mon, 8 Apr 2019 09:18:20 +0100 Subject: [PATCH 03/14] PAYARA-3111 move options to own page in admin console --- .../common/admingui/Strings.properties | 4 + .../security/adminAudit/adminaudit.jsf | 165 ++++++++++++++++++ .../src/main/resources/templates/menu.inc | 2 + .../org/glassfish/internal/api/Globals.java | 5 +- 4 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf diff --git a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties index 55d31b8ffcf..1f4d49c864f 100644 --- a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties +++ b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties @@ -105,6 +105,10 @@ security.secureAdmin.instancealias=Instance Alias: security.secureAdmin.instancealiasHelp=The alias that refers to the SSL/TLS certificate on the instances. This alias is used by the DAS to authenticate against the instances. security.secureLabel=Secure Administration: +## Admin Audit +adminAudit.PageTitle=Admin Audit +adminaudit.PageHelp=Options for the admin commands audit system + ## Realms realm.NewPageTitle=New Realm diff --git a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf new file mode 100644 index 00000000000..f2d54d34ac7 --- /dev/null +++ b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf @@ -0,0 +1,165 @@ + + + + + + + + + + + #include "/common/monitor/monitoringConfigTabs.inc" +#include "/common/shared/alertMsg.inc" + + + + + + + + + + + + + #include "/common/shared/configNameSection.inc" + + + + + + + + + "

+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + diff --git a/appserver/admingui/core/src/main/resources/templates/menu.inc b/appserver/admingui/core/src/main/resources/templates/menu.inc index 35b21e83341..46903dc7994 100644 --- a/appserver/admingui/core/src/main/resources/templates/menu.inc +++ b/appserver/admingui/core/src/main/resources/templates/menu.inc @@ -39,6 +39,7 @@ holder. --> + @@ -77,6 +78,7 @@ + diff --git a/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java b/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java index 1e85f672e6f..01d9834b098 100644 --- a/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java +++ b/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. * - * Portions Copyright [2017] Payara Foundation and/or affiliates + * Portions Copyright [2017-2019] Payara Foundation and/or affiliates */ package org.glassfish.internal.api; @@ -45,13 +45,12 @@ import com.sun.enterprise.module.ModulesRegistry; import com.sun.enterprise.module.single.StaticModulesRegistry; import org.jvnet.hk2.annotations.Service; -import org.glassfish.common.util.Constants; -import org.glassfish.hk2.api.Rank; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.runlevel.RunLevel; import com.sun.enterprise.config.serverbeans.ConfigBeansUtilities; import javax.inject.Inject; import javax.inject.Singleton; +import org.jvnet.hk2.annotations.Optional; /** * Global class for storing the service locator for all hk2 services From 86bd2b289e39cb3dd68a05fe79a1354902087a51 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Mon, 8 Apr 2019 17:47:02 +0100 Subject: [PATCH 04/14] Attemp to fix admin console integration --- .../src/main/resources/security/adminAudit/adminaudit.jsf | 8 ++------ appserver/pom.xml | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf index f2d54d34ac7..94826c9b1a3 100644 --- a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf +++ b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf @@ -44,8 +44,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. setResourceBundle(key="i18nc" bundle="org.glassfish.admingui.core.Strings"); /> - @@ -56,11 +55,8 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. setPageSessionAttribute(key="ADMIN_AUDIT_URL", value="#{sessionScope.REST_URL}/configs/config/#{pageSession.configName}/admin-audit-configuration"); - gf.restRequest(endpoint="#{sessionScope.REST_URL}/get-admin-audit-configuration?target=#{pageSession.configName}" - method="GET" result="#{requestScope.resp}"); + gf.restRequest(endpoint="#{pageSession.ADMIN_AUDIT_URL}" method="GET" result="#{requestScope.resp}"); - gf.restRequest(endpoint="#{pageSession.ADMIN_AUDIT_URL}/monitored-attribute.json" method="GET" result="#{requestScope.propTable}") - setPageSessionAttribute(key="tableList" value="#{requestScope.propTable.data.extraProperties.monitoredAttributes}"); setPageSessionAttribute(key="valueMap", value="#{requestScope.resp.data.extraProperties.adminauditConfiguration}"); setPageSessionAttribute(key="valueNotifierMap", value="#{requestScope.resp.data.extraProperties.notifierListLOG}"); mapPut(map="#{pageSession.valueMap}" key="target" value="#{pageSession.configName}"); diff --git a/appserver/pom.xml b/appserver/pom.xml index 8643c33d868..0c87b1b0e6e 100644 --- a/appserver/pom.xml +++ b/appserver/pom.xml @@ -180,7 +180,7 @@ payara${major_version} 0.2 - 2.1.3 + 2.1.5-SNAPSHOT 4.0.2.10.payara-p15 1.122-57.2889 From 69c6b5682df2b32950bf5e9b9912382e4c751027 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Tue, 9 Apr 2019 10:49:32 +0100 Subject: [PATCH 05/14] PAYARA-3111 admin console integration now works, but localisation fails --- .../common/admingui/Strings.properties | 2 ++ .../main/resources/pluginTreeNodeSecurity.jsf | 15 +++++++++++++ .../security/adminAudit/adminaudit.jsf | 2 +- .../admingui/core/Strings.properties | 1 + .../admin/rest/utils/ResourceUtil.java | 2 +- .../GetAdminAuditServiceConfiguration.java | 22 +++++++++++++------ 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties index 1f4d49c864f..7f2ba849e9c 100644 --- a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties +++ b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties @@ -108,6 +108,8 @@ security.secureLabel=Secure Administration: ## Admin Audit adminAudit.PageTitle=Admin Audit adminaudit.PageHelp=Options for the admin commands audit system +adminAudit.Title=AdminAudit +adminaudit.Title=Admin Audit ## Realms diff --git a/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf b/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf index e3cb79a2c78..bc8e4cb7448 100644 --- a/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf +++ b/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf @@ -39,6 +39,7 @@ holder. --> + @@ -50,6 +51,20 @@ + + + + + + map = new HashMap<>(); Properties extraProperties = new Properties(); - extraProperties.put(headers[0], config.getEnabled()); - extraProperties.put(headers[1], config.getAuditLevel()); + map.put(ATTRIBUTE_HEADERS[0], config.getEnabled()); + map.put(ATTRIBUTE_HEADERS[1], config.getAuditLevel()); + extraProperties.put("adminauditConfiguration", map); ActionReport notifiersReport = actionReport.addSubActionsReport(); From 3420dbb93723ea430a36152ea445301beefc238d Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Wed, 10 Apr 2019 14:47:08 +0100 Subject: [PATCH 06/14] PAYARA-3111 some localisations for the audit service in the admin console now work --- .../common/admingui/Strings.properties | 11 ++++- .../main/resources/pluginTreeNodeSecurity.jsf | 2 +- .../security/adminAudit/adminaudit.jsf | 40 +++++++------------ .../admingui/core/Strings.properties | 20 ++++++++++ .../GetAdminAuditServiceConfiguration.java | 4 -- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties index 7f2ba849e9c..400b52e1926 100644 --- a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties +++ b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties @@ -108,8 +108,17 @@ security.secureLabel=Secure Administration: ## Admin Audit adminAudit.PageTitle=Admin Audit adminaudit.PageHelp=Options for the admin commands audit system -adminAudit.Title=AdminAudit adminaudit.Title=Admin Audit +adminaudit.Enabled=Enabled +adminaudit.EnabledHelp=Enable the admin audit service +adminaudit.Dynamic=Dynamic +adminaudit.DynamicHelp=Make the changes take effect immediately +adminaudit.configuration.availableNotifiers=Available Notifiers +adminaudit.configuration.selectedNotifiers=Selected Notifiers +adminaudit.link.to.notification.page.text.prefix=Selected Notifiers need to be enabled also in the +adminaudit.link.to.notification.page.text=Notification Service +adminaudit.link.to.notification.page.text.suffix=to receive notifications. +adminaudit.link.to.notification.page.text.prefix= ## Realms diff --git a/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf b/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf index bc8e4cb7448..dba61d02f70 100644 --- a/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf +++ b/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf @@ -61,7 +61,7 @@ text="$resource{i18n.tree.adminAudit}" url="#{request.contextPath}/common/security/adminAudit/adminaudit.jsf?configName=${configName}"> - diff --git a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf index 4409c19ed32..46bfd2b9927 100644 --- a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf +++ b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf @@ -44,7 +44,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. setResourceBundle(key="i18nc" bundle="org.glassfish.admingui.core.Strings"); /> - @@ -82,14 +82,13 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. /> - #include "/common/monitor/monitoringConfigTabs.inc" #include "/common/shared/alertMsg.inc" - + - + - - + + - - + + "

@@ -128,32 +127,21 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. selectAll="$boolean{true}" items="#{pageSession.allNotifiers}" selected="#{pageSession.enabledNotifiersArr}" - availableItemsLabel="$resource{i18n.adminaudit.configuration.availableNotifiers}" - selectedItemsLabel="$resource{i18n.adminaudit.configuration.selectedNotifiers}"> + availableItemsLabel="$resource{i18nc.adminaudit.configuration.availableNotifiers}" + selectedItemsLabel="$resource{i18nc.adminaudit.configuration.selectedNotifiers}">
- + - + - + - - - - - - - - -
diff --git a/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties b/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties index 0f8044a6f5e..243c2237582 100644 --- a/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties +++ b/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties @@ -1204,3 +1204,23 @@ cdi.cdiServicePageTitle=CDI Service Configuration cdi.cdiServicePageTitleHelp= cdi.implicitScanning=Implicit CDI Scanning cdi.implicitScanningHelp= + +# Admin audit service +adminaudit.PageTitle=Admin Audit Service +adminaudit.PageHelp=Admin AuditPageHelp +adminAudit.PageTitle=Admin Audit +adminaudit.PageHelp=Options for the admin commands audit system +adminAudit.Title=AdminAudit +adminaudit.Title=Admin Audit +adminAudit.PageTitle=Admin Audit +adminaudit.PageHelp=Options for the admin commands audit system +adminaudit.Title=Admin Audit +adminaudit.Enabled=Enabled +adminaudit.EnabledHelp=Enable the admin audit service +adminaudit.Dynamic=Dynamic +adminaudit.DynamicHelp=Make the changes take effect immediately +adminaudit.configuration.availableNotifiers=Available Notifiers +adminaudit.configuration.selectedNotifiers=Selected Notifiers +adminaudit.link.to.notification.page.text.prefix=Selected Notifiers need to be enabled also in the +adminaudit.link.to.notification.page.text=Notification Service +adminaudit.link.to.notification.page.text.suffix=to receive notifications. \ No newline at end of file diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java index 9fe24d2c7e1..19649c3ed78 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java @@ -42,14 +42,10 @@ */ package fish.payara.audit.admin; -import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.util.ColumnFormatter; -import com.sun.enterprise.util.SystemPropertyConstants; import fish.payara.audit.AdminAuditConfiguration; import fish.payara.nucleus.notification.configuration.Notifier; -import fish.payara.nucleus.notification.service.BaseNotifierService; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Properties; import javax.inject.Inject; From 29db0102e34480ff66bc88cf4aa554deaf744042 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 11 Apr 2019 15:50:36 +0100 Subject: [PATCH 07/14] PAYARA-3111 stopped adminaudit in the admin console having child pages --- .../common/src/main/resources/pluginTreeNodeSecurity.jsf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf b/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf index dba61d02f70..9c2a9dca012 100644 --- a/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf +++ b/appserver/admingui/common/src/main/resources/pluginTreeNodeSecurity.jsf @@ -52,9 +52,14 @@ alt="$resource{i18n.tree.security}" border="0" immediate="true" /> + + + + Date: Wed, 17 Apr 2019 16:38:27 +0100 Subject: [PATCH 08/14] PAYARA-3111 Button now appears in admin console, changes can be saved Currently available notifiers are not shown however --- .../security/adminAudit/adminaudit.jsf | 21 +++++++++---------- .../admingui/core/Strings.properties | 2 ++ .../extras/rest/PayaraRestApiHandlers.java | 18 ++++++++++++---- .../datadog/DatadogNotifierService.java | 4 ++-- .../fish/payara/audit/AdminAuditService.java | 12 ++++++----- .../GetAdminAuditServiceConfiguration.java | 4 ++-- .../admin/SetAdminAuditConfiguration.java | 13 +++++++++++- 7 files changed, 49 insertions(+), 25 deletions(-) diff --git a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf index 46bfd2b9927..257ce499e5d 100644 --- a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf +++ b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf @@ -53,9 +53,9 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. getRequestValue(key="configName" value="#{pageSession.configName}"); setPageSessionAttribute(key="ADMIN_AUDIT_URL", - value="#{sessionScope.REST_URL}/configs/config/#{pageSession.configName}/admin-audit-configuration/get-admin-audit-configuration"); + value="#{sessionScope.REST_URL}/configs/config/#{pageSession.configName}/admin-audit-configuration"); - gf.restRequest(endpoint="#{pageSession.ADMIN_AUDIT_URL}" method="GET" result="#{requestScope.resp}"); + gf.restRequest(endpoint="#{pageSession.ADMIN_AUDIT_URL}/get-admin-audit-configuration" method="GET" result="#{requestScope.resp}"); setPageSessionAttribute(key="valueMap", value="#{requestScope.resp.data.extraProperties.adminauditConfiguration}"); setPageSessionAttribute(key="valueNotifierMap", value="#{requestScope.resp.data.extraProperties.notifierListLOG}"); @@ -85,27 +85,22 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. #include "/common/shared/alertMsg.inc" - - @@ -117,7 +112,11 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - + + + + "

diff --git a/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties b/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties index 243c2237582..5ebe42b377e 100644 --- a/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties +++ b/appserver/admingui/core/src/main/resources/org/glassfish/admingui/core/Strings.properties @@ -1219,6 +1219,8 @@ adminaudit.Enabled=Enabled adminaudit.EnabledHelp=Enable the admin audit service adminaudit.Dynamic=Dynamic adminaudit.DynamicHelp=Make the changes take effect immediately +adminaudit.UnitLabel=Audit Level +adminaudit.UnitLabelHelp=The level of admin commands to audit adminaudit.configuration.availableNotifiers=Available Notifiers adminaudit.configuration.selectedNotifiers=Selected Notifiers adminaudit.link.to.notification.page.text.prefix=Selected Notifiers need to be enabled also in the diff --git a/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java b/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java index 142e09aacc5..fc115460f9e 100644 --- a/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java +++ b/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2018] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2016-2019] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -574,10 +574,12 @@ public static void updateNotifiers(HandlerContext handlerCtx) { boolean forRequestTracing = false; boolean forHealthCheck = false; boolean forMonitoring = false; + boolean forAdminAudit = false; for (String notifier : notifiers){ String name = notifier.split("-")[1]; String restEndpoint; + HashMap attrs = new HashMap<>(); if (endpoint.contains("request-tracing-service-configuration")){ restEndpoint = endpoint + "/requesttracing-" + name + "-notifier-configure"; forRequestTracing = true; @@ -587,19 +589,27 @@ public static void updateNotifiers(HandlerContext handlerCtx) { } else if (endpoint.contains("monitoring-service-configuration")){ restEndpoint = endpoint + "/monitoring-" + name + "-notifier-configure"; forMonitoring = true; + } else if (endpoint.contains("admin-audit-configuration")) { + restEndpoint = endpoint + "/set-admin-audit-service-notifier-configuration"; + attrs.put("notifier", name); + forAdminAudit = true; } else { //Unknown service being configured throw new UnknownConfigurationException(); } - HashMap attrs = new HashMap<>(); + if (enabledNotifiers.contains(notifier)){ attrs.put("enabled", "true"); } else { attrs.put("enabled", "false"); } - //PAYARA-1616 go silent, bootstrap will take place after iteration. - attrs.put("dynamic", "false"); + if (!forAdminAudit) { + //PAYARA-1616 go silent, bootstrap will take place after iteration. + attrs.put("dynamic", "false"); + } else { + attrs.put("dynamic", "true"); + } attrs.put("target", target); RestUtil.restRequest(restEndpoint, attrs, "post", handlerCtx, quiet, throwException); } diff --git a/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java b/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java index 94273b40ef4..53f59e31e0a 100644 --- a/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java +++ b/appserver/payara-appserver-modules/notification-datadog-core/src/main/java/fish/payara/notification/datadog/DatadogNotifierService.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2017 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2017-2019 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -66,7 +66,7 @@ public class DatadogNotifierService extends QueueBasedNotifierService principals = subject.getPrincipals(PrincipalImpl.class); String name = principals.iterator().next().getName(); for (NotifierExecutionOptions notifierExecutionOptions : notifierExecutionOptionsList) { - - NotificationEventFactory notificationEventFactory = eventFactoryStore.get(notifierExecutionOptions.getNotifierType()); - NotificationEvent notificationEvent = notificationEventFactory - .buildNotificationEvent(Level.WARNING, AUDIT_MESSAGE, name + " issued command " + command + " with parameters " + parameters.toString(), null); - notificationSevice.notify(EventSource.AUDIT, notificationEvent); + + if (notifierExecutionOptions.isEnabled()) { + NotificationEventFactory notificationEventFactory = eventFactoryStore.get(notifierExecutionOptions.getNotifierType()); + NotificationEvent notificationEvent = notificationEventFactory + .buildNotificationEvent(Level.WARNING, AUDIT_MESSAGE, name + " issued command " + command + " with parameters " + parameters.toString(), null); + notificationSevice.notify(EventSource.AUDIT, notificationEvent); + } } } } diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java index 19649c3ed78..7b5bd4f2d8a 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java @@ -99,8 +99,8 @@ public void execute(AdminCommandContext context) { Map map = new HashMap<>(); Properties extraProperties = new Properties(); - map.put(ATTRIBUTE_HEADERS[0], config.getEnabled()); - map.put(ATTRIBUTE_HEADERS[1], config.getAuditLevel()); + map.put("enabled", config.getEnabled()); + map.put("auditLevel", config.getAuditLevel()); extraProperties.put("adminauditConfiguration", map); ActionReport notifiersReport = actionReport.addSubActionsReport(); diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java index 6b4842f9068..f75ac4500aa 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java @@ -42,6 +42,8 @@ */ package fish.payara.audit.admin; +import com.sun.enterprise.config.serverbeans.Config; +import com.sun.enterprise.util.SystemPropertyConstants; import org.glassfish.api.Param; import org.glassfish.api.admin.AdminCommand; import org.glassfish.api.admin.AdminCommandContext; @@ -61,6 +63,7 @@ import org.glassfish.config.support.CommandTarget; import org.glassfish.config.support.TargetType; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.internal.api.Target; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.config.ConfigSupport; import org.jvnet.hk2.config.SingleConfigCode; @@ -94,16 +97,24 @@ public class SetAdminAuditConfiguration implements AdminCommand { @Param(name = "auditLevel", optional = true, acceptableValues = "MODIFIERS, ACCESSORS, INTERNAL") private String auditLevel; + + @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) + private String target; + private Config targetConfig; @Inject private AdminAuditService auditService; @Inject - private AdminAuditConfiguration configuration; + private Target targetUtil; @Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); + + targetConfig = targetUtil.getConfig(target); + + final AdminAuditConfiguration configuration = targetConfig.getExtensionByType(AdminAuditConfiguration.class); try { ConfigSupport.apply(new SingleConfigCode() { From 6f311a7bfd661cd4ccdd9952e1a41e4a8ff54018 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 18 Apr 2019 14:34:05 +0100 Subject: [PATCH 09/14] PAYARA-3111 admin console integration now works --- .../security/adminAudit/adminaudit.jsf | 4 +- nucleus/payara-modules/asadmin-audit/pom.xml | 5 -- .../GetAdminAuditServiceConfiguration.java | 72 ++++++++++++++++--- .../admin/SetAdminAuditConfiguration.java | 5 +- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf index 257ce499e5d..955b33d994c 100644 --- a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf +++ b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf @@ -55,7 +55,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. setPageSessionAttribute(key="ADMIN_AUDIT_URL", value="#{sessionScope.REST_URL}/configs/config/#{pageSession.configName}/admin-audit-configuration"); - gf.restRequest(endpoint="#{pageSession.ADMIN_AUDIT_URL}/get-admin-audit-configuration" method="GET" result="#{requestScope.resp}"); + gf.restRequest(endpoint="#{pageSession.ADMIN_AUDIT_URL}/get-admin-audit-configuration?target=#{pageSession.configName}" method="GET" result="#{requestScope.resp}"); setPageSessionAttribute(key="valueMap", value="#{requestScope.resp.data.extraProperties.adminauditConfiguration}"); setPageSessionAttribute(key="valueNotifierMap", value="#{requestScope.resp.data.extraProperties.notifierListLOG}"); @@ -93,7 +93,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. mapPut(map="#{pageSession.valueMap}" key="dynamic" value="#{pageSession.dynamic}"); mapRemove(map="#{pageSession.valueMap}" key="Audit Level"); prepareSuccessfulMsg(); - gf.updateEntity(endpoint="#{pageSession.ADMIN_AUDIT_URL}/set-admin-audit-configuration" + gf.updateEntity(endpoint="#{pageSession.ADMIN_AUDIT_URL}/set-admin-audit-configuration?target=#{pageSession.configName}" attrs="#{pageSession.valueMap}" convertToFalse="#{pageSession.convertToFalseList}"); py.updateNotifiers(endpoint="#{pageSession.ADMIN_AUDIT_URL}" dynamic="#{pageSession.dynamic}" target="#{pageSession.configName}" selected="#{pageSession.enabledNotifiersArr}" notifiers="#{pageSession.allNotifiersArray}"); diff --git a/nucleus/payara-modules/asadmin-audit/pom.xml b/nucleus/payara-modules/asadmin-audit/pom.xml index ee244aa7447..4469c8542c7 100644 --- a/nucleus/payara-modules/asadmin-audit/pom.xml +++ b/nucleus/payara-modules/asadmin-audit/pom.xml @@ -70,10 +70,5 @@ notification-core ${project.version}
- - fish.payara.payara-modules - notification-core - ${project.version} - diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java index 7b5bd4f2d8a..aa3deba6237 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java @@ -42,14 +42,22 @@ */ package fish.payara.audit.admin; +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.sun.enterprise.config.serverbeans.Config; import com.sun.enterprise.util.ColumnFormatter; +import com.sun.enterprise.util.SystemPropertyConstants; import fish.payara.audit.AdminAuditConfiguration; import fish.payara.nucleus.notification.configuration.Notifier; +import fish.payara.nucleus.notification.configuration.NotifierConfigurationType; +import fish.payara.nucleus.notification.service.BaseNotifierService; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; import javax.inject.Inject; import org.glassfish.api.ActionReport; +import org.glassfish.api.Param; import org.glassfish.api.admin.AdminCommand; import org.glassfish.api.admin.AdminCommandContext; import org.glassfish.api.admin.CommandLock; @@ -60,7 +68,12 @@ import org.glassfish.config.support.CommandTarget; import org.glassfish.config.support.TargetType; import org.glassfish.hk2.api.PerLookup; +import org.glassfish.hk2.api.ServiceHandle; +import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.internal.api.Target; import org.jvnet.hk2.annotations.Service; +import org.jvnet.hk2.config.ConfigSupport; +import org.jvnet.hk2.config.ConfigView; /** * Gets the current configuration of the admin audit service @@ -84,7 +97,14 @@ public class GetAdminAuditServiceConfiguration implements AdminCommand { private final static String[] NOTIFIER_HEADERS= {"Name", "Notifier Enabled"}; @Inject - private AdminAuditConfiguration config; + ServiceLocator habitat; + + @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) + private String target; + private Config targetConfig; + + @Inject + private Target targetUtil; @Override public void execute(AdminCommandContext context) { @@ -92,10 +112,13 @@ public void execute(AdminCommandContext context) { final ActionReport actionReport = context.getActionReport(); ColumnFormatter columnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS); - ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS); + ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS); - Object[] values = {config.getEnabled(), config.getAuditLevel()}; - columnFormatter.addRow(values); + targetConfig = targetUtil.getConfig(target); + AdminAuditConfiguration config = targetConfig.getExtensionByType(AdminAuditConfiguration.class); + + Object[] configValues = {config.getEnabled(), config.getAuditLevel()}; + columnFormatter.addRow(configValues); Map map = new HashMap<>(); Properties extraProperties = new Properties(); @@ -105,11 +128,39 @@ public void execute(AdminCommandContext context) { ActionReport notifiersReport = actionReport.addSubActionsReport(); + List> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class); + Properties notifierProps = new Properties(); - for (Notifier notifier: config.getNotifierList()) { - Object[] notifierValues = { notifier.toString(), notifier.getEnabled()}; - notifiersColumnFormatter.addRow(notifierValues); - notifierProps.put(notifier.toString(), notifier.getEnabled()); + if (!config.getNotifierList().isEmpty()) { + List> notifierClassList = Lists.transform(config.getNotifierList(), new Function>() { + @Override + public Class apply(Notifier input) { + return resolveNotifierClass(input); + } + }); + + for (ServiceHandle serviceHandle : allNotifierServiceHandles) { + Notifier notifier = config.getNotifierByType(serviceHandle.getService().getNotifierType()); + if (notifier != null) { + ConfigView view = ConfigSupport.getImpl(notifier); + NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class); + + if (notifierClassList.contains(view.getProxyType())) { + Object values[] = new Object[2]; + values[0] = annotation.type(); + values[1] = notifier.getEnabled(); + notifiersColumnFormatter.addRow(values); + + Map mapNotifiers = new HashMap<>(2); + mapNotifiers.put("notifierName", values[0]); + mapNotifiers.put("notifierEnabled", values[1]); + + notifierProps.put("notifierList" + annotation.type(), mapNotifiers); + } + } + + // extraProperties.putAll(notifierProps); + } } notifiersReport.setMessage(notifiersColumnFormatter.toString()); extraProperties.put("notifiers", notifierProps); @@ -121,4 +172,9 @@ public void execute(AdminCommandContext context) { actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS); } + private Class resolveNotifierClass(Notifier input) { + ConfigView view = ConfigSupport.getImpl(input); + return view.getProxyType(); + } + } diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java index f75ac4500aa..d4d948172f1 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java @@ -60,6 +60,7 @@ import org.glassfish.api.admin.RestEndpoint; import org.glassfish.api.admin.RestEndpoints; import org.glassfish.api.admin.RuntimeType; +import org.glassfish.api.admin.ServerEnvironment; import org.glassfish.config.support.CommandTarget; import org.glassfish.config.support.TargetType; import org.glassfish.hk2.api.PerLookup; @@ -107,7 +108,7 @@ public class SetAdminAuditConfiguration implements AdminCommand { @Inject private Target targetUtil; - + @Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); @@ -127,7 +128,7 @@ public Object run(AdminAuditConfiguration configurationProxy) throws PropertyVet } }, configuration); - if (dynamic) { + if (dynamic && target.equals(SystemPropertyConstants.DAS_SERVER_NAME)) { auditService.setEnabled(enabled); auditService.setAuditLevel(AuditLevel.valueOf(auditLevel)); } From 45f648b1a5d5fcd283a3e4a5b4143f70f7422826 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 18 Apr 2019 16:24:56 +0100 Subject: [PATCH 10/14] PAYARA-3111 added test for running command --- .../admin/rest/utils/RunCommandTest.java | 367 ++++++++++++++++++ .../fish/payara/audit/AdminAuditService.java | 3 +- 2 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java diff --git a/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java b/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java new file mode 100644 index 00000000000..96c9f590d63 --- /dev/null +++ b/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java @@ -0,0 +1,367 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package fish.payara.admin.rest.utils; + +import com.sun.enterprise.config.serverbeans.Server; +import com.sun.enterprise.module.bootstrap.StartupContext; +import com.sun.enterprise.v3.admin.CommandRunnerImpl; +import com.sun.enterprise.v3.common.DoNothingActionReporter; +import fish.payara.audit.AdminAuditConfiguration; +import fish.payara.audit.AdminAuditService; +import fish.payara.audit.admin.GetAdminAuditServiceConfiguration; +import fish.payara.nucleus.notification.NotificationService; +import fish.payara.nucleus.notification.configuration.Notifier; +import fish.payara.nucleus.notification.configuration.NotifierType; +import fish.payara.nucleus.notification.domain.EventSource; +import fish.payara.nucleus.notification.domain.NotificationEvent; +import fish.payara.nucleus.notification.domain.NotificationEventFactory; +import fish.payara.nucleus.notification.domain.NotifierExecutionOptionsFactory; +import fish.payara.nucleus.notification.domain.NotifierExecutionOptionsFactoryStore; +import fish.payara.nucleus.notification.log.LogNotificationEvent; +import fish.payara.nucleus.notification.log.LogNotificationEventFactory; +import fish.payara.nucleus.notification.service.NotificationEventFactoryStore; +import java.beans.PropertyVetoException; +import java.io.BufferedReader; +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.security.auth.Subject; +import org.glassfish.admin.rest.utils.ResourceUtil; +import org.glassfish.admin.rest.utils.xml.RestActionReporter; +import org.glassfish.api.ActionReport; +import org.glassfish.api.StartupRunLevel; +import org.glassfish.api.admin.AdminCommand; +import org.glassfish.api.admin.AdminCommandEventBroker; +import org.glassfish.api.admin.CommandModel; +import org.glassfish.api.admin.CommandParameters; +import org.glassfish.api.admin.CommandRunner; +import org.glassfish.api.admin.ParameterMap; +import org.glassfish.api.admin.Payload; +import org.glassfish.api.admin.ProgressStatus; +import org.glassfish.api.admin.RuntimeType; +import org.glassfish.api.admin.ServerEnvironment; +import org.glassfish.api.event.EventListener; + +import org.jvnet.hk2.config.ConfigBeanProxy; +import org.jvnet.hk2.config.TransactionFailure; +import org.glassfish.hk2.api.DynamicConfiguration; +import org.glassfish.hk2.api.DynamicConfigurationService; +import org.glassfish.hk2.api.ServiceLocator; +import org.glassfish.hk2.api.ServiceLocatorFactory; +import org.glassfish.hk2.runlevel.RunLevelContext; +import org.glassfish.hk2.runlevel.RunLevelController; +import org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext; +import org.glassfish.hk2.runlevel.internal.RunLevelControllerImpl; +import org.glassfish.hk2.utilities.ServiceLocatorUtilities; +import org.glassfish.internal.api.Globals; +import org.glassfish.internal.api.Target; +import org.junit.Before; +import org.junit.Test; +import org.jvnet.hk2.annotations.ContractsProvided; +import org.jvnet.hk2.annotations.Service; +import org.testng.Assert; +import sun.security.acl.PrincipalImpl; + +/** + * + * @author jonathan + */ +public class RunCommandTest { + + private ServiceLocator habitat; + + private List events; + + @Before + public void setUp() { + habitat = ServiceLocatorFactory.getInstance().create("testServiceLocator"); + ServiceLocatorUtilities.addOneConstant(habitat, new TestNotificationService()); + ServiceLocatorUtilities.addOneConstant(habitat, this); + ServiceLocatorUtilities.addClasses(habitat, AdminAuditService.class, GetAdminAuditServiceConfiguration.class, TestConfiguration.class, + Target.class, NotificationEventFactoryStore.class, NotifierExecutionOptionsFactoryStore.class, TestCommandRunner.class); + + Globals.setDefaultHabitat(habitat); + + DynamicConfigurationService dcs = habitat.getService(DynamicConfigurationService.class); + DynamicConfiguration config = dcs.createDynamicConfiguration(); + + config.addActiveDescriptor(RunLevelControllerImpl.class); + config.addActiveDescriptor(AsyncRunLevelContext.class); + config.addActiveDescriptor(RunLevelContext.class); + + config.commit(); + + habitat.getService(RunLevelController.class).proceedTo(StartupRunLevel.VAL); + habitat.getService(NotificationEventFactoryStore.class).register(NotifierType.LOG, new fish.payara.nucleus.notification.log.LogNotificationEventFactory() { + @Override + public LogNotificationEvent buildNotificationEvent(Level level, String subject, String message, Object[] parameters) { + LogNotificationEvent event = new LogNotificationEvent(); + Assert.assertEquals(Level.WARNING, level); + event.setLevel(level); + Assert.assertNull(parameters); + event.setParameters(parameters); + event.setMessage(message); + Assert.assertEquals("AUDIT", subject); + event.setSubject(subject); + return event; + } + }); + + + events = new LinkedList<>(); + } + + @Test + public void test() { + Subject testSubject = new Subject(); + testSubject.getPrincipals().add(new PrincipalImpl("testuser")); + RestActionReporter commandResult = ResourceUtil.runCommand("get-admin-audit-configuration", new ParameterMap(), testSubject); + Assert.assertTrue(commandResult.isSuccess()); + + + } + + @Service + @ContractsProvided(NotificationService.class) + class TestNotificationService extends NotificationService { + + @Override + public void notify(EventSource source, NotificationEvent notificationEvent) { + if (!source.equals(EventSource.AUDIT)) { + Assert.fail("Recieved non-audit message, was of type" + source.getValue()); + } + events.add(notificationEvent); + + } + + } + + @Service + @ContractsProvided(AdminAuditConfiguration.class) + class TestConfiguration implements AdminAuditConfiguration { + + @Inject + public TestConfiguration() { + + } + + + @Override + public String getEnabled() { + return Boolean.TRUE.toString(); + } + + @Override + public void enabled(String value) throws PropertyVetoException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public String getAuditLevel() { + return "INTERNAL"; + } + + @Override + public void setAuditLevel(String value) throws PropertyVetoException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public List getNotifierList() { + return new ArrayList<>(); + } + + @Override + public T getNotifierByType(Class type) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public ConfigBeanProxy getParent() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public T getParent(Class type) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public T createChild(Class type) throws TransactionFailure { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public ConfigBeanProxy deepCopy(ConfigBeanProxy parent) throws TransactionFailure { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + } + + @Service + @ContractsProvided(CommandRunner.class) + class TestCommandRunner implements CommandRunner { + + @Inject + public TestCommandRunner() { + + } + + @Override + public ActionReport getActionReport(String name) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public CommandModel getModel(String name, Logger logger) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public CommandModel getModel(String scope, String name, Logger logger) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public BufferedReader getHelp(CommandModel model) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean validateCommandModelETag(AdminCommand command, String eTag) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean validateCommandModelETag(CommandModel model, String eTag) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public AdminCommand getCommand(String commandName, ActionReport report, Logger logger) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public AdminCommand getCommand(String scope, String commandName, ActionReport report, Logger logger) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public CommandInvocation getCommandInvocation(String name, ActionReport report, Subject subject) { + return new CommandInvocation() { + @Override + public CommandInvocation parameters(CommandParameters params) { + return this; + } + + @Override + public CommandInvocation parameters(ParameterMap params) { + return this; + } + + @Override + public CommandInvocation inbound(Payload.Inbound inbound) { + return this; + } + + @Override + public CommandInvocation outbound(Payload.Outbound outbound) { + return this; + } + + @Override + public CommandInvocation listener(String nameRegexp, AdminCommandEventBroker.AdminCommandListener listener) { + return this; + } + + @Override + public CommandInvocation progressStatusChild(ProgressStatus ps) { + return this; + } + + @Override + public CommandInvocation managedJob() { + return this; + } + + @Override + public ActionReport report() { + return new DoNothingActionReporter(); + } + + @Override + public void execute() { + // do nothing + } + + @Override + public void execute(AdminCommand command) { + //do nothing + } + }; + } + + @Override + public CommandInvocation getCommandInvocation(String scope, String name, ActionReport report, Subject subject) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public CommandInvocation getCommandInvocation(String name, ActionReport report, Subject subject, boolean isNotify) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public CommandInvocation getCommandInvocation(String scope, String name, ActionReport report, Subject subject, boolean isNotify) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + } + +} diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java index 9e9cc3fdfd5..5f93851bfa8 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java @@ -53,6 +53,7 @@ import fish.payara.nucleus.notification.domain.NotifierExecutionOptionsFactoryStore; import fish.payara.nucleus.notification.log.LogNotifierExecutionOptions; import fish.payara.nucleus.notification.service.NotificationEventFactoryStore; +import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -166,7 +167,7 @@ public List getNotifierExecutionOptionsList() { public void recordAsadminCommand(String command, ParameterMap parameters, Subject subject) { if (enabled && notifierExecutionOptionsList != null && checkAuditLevel(command)) { - Set principals = subject.getPrincipals(PrincipalImpl.class); + Set principals = subject.getPrincipals(); String name = principals.iterator().next().getName(); for (NotifierExecutionOptions notifierExecutionOptions : notifierExecutionOptionsList) { From 6c01ff17d792d03b9b57ac934b85709698253cc6 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 18 Apr 2019 16:52:17 +0100 Subject: [PATCH 11/14] PAYARA-3111 cleanup --- .../src/main/resources/security/security.jsf | 15 +----- .../main/resources/security/securityAttrs.inc | 4 -- appserver/pom.xml | 2 +- .../admin/rest/utils/RunCommandTest.java | 42 ++++++++-------- .../org/glassfish/internal/api/Globals.java | 5 +- .../payara/audit/AdminAuditConfiguration.java | 4 +- .../fish/payara/audit/AdminAuditService.java | 1 - ...dminAuditServiceNotifierConfiguration.java | 2 +- .../java/fish/payara/audit/package-info.java | 49 +++++++++++++++++++ 9 files changed, 77 insertions(+), 47 deletions(-) create mode 100644 nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/package-info.java diff --git a/appserver/admingui/common/src/main/resources/security/security.jsf b/appserver/admingui/common/src/main/resources/security/security.jsf index 2e9027c3b0f..b6432574e53 100644 --- a/appserver/admingui/common/src/main/resources/security/security.jsf +++ b/appserver/admingui/common/src/main/resources/security/security.jsf @@ -39,7 +39,6 @@ holder. --> - @@ -88,14 +83,6 @@ removeEmptyProps(props="#{pageSession.tableList}" modifiedProps="#{pageSession.tableList}"); javaToJSON(obj="#{pageSession.tableList}" json="#{requestScope.tmpJSON}"); gf.restRequest(endpoint="#{pageSession.selfUrl}/property.json", method="POST", data="#{requestScope.tmpJSON}", result="#{requestScope.restResponse}"); - - gf.createEntity(endpoint="#{pageSession.adminAuditUrl}" - attrs="#{pageSession.adminAudit}" - skipAttrs="#{pageSession.skipAttrsList}" - convertToFalse="#{pageSession.convertToFalseList}" - ); - - prepareSuccessfulMsg(); gf.redirect(page="#{pageSession.selfPage}&alertType=${alertType}&alertSummary=${alertSummary}&alertDetail=${alertDetail}"); /> diff --git a/appserver/admingui/common/src/main/resources/security/securityAttrs.inc b/appserver/admingui/common/src/main/resources/security/securityAttrs.inc index 7c92b52934a..f506d5cc30a 100644 --- a/appserver/admingui/common/src/main/resources/security/securityAttrs.inc +++ b/appserver/admingui/common/src/main/resources/security/securityAttrs.inc @@ -39,7 +39,6 @@ holder. --> - @@ -55,9 +54,6 @@ /> - - - diff --git a/appserver/pom.xml b/appserver/pom.xml index 0c87b1b0e6e..8643c33d868 100644 --- a/appserver/pom.xml +++ b/appserver/pom.xml @@ -180,7 +180,7 @@ payara${major_version} 0.2 - 2.1.5-SNAPSHOT + 2.1.3 4.0.2.10.payara-p15 1.122-57.2889 diff --git a/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java b/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java index 96c9f590d63..35ac2739f40 100644 --- a/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java +++ b/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java @@ -42,10 +42,18 @@ */ package fish.payara.admin.rest.utils; -import com.sun.enterprise.config.serverbeans.Server; -import com.sun.enterprise.module.bootstrap.StartupContext; -import com.sun.enterprise.v3.admin.CommandRunnerImpl; +import java.io.BufferedReader; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.inject.Inject; + +import javax.security.auth.Subject; + import com.sun.enterprise.v3.common.DoNothingActionReporter; + import fish.payara.audit.AdminAuditConfiguration; import fish.payara.audit.AdminAuditService; import fish.payara.audit.admin.GetAdminAuditServiceConfiguration; @@ -54,23 +62,12 @@ import fish.payara.nucleus.notification.configuration.NotifierType; import fish.payara.nucleus.notification.domain.EventSource; import fish.payara.nucleus.notification.domain.NotificationEvent; -import fish.payara.nucleus.notification.domain.NotificationEventFactory; -import fish.payara.nucleus.notification.domain.NotifierExecutionOptionsFactory; import fish.payara.nucleus.notification.domain.NotifierExecutionOptionsFactoryStore; import fish.payara.nucleus.notification.log.LogNotificationEvent; -import fish.payara.nucleus.notification.log.LogNotificationEventFactory; import fish.payara.nucleus.notification.service.NotificationEventFactoryStore; import java.beans.PropertyVetoException; -import java.io.BufferedReader; -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.security.auth.Subject; + + import org.glassfish.admin.rest.utils.ResourceUtil; import org.glassfish.admin.rest.utils.xml.RestActionReporter; import org.glassfish.api.ActionReport; @@ -83,9 +80,6 @@ import org.glassfish.api.admin.ParameterMap; import org.glassfish.api.admin.Payload; import org.glassfish.api.admin.ProgressStatus; -import org.glassfish.api.admin.RuntimeType; -import org.glassfish.api.admin.ServerEnvironment; -import org.glassfish.api.event.EventListener; import org.jvnet.hk2.config.ConfigBeanProxy; import org.jvnet.hk2.config.TransactionFailure; @@ -100,16 +94,20 @@ import org.glassfish.hk2.utilities.ServiceLocatorUtilities; import org.glassfish.internal.api.Globals; import org.glassfish.internal.api.Target; + import org.junit.Before; import org.junit.Test; import org.jvnet.hk2.annotations.ContractsProvided; import org.jvnet.hk2.annotations.Service; import org.testng.Assert; + import sun.security.acl.PrincipalImpl; /** - * - * @author jonathan + * Test for running a command to check that is is processed properly. + * This tests the admin audit service. + * @see ResourceUtil#runCommand(java.lang.String, org.glassfish.api.admin.ParameterMap, javax.security.auth.Subject) + * @author jonathan coustick */ public class RunCommandTest { @@ -157,7 +155,7 @@ public LogNotificationEvent buildNotificationEvent(Level level, String subject, } @Test - public void test() { + public void testAdminAudit() { Subject testSubject = new Subject(); testSubject.getPrincipals().add(new PrincipalImpl("testuser")); RestActionReporter commandResult = ResourceUtil.runCommand("get-admin-audit-configuration", new ParameterMap(), testSubject); diff --git a/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java b/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java index 01d9834b098..1e85f672e6f 100644 --- a/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java +++ b/nucleus/common/internal-api/src/main/java/org/glassfish/internal/api/Globals.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. * - * Portions Copyright [2017-2019] Payara Foundation and/or affiliates + * Portions Copyright [2017] Payara Foundation and/or affiliates */ package org.glassfish.internal.api; @@ -45,12 +45,13 @@ import com.sun.enterprise.module.ModulesRegistry; import com.sun.enterprise.module.single.StaticModulesRegistry; import org.jvnet.hk2.annotations.Service; +import org.glassfish.common.util.Constants; +import org.glassfish.hk2.api.Rank; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.runlevel.RunLevel; import com.sun.enterprise.config.serverbeans.ConfigBeansUtilities; import javax.inject.Inject; import javax.inject.Singleton; -import org.jvnet.hk2.annotations.Optional; /** * Global class for storing the service locator for all hk2 services diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java index 65600a6d308..bf429dc466c 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditConfiguration.java @@ -56,8 +56,8 @@ import org.jvnet.hk2.config.Element; /** - * - * @author jonathan + * Configuration for the Admin Audit service + * @author jonathan coustick */ @Configured public interface AdminAuditConfiguration extends ConfigBeanProxy, ConfigExtension { diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java index 5f93851bfa8..f7a803f471d 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/AdminAuditService.java @@ -66,7 +66,6 @@ import org.glassfish.api.StartupRunLevel; import org.glassfish.api.admin.ParameterMap; import org.glassfish.hk2.runlevel.RunLevel; -import org.glassfish.security.common.PrincipalImpl; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.config.ConfigSupport; import org.jvnet.hk2.config.ConfigView; diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java index 1de4fb8c4e9..4654bf54ed3 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java @@ -92,7 +92,7 @@ * setting. * * @author jonathan coustick - * @since 5.191 + * @since 5.192 */ @Service(name = "set-admin-audit-service-notifier-configuration") @PerLookup diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/package-info.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/package-info.java new file mode 100644 index 00000000000..169c3d4b0cc --- /dev/null +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/package-info.java @@ -0,0 +1,49 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +/** + * Audit system for the admin console and rest management interface + * @since 5.192 + * @author Jonathan Coustick + */ +package fish.payara.audit; From 434e05c2f398f64934c0782ac26d8b6679abc2cf Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Tue, 23 Apr 2019 10:39:43 +0100 Subject: [PATCH 12/14] PAYARA-3111 requested changes --- .../extras/rest/PayaraRestApiHandlers.java | 18 +++++++------- .../admin/rest/utils/ResourceUtil.java | 3 +-- .../admin/rest/utils/RunCommandTest.java | 18 +++++++------- .../GetAdminAuditServiceConfiguration.java | 4 ++-- ...dminAuditServiceNotifierConfiguration.java | 24 +++++++++---------- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java b/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java index fc115460f9e..b1b1bf9d71b 100644 --- a/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java +++ b/appserver/admingui/payara-console-extras/src/main/java/fish/payara/admingui/extras/rest/PayaraRestApiHandlers.java @@ -579,7 +579,7 @@ public static void updateNotifiers(HandlerContext handlerCtx) { for (String notifier : notifiers){ String name = notifier.split("-")[1]; String restEndpoint; - HashMap attrs = new HashMap<>(); + Map attributes = new HashMap<>(); if (endpoint.contains("request-tracing-service-configuration")){ restEndpoint = endpoint + "/requesttracing-" + name + "-notifier-configure"; forRequestTracing = true; @@ -591,7 +591,7 @@ public static void updateNotifiers(HandlerContext handlerCtx) { forMonitoring = true; } else if (endpoint.contains("admin-audit-configuration")) { restEndpoint = endpoint + "/set-admin-audit-service-notifier-configuration"; - attrs.put("notifier", name); + attributes.put("notifier", name); forAdminAudit = true; } else { //Unknown service being configured @@ -600,18 +600,18 @@ public static void updateNotifiers(HandlerContext handlerCtx) { if (enabledNotifiers.contains(notifier)){ - attrs.put("enabled", "true"); + attributes.put("enabled", "true"); } else { - attrs.put("enabled", "false"); + attributes.put("enabled", "false"); } if (!forAdminAudit) { //PAYARA-1616 go silent, bootstrap will take place after iteration. - attrs.put("dynamic", "false"); + attributes.put("dynamic", "false"); } else { - attrs.put("dynamic", "true"); + attributes.put("dynamic", "true"); } - attrs.put("target", target); - RestUtil.restRequest(restEndpoint, attrs, "post", handlerCtx, quiet, throwException); + attributes.put("target", target); + RestUtil.restRequest(restEndpoint, attributes, "post", handlerCtx, quiet, throwException); } // PAYARA-1616 // manually bootstrap healthCheck and requestTracing services for once so that it doesn't get bootstrapped each time for enabled notifier. @@ -824,4 +824,4 @@ public static void createDeploymentGroupInstances(HandlerContext handlerCtx) { } } -} \ No newline at end of file +} diff --git a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java index c23e33a9ad3..561f4e8f7cd 100644 --- a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java +++ b/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/ResourceUtil.java @@ -249,8 +249,7 @@ public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob) { - AsadminRecorderService asadminRecorderService = Globals. - getDefaultHabitat().getService(AsadminRecorderService.class); + AsadminRecorderService asadminRecorderService = Globals.get(AsadminRecorderService.class); if (asadminRecorderService != null && asadminRecorderService.isEnabled()) { asadminRecorderService.recordAsadminCommand(commandName, parameters); diff --git a/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java b/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java index 35ac2739f40..94fca945683 100644 --- a/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java +++ b/nucleus/admin/rest/rest-service/src/test/java/fish/payara/admin/rest/utils/RunCommandTest.java @@ -111,21 +111,21 @@ */ public class RunCommandTest { - private ServiceLocator habitat; + private ServiceLocator serviceLocator; private List events; @Before public void setUp() { - habitat = ServiceLocatorFactory.getInstance().create("testServiceLocator"); - ServiceLocatorUtilities.addOneConstant(habitat, new TestNotificationService()); - ServiceLocatorUtilities.addOneConstant(habitat, this); - ServiceLocatorUtilities.addClasses(habitat, AdminAuditService.class, GetAdminAuditServiceConfiguration.class, TestConfiguration.class, + serviceLocator = ServiceLocatorFactory.getInstance().create("testServiceLocator"); + ServiceLocatorUtilities.addOneConstant(serviceLocator, new TestNotificationService()); + ServiceLocatorUtilities.addOneConstant(serviceLocator, this); + ServiceLocatorUtilities.addClasses(serviceLocator, AdminAuditService.class, GetAdminAuditServiceConfiguration.class, TestConfiguration.class, Target.class, NotificationEventFactoryStore.class, NotifierExecutionOptionsFactoryStore.class, TestCommandRunner.class); - Globals.setDefaultHabitat(habitat); + Globals.setDefaultHabitat(serviceLocator); - DynamicConfigurationService dcs = habitat.getService(DynamicConfigurationService.class); + DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); config.addActiveDescriptor(RunLevelControllerImpl.class); @@ -134,8 +134,8 @@ public void setUp() { config.commit(); - habitat.getService(RunLevelController.class).proceedTo(StartupRunLevel.VAL); - habitat.getService(NotificationEventFactoryStore.class).register(NotifierType.LOG, new fish.payara.nucleus.notification.log.LogNotificationEventFactory() { + serviceLocator.getService(RunLevelController.class).proceedTo(StartupRunLevel.VAL); + serviceLocator.getService(NotificationEventFactoryStore.class).register(NotifierType.LOG, new fish.payara.nucleus.notification.log.LogNotificationEventFactory() { @Override public LogNotificationEvent buildNotificationEvent(Level level, String subject, String message, Object[] parameters) { LogNotificationEvent event = new LogNotificationEvent(); diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java index aa3deba6237..08610fdfbe4 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java @@ -97,7 +97,7 @@ public class GetAdminAuditServiceConfiguration implements AdminCommand { private final static String[] NOTIFIER_HEADERS= {"Name", "Notifier Enabled"}; @Inject - ServiceLocator habitat; + ServiceLocator serviceLocator; @Param(name = "target", optional = true, defaultValue = SystemPropertyConstants.DAS_SERVER_NAME) private String target; @@ -128,7 +128,7 @@ public void execute(AdminCommandContext context) { ActionReport notifiersReport = actionReport.addSubActionsReport(); - List> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class); + List> allNotifierServiceHandles = serviceLocator.getAllServiceHandles(BaseNotifierService.class); Properties notifierProps = new Properties(); if (!config.getNotifierList().isEmpty()) { diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java index 4654bf54ed3..2d6be5f0f62 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java @@ -106,18 +106,6 @@ }) public class SetAdminAuditServiceNotifierConfiguration implements AdminCommand { - @Inject - private Target targetUtil; - - @Inject - private ServerEnvironment server; - - @Inject - private ConfigModularityUtils configModularityUtils; - - @Inject - private AdminAuditService auditService; - @Param(name = "dynamic", optional = true, defaultValue = "false") private Boolean dynamic; @@ -135,6 +123,18 @@ public class SetAdminAuditServiceNotifierConfiguration implements AdminCommand { private String notifierName; private NotifierType notifierType; + @Inject + private Target targetUtil; + + @Inject + private ServerEnvironment server; + + @Inject + private ConfigModularityUtils configModularityUtils; + + @Inject + private AdminAuditService auditService; + private ActionReport report; private static final Logger LOGGER = Logger.getLogger(SetAdminAuditServiceNotifierConfiguration.class.getPackage().toString()); From 48987f916a18f3c119f5ff534bbd376d2ae7ee08 Mon Sep 17 00:00:00 2001 From: merorai Date: Thu, 25 Apr 2019 09:55:25 +0100 Subject: [PATCH 13/14] * Moved the Save button to the right to keep it consistent with rest of the design. * Added Configuration Name to the page --- .../security/adminAudit/adminaudit.jsf | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf index 955b33d994c..9a4412c9a0b 100644 --- a/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf +++ b/appserver/admingui/common/src/main/resources/security/adminAudit/adminaudit.jsf @@ -81,30 +81,35 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. /> - + #include "/common/shared/alertMsg.inc" - - + + + - - + + + + - #include "/common/shared/configNameSection.inc" +#include "/common/shared/configNameSection.inc" @@ -142,7 +147,7 @@ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - + + From 2f2dbf9a89a43ab58135829c35de508095215520 Mon Sep 17 00:00:00 2001 From: Jonathan Coustick Date: Thu, 25 Apr 2019 16:54:56 +0100 Subject: [PATCH 14/14] PAYARA-3111 removed duplicate code and added deployment group support --- .../glassfish/common/admingui/Strings.properties | 16 ---------------- .../admin/GetAdminAuditServiceConfiguration.java | 4 ++-- .../audit/admin/SetAdminAuditConfiguration.java | 6 +++--- ...etAdminAuditServiceNotifierConfiguration.java | 3 ++- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties index 400b52e1926..be77a914674 100644 --- a/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties +++ b/appserver/admingui/common/src/main/resources/org/glassfish/common/admingui/Strings.properties @@ -105,22 +105,6 @@ security.secureAdmin.instancealias=Instance Alias: security.secureAdmin.instancealiasHelp=The alias that refers to the SSL/TLS certificate on the instances. This alias is used by the DAS to authenticate against the instances. security.secureLabel=Secure Administration: -## Admin Audit -adminAudit.PageTitle=Admin Audit -adminaudit.PageHelp=Options for the admin commands audit system -adminaudit.Title=Admin Audit -adminaudit.Enabled=Enabled -adminaudit.EnabledHelp=Enable the admin audit service -adminaudit.Dynamic=Dynamic -adminaudit.DynamicHelp=Make the changes take effect immediately -adminaudit.configuration.availableNotifiers=Available Notifiers -adminaudit.configuration.selectedNotifiers=Selected Notifiers -adminaudit.link.to.notification.page.text.prefix=Selected Notifiers need to be enabled also in the -adminaudit.link.to.notification.page.text=Notification Service -adminaudit.link.to.notification.page.text.suffix=to receive notifications. -adminaudit.link.to.notification.page.text.prefix= - - ## Realms realm.NewPageTitle=New Realm realm.NewPageHelp=Create a new security (authentication) realm. Valid realm types are PAM, OSGi, File, Certificate, LDAP, JDBC, Digest, Oracle Solaris, and Custom. diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java index 08610fdfbe4..37ff066d548 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/GetAdminAuditServiceConfiguration.java @@ -84,7 +84,8 @@ @PerLookup @CommandLock(CommandLock.LockType.NONE) @ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG, + CommandTarget.DEPLOYMENT_GROUP}) @RestEndpoints({ @RestEndpoint(configBean = AdminAuditConfiguration.class, opType = RestEndpoint.OpType.GET, @@ -159,7 +160,6 @@ public Class apply(Notifier input) { } } - // extraProperties.putAll(notifierProps); } } notifiersReport.setMessage(notifiersColumnFormatter.toString()); diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java index d4d948172f1..de1c97fc27c 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditConfiguration.java @@ -60,7 +60,6 @@ import org.glassfish.api.admin.RestEndpoint; import org.glassfish.api.admin.RestEndpoints; import org.glassfish.api.admin.RuntimeType; -import org.glassfish.api.admin.ServerEnvironment; import org.glassfish.config.support.CommandTarget; import org.glassfish.config.support.TargetType; import org.glassfish.hk2.api.PerLookup; @@ -79,7 +78,8 @@ @Service(name = "set-admin-audit-configuration") @PerLookup @ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG, + CommandTarget.DEPLOYMENT_GROUP}) @RestEndpoints({ @RestEndpoint(configBean = AdminAuditConfiguration.class, opType = RestEndpoint.OpType.POST, @@ -128,7 +128,7 @@ public Object run(AdminAuditConfiguration configurationProxy) throws PropertyVet } }, configuration); - if (dynamic && target.equals(SystemPropertyConstants.DAS_SERVER_NAME)) { + if (dynamic && target.equals("server-config")) { auditService.setEnabled(enabled); auditService.setAuditLevel(AuditLevel.valueOf(auditLevel)); } diff --git a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java index 2d6be5f0f62..9cde0e4653a 100644 --- a/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java +++ b/nucleus/payara-modules/asadmin-audit/src/main/java/fish/payara/audit/admin/SetAdminAuditServiceNotifierConfiguration.java @@ -97,7 +97,8 @@ @Service(name = "set-admin-audit-service-notifier-configuration") @PerLookup @ExecuteOn({RuntimeType.DAS, RuntimeType.INSTANCE}) -@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) +@TargetType(value ={CommandTarget.DEPLOYMENT_GROUP, CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, + CommandTarget.CLUSTERED_INSTANCE, CommandTarget.CONFIG}) @RestEndpoints({ @RestEndpoint(configBean = AdminAuditConfiguration.class, opType = RestEndpoint.OpType.POST,