Search in sources :

Example 1 with RestMonitoringConfiguration

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());
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) RestMonitoringConfiguration(fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration)

Example 2 with RestMonitoringConfiguration

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);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) RestMonitoringConfiguration(fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 3 with RestMonitoringConfiguration

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);
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) RestMonitoringConfiguration(fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration) RestMonitoringEndpointDecider(fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider)

Example 4 with RestMonitoringConfiguration

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();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) RestMonitoringConfiguration(fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration) ActionReport(org.glassfish.api.ActionReport) Subject(javax.security.auth.Subject)

Aggregations

RestMonitoringConfiguration (fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration)4 Config (com.sun.enterprise.config.serverbeans.Config)3 ActionReport (org.glassfish.api.ActionReport)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 RestMonitoringEndpointDecider (fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Subject (javax.security.auth.Subject)1 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)1 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)1