use of fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration in project Payara by payara.
the class RestMonitoringAuthModule method initialize.
@Override
public void initialize(MessagePolicy requestPolicy, MessagePolicy responsePolicy, CallbackHandler handler, Map options) throws AuthException {
this.handler = handler;
ServiceLocator habitat = SecurityServicesUtil.getInstance().getHabitat();
RestMonitoringConfiguration restMonitoringConfiguration = habitat.getService(RestMonitoringConfiguration.class);
contextRoot = restMonitoringConfiguration.getContextRoot();
securityEnabled = Boolean.parseBoolean(restMonitoringConfiguration.getSecurityEnabled());
}
use of fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration in project Payara by payara.
the class GetRestMonitoringConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
ActionReport restMonitoringReport = actionReport.addSubActionsReport();
Config config = targetUtil.getConfig(target);
if (config == null) {
actionReport.setMessage("No such config name: " + targetUtil);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
RestMonitoringConfiguration restMonitoringConfiguration = config.getExtensionByType(RestMonitoringConfiguration.class);
ColumnFormatter columnFormatter = new ColumnFormatter(OUTPUT_HEADERS);
Object[] outputValues = { restMonitoringConfiguration.getEnabled(), restMonitoringConfiguration.getApplicationName(), restMonitoringConfiguration.getContextRoot(), restMonitoringConfiguration.getSecurityEnabled() };
columnFormatter.addRow(outputValues);
Map<String, Object> extraPropertiesMap = new HashMap<>();
extraPropertiesMap.put("enabled", restMonitoringConfiguration.getEnabled());
extraPropertiesMap.put("applicationname", restMonitoringConfiguration.getApplicationName());
extraPropertiesMap.put("contextroot", restMonitoringConfiguration.getContextRoot());
extraPropertiesMap.put("securityenabled", restMonitoringConfiguration.getSecurityEnabled());
Properties extraProperties = new Properties();
extraProperties.put("restMonitoringConfiguration", extraPropertiesMap);
actionReport.setExtraProperties(extraProperties);
restMonitoringReport.setMessage(columnFormatter.toString());
restMonitoringReport.appendMessage(StringUtils.EOL);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration in project Payara by payara.
the class RestMonitoringService method changed.
@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
List<UnprocessedChangeEvent> unprocessedChanges = new ArrayList<>();
boolean dynamicStart = false;
for (PropertyChangeEvent propertyChangeEvent : propertyChangeEvents) {
// Check that the property change event is for us.
if (propertyChangeEvent.getSource().toString().equals("GlassFishConfigBean." + RestMonitoringConfiguration.class.getName()) && isCurrentInstanceMatchTarget(propertyChangeEvent)) {
// Check if the property has actually changed
if (!propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
// If the application hasn't attempted to start yet
if (!startAttempted) {
// property, we don't need to compare it to the current value - it can only be true
if (propertyChangeEvent.getPropertyName().equals("enabled")) {
// Flag that we want to dynamically start Rest Monitoring
dynamicStart = true;
} else if (propertyChangeEvent.getPropertyName().equals("context-root")) {
// If we haven't attempted to start the app yet, grab the new context root
Config serverConfig = domain.getServerNamed(serverEnv.getInstanceName()).getConfig();
RestMonitoringEndpointDecider endpointDecider = new RestMonitoringEndpointDecider(serverConfig, restMonitoringConfiguration);
contextRoot = endpointDecider.getContextRoot();
}
} else if (!propertyChangeEvent.getPropertyName().equals("security-enabled")) {
// If a startup has been attempted and the changed property isn't securityEnabled, throw an
// unprocessed change event as we need to restart
unprocessedChanges.add(new UnprocessedChangeEvent(propertyChangeEvent, "Rest monitoring redeployment required"));
}
}
}
}
// This should only be true if rest monitoring was not enabled at startup, and we've just enabled the service
if (dynamicStart) {
loadApplication(true);
}
// If we need to restart, throw an unprocessed change event
if (unprocessedChanges.isEmpty()) {
return null;
} else {
return new UnprocessedChangeEvents(unprocessedChanges);
}
}
use of fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration in project Payara by payara.
the class SetRestMonitoringConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext context) {
Config targetConfig = targetUtil.getConfig(target);
RestMonitoringConfiguration restMonitoringConfiguration = targetConfig.getExtensionByType(RestMonitoringConfiguration.class);
ActionReport actionReport = context.getActionReport();
Subject subject = context.getSubject();
// If the required message security provider is not present, create it
if (!messageSecurityProviderExists(actionReport.addSubActionsReport(), context.getSubject())) {
createRequiredMessageSecurityProvider(actionReport.addSubActionsReport(), subject);
}
// Create the default user if it doesn't exist
if (!defaultRestMonitoringUserExists(actionReport.addSubActionsReport(), subject)) {
createDefaultRestMonitoringUser(actionReport.addSubActionsReport(), subject);
}
try {
ConfigSupport.apply(new SingleConfigCode<RestMonitoringConfiguration>() {
@Override
public Object run(RestMonitoringConfiguration configProxy) throws PropertyVetoException {
if (enabled != null) {
configProxy.setEnabled(enabled.toString());
}
if (contextRoot != null) {
configProxy.setContextRoot(contextRoot);
}
if (applicationName != null) {
configProxy.setApplicationName(applicationName);
}
if (securityEnabled != null) {
configProxy.setSecurityEnabled(securityEnabled.toString());
}
return null;
}
}, restMonitoringConfiguration);
} catch (TransactionFailure ex) {
context.getActionReport().failure(LOGGER, "Failed to update Rest Monitoring configuration", ex);
}
// If security is enabled but secure admin isn't, prompt a warning
if (Boolean.parseBoolean(restMonitoringConfiguration.getSecurityEnabled()) && !SecureAdmin.Util.isEnabled(domain.getSecureAdmin())) {
actionReport.appendMessage("\n---WARNING---\nSecure Admin is not enabled! - it is highly " + "recommended that you do so to properly secure the Rest Monitoring service.\n");
}
// If everything has passed, scrap the subaction reports as we don't want to print them out
if (!actionReport.hasFailures() || !actionReport.hasWarnings()) {
actionReport.getSubActionsReport().clear();
}
}
Aggregations