Search in sources :

Example 31 with Protocol

use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.

the class DeleteProtocolFinder method execute.

@Override
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    report = context.getActionReport();
    try {
        final Protocols protocols = config.getNetworkConfig().getProtocols();
        final Protocol protocol = protocols.findProtocol(protocolName);
        validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
        PortUnification pu = getPortUnification(protocol);
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) {
                final Protocol prot = (Protocol) params[0];
                final PortUnification portUnification = (PortUnification) params[1];
                final List<ProtocolFinder> oldList = portUnification.getProtocolFinder();
                List<ProtocolFinder> newList = new ArrayList<ProtocolFinder>();
                for (final ProtocolFinder finder : oldList) {
                    if (!name.equals(finder.getName())) {
                        newList.add(finder);
                    }
                }
                if (oldList.size() == newList.size()) {
                    throw new RuntimeException(String.format("No finder named %s found for protocol %s", name, protocolName));
                }
                if (newList.isEmpty()) {
                    prot.setPortUnification(null);
                } else {
                    portUnification.setProtocolFinder(newList);
                }
                return null;
            }
        }, protocol, pu);
        cleanPortUnification(pu);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) Config(com.sun.enterprise.config.serverbeans.Config) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ConfigCode(org.jvnet.hk2.config.ConfigCode) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 32 with Protocol

use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.

the class GetProtocol method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // Check that a configuration can be found
    if (targetUtil.getConfig(target) == null) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
        return;
    }
    Config config = targetUtil.getConfig(target);
    // Check that a matching listener can be found
    List<Protocol> protocols = config.getNetworkConfig().getProtocols().getProtocol();
    Optional<Protocol> optionalProtocol = protocols.stream().filter(protocol -> protocol.getName().equals(protocolName)).findFirst();
    if (!optionalProtocol.isPresent()) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_PROTOCOL), protocolName, target));
        return;
    }
    Protocol protocol = optionalProtocol.get();
    // Write message body
    report.appendMessage(String.format("Name: %s\n", protocol.getName()));
    // Write HTTP config options
    report.appendMessage("\nHTTP:\n");
    report.appendMessage(String.format("Server Name: %s\n", protocol.getHttp().getServerName()));
    report.appendMessage(String.format("Max Connections: %s seconds\n", protocol.getHttp().getMaxConnections()));
    report.appendMessage(String.format("Default Virtual Server: %s\n", protocol.getHttp().getDefaultVirtualServer()));
    report.appendMessage(String.format("Server Header: %s\n", protocol.getHttp().getServerHeader()));
    report.appendMessage(String.format("X-Powered-By: %s\n", protocol.getHttp().getXpoweredBy()));
    if (verbose) {
        report.appendMessage(String.format("Request Timeout: %s seconds\n", protocol.getHttp().getRequestTimeoutSeconds()));
        report.appendMessage(String.format("Timeout: %s seconds\n", protocol.getHttp().getTimeoutSeconds()));
        report.appendMessage(String.format("DNS Lookup Enabled: %s\n", protocol.getHttp().getDnsLookupEnabled()));
        report.appendMessage(String.format("X Frame Options: %s\n", protocol.getHttp().getXframeOptions()));
    }
    // Write HTTP/2 config options
    report.appendMessage("\nHTTP/2:\n");
    report.appendMessage(String.format("Enabled: %s\n", protocol.getHttp().getHttp2Enabled()));
    if (Boolean.parseBoolean(protocol.getHttp().getHttp2Enabled())) {
        report.appendMessage(String.format("Push Enabled: %s\n", protocol.getHttp().getHttp2PushEnabled()));
        report.appendMessage(String.format("Cipher Check: %s\n", !Boolean.parseBoolean(protocol.getHttp().getHttp2DisableCipherCheck())));
        if (verbose) {
            report.appendMessage(String.format("Max Concurrent Streams: %s\n", protocol.getHttp().getHttp2MaxConcurrentStreams()));
            report.appendMessage(String.format("Initial Window Size: %s bytes\n", protocol.getHttp().getHttp2InitialWindowSizeInBytes()));
            report.appendMessage(String.format("Max Frame Payload Size: %s bytes\n", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes()));
            report.appendMessage(String.format("Max Header List Size: %s bytes\n", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes()));
            report.appendMessage(String.format("Streams High Water Mark: %s\n", protocol.getHttp().getHttp2StreamsHighWaterMark()));
            report.appendMessage(String.format("Clean Percentage: %s\n", protocol.getHttp().getHttp2CleanPercentage()));
            report.appendMessage(String.format("Clean Frequency Check: %s\n", protocol.getHttp().getHttp2CleanFrequencyCheck()));
        }
    }
    // Write the variables as properties
    Properties properties = new Properties();
    properties.put("name", protocol.getName());
    properties.put("serverName", protocol.getHttp().getServerName() == null ? "null" : protocol.getHttp().getServerName());
    properties.put("maxConnections", protocol.getHttp().getMaxConnections());
    properties.put("defaultVirtualServer", protocol.getHttp().getDefaultVirtualServer());
    properties.put("serverHeader", protocol.getHttp().getServerHeader());
    properties.put("xPoweredBy", protocol.getHttp().getXpoweredBy());
    properties.put("requestTimeoutSeconds", protocol.getHttp().getRequestTimeoutSeconds());
    properties.put("timeoutSeconds", protocol.getHttp().getTimeoutSeconds());
    properties.put("dnsLookupEnabled", protocol.getHttp().getDnsLookupEnabled());
    properties.put("xFrameOptions", protocol.getHttp().getXframeOptions());
    properties.put("http2Enabled", protocol.getHttp().getHttp2Enabled());
    properties.put("http2MaxConcurrentStreams", protocol.getHttp().getHttp2MaxConcurrentStreams());
    properties.put("http2InitialWindowSizeInBytes", protocol.getHttp().getHttp2InitialWindowSizeInBytes());
    properties.put("http2MaxFramePayloadSizeInBytes", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes());
    properties.put("http2MaxHeaderListSizeInBytes", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes());
    properties.put("http2StreamsHighWaterMark", protocol.getHttp().getHttp2StreamsHighWaterMark());
    properties.put("http2CleanPercentage", protocol.getHttp().getHttp2CleanPercentage());
    properties.put("http2CleanFrequencyCheck", protocol.getHttp().getHttp2CleanFrequencyCheck());
    properties.put("http2DisableCipherCheck", protocol.getHttp().getHttp2DisableCipherCheck());
    properties.put("http2PushEnabled", protocol.getHttp().getHttp2PushEnabled());
    report.setExtraProperties(properties);
}
Also used : Param(org.glassfish.api.Param) LogFacade(org.glassfish.web.admin.LogFacade) RestEndpoint(org.glassfish.api.admin.RestEndpoint) CommandLock(org.glassfish.api.admin.CommandLock) MessageFormat(java.text.MessageFormat) I18n(org.glassfish.api.I18n) PerLookup(org.glassfish.hk2.api.PerLookup) Inject(javax.inject.Inject) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) ExecuteOn(org.glassfish.api.admin.ExecuteOn) RuntimeType(org.glassfish.api.admin.RuntimeType) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) TargetType(org.glassfish.config.support.TargetType) Logger(java.util.logging.Logger) List(java.util.List) Target(org.glassfish.internal.api.Target) Service(org.jvnet.hk2.annotations.Service) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) CommandTarget(org.glassfish.config.support.CommandTarget) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Optional(java.util.Optional) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) Config(com.sun.enterprise.config.serverbeans.Config) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) Properties(java.util.Properties)

Example 33 with Protocol

use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.

the class ListProtocols method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    List<Protocol> list = config.getNetworkConfig().getProtocols().getProtocol();
    for (Protocol protocol : list) {
        report.getTopMessagePart().addChild().setMessage(protocol.getName());
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 34 with Protocol

use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.

the class GenericGrizzlyListener method configureSubProtocol.

protected void configureSubProtocol(final ServiceLocator habitat, final NetworkListener networkListener, final Protocol protocol, final FilterChainBuilder filterChainBuilder) {
    if (protocol.getHttp() != null) {
        final Http http = protocol.getHttp();
        configureHttpProtocol(habitat, networkListener, http, filterChainBuilder, Boolean.valueOf(protocol.getSecurityEnabled()));
    } else if (protocol.getPortUnification() != null) {
        // Port unification
        final PortUnification pu = protocol.getPortUnification();
        final String puFilterClassname = pu.getClassname();
        PUFilter puFilter = null;
        if (puFilterClassname != null) {
            try {
                puFilter = Utils.newInstance(habitat, PUFilter.class, puFilterClassname, puFilterClassname);
                configureElement(habitat, networkListener, pu, puFilter);
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Can not initialize port unification filter: " + puFilterClassname + " default filter will be used instead", e);
            }
        }
        if (puFilter == null) {
            puFilter = new PUFilter();
        }
        List<org.glassfish.grizzly.config.dom.ProtocolFinder> findersConfig = pu.getProtocolFinder();
        for (org.glassfish.grizzly.config.dom.ProtocolFinder finderConfig : findersConfig) {
            final String finderClassname = finderConfig.getClassname();
            try {
                final ProtocolFinder protocolFinder = Utils.newInstance(habitat, ProtocolFinder.class, finderClassname, finderClassname);
                configureElement(habitat, networkListener, finderConfig, protocolFinder);
                final Protocol subProtocol = finderConfig.findProtocol();
                if (subProtocol.getHttp() != null) {
                    if (LOGGER.isLoggable(WARNING)) {
                        LOGGER.log(WARNING, "HTTP/2 (enabled by default) is unsupported with port " + "unification and will be disabled for network listener {0}.", networkListener.getName());
                    }
                    skipHttp2 = true;
                }
                final FilterChainBuilder subProtocolFilterChainBuilder = puFilter.getPUFilterChainBuilder();
                // If subprotocol is secured - we need to wrap it under SSLProtocolFinder
                if (Boolean.valueOf(subProtocol.getSecurityEnabled())) {
                    final PUFilter extraSslPUFilter = new PUFilter();
                    final Filter addedSSLFilter = configureSsl(habitat, getSsl(subProtocol), subProtocolFilterChainBuilder);
                    subProtocolFilterChainBuilder.add(extraSslPUFilter);
                    final FilterChainBuilder extraSslPUFilterChainBuilder = extraSslPUFilter.getPUFilterChainBuilder();
                    try {
                        // temporary add SSL Filter, so subprotocol
                        // will see it
                        extraSslPUFilterChainBuilder.add(addedSSLFilter);
                        configureSubProtocol(habitat, networkListener, subProtocol, extraSslPUFilterChainBuilder);
                    } finally {
                        // remove SSL Filter
                        extraSslPUFilterChainBuilder.remove(addedSSLFilter);
                    }
                    extraSslPUFilter.register(protocolFinder, extraSslPUFilterChainBuilder.build());
                    puFilter.register(new SSLProtocolFinder(new SSLConfigurator(habitat, subProtocol.getSsl())), subProtocolFilterChainBuilder.build());
                } else {
                    configureSubProtocol(habitat, networkListener, subProtocol, subProtocolFilterChainBuilder);
                    puFilter.register(protocolFinder, subProtocolFilterChainBuilder.build());
                }
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Can not initialize sub protocol. Finder: " + finderClassname, e);
            }
        }
        filterChainBuilder.add(puFilter);
    } else if (protocol.getHttpRedirect() != null) {
        filterChainBuilder.add(createHttpServerCodecFilter());
        final HttpRedirectFilter filter = new HttpRedirectFilter();
        filter.configure(habitat, networkListener, protocol.getHttpRedirect());
        filterChainBuilder.add(filter);
    } else {
        ProtocolChainInstanceHandler pcihConfig = protocol.getProtocolChainInstanceHandler();
        if (pcihConfig == null) {
            LOGGER.log(Level.WARNING, "Empty protocol declaration");
            return;
        }
        ProtocolChain filterChainConfig = pcihConfig.getProtocolChain();
        for (ProtocolFilter filterConfig : filterChainConfig.getProtocolFilter()) {
            final String filterClassname = filterConfig.getClassname();
            try {
                final Filter filter = loadFilter(habitat, filterConfig.getName(), filterClassname);
                configureElement(habitat, networkListener, filterConfig, filter);
                filterChainBuilder.add(filter);
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Can not initialize protocol filter: " + filterClassname, e);
                throw new IllegalStateException("Can not initialize protocol filter: " + filterClassname);
            }
        }
    }
}
Also used : PUFilter(org.glassfish.grizzly.portunif.PUFilter) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) Http(org.glassfish.grizzly.config.dom.Http) IOException(java.io.IOException) SSLProtocolFinder(org.glassfish.grizzly.portunif.finders.SSLProtocolFinder) ProtocolFinder(org.glassfish.grizzly.portunif.ProtocolFinder) HttpRedirectFilter(org.glassfish.grizzly.config.portunif.HttpRedirectFilter) PUFilter(org.glassfish.grizzly.portunif.PUFilter) Filter(org.glassfish.grizzly.filterchain.Filter) SNIFilter(org.glassfish.grizzly.sni.SNIFilter) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter) IdleTimeoutFilter(org.glassfish.grizzly.utils.IdleTimeoutFilter) HttpServerFilter(org.glassfish.grizzly.http.server.HttpServerFilter) CompressionEncodingFilter(org.glassfish.grizzly.http.server.CompressionEncodingFilter) HttpRedirectFilter(org.glassfish.grizzly.config.portunif.HttpRedirectFilter) FileCacheFilter(org.glassfish.grizzly.http.server.FileCacheFilter) SSLBaseFilter(org.glassfish.grizzly.ssl.SSLBaseFilter) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter) ProtocolChainInstanceHandler(org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler) ProtocolChain(org.glassfish.grizzly.config.dom.ProtocolChain) List(java.util.List) ArrayList(java.util.ArrayList) FilterChainBuilder(org.glassfish.grizzly.filterchain.FilterChainBuilder) SSLProtocolFinder(org.glassfish.grizzly.portunif.finders.SSLProtocolFinder) Protocol(org.glassfish.grizzly.config.dom.Protocol) PUProtocol(org.glassfish.grizzly.portunif.PUProtocol) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter)

Example 35 with Protocol

use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.

the class SecureAdminConfigUpgrade method isOriginalAdminSecured.

private boolean isOriginalAdminSecured() {
    /*
         * The Grizzly conversion has already occurred.  So look for
         *
         * <server-config>
         *   <network-config>
         *     <protocols>
         *       <protocol name="admin-listener">
         *         <ssl ...>
         *
         */
    final Config serverConfig;
    final NetworkConfig nc;
    final Protocol p;
    final Ssl ssl;
    if ((serverConfig = configs.getConfigByName(SecureAdminUpgradeHelper.DAS_CONFIG_NAME)) == null) {
        return false;
    }
    if ((nc = serverConfig.getNetworkConfig()) == null) {
        return false;
    }
    if ((p = nc.findProtocol(ADMIN_LISTENER_NAME)) == null) {
        return false;
    }
    return (ssl = p.getSsl()) != null;
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) Ssl(org.glassfish.grizzly.config.dom.Ssl)

Aggregations

Protocol (org.glassfish.grizzly.config.dom.Protocol)42 Config (com.sun.enterprise.config.serverbeans.Config)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)18 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)16 CommandTarget (org.glassfish.config.support.CommandTarget)15 Target (org.glassfish.internal.api.Target)15 Protocols (org.glassfish.grizzly.config.dom.Protocols)14 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)12 ActionReport (org.glassfish.api.ActionReport)11 Http (org.glassfish.grizzly.config.dom.Http)9 PropertyVetoException (java.beans.PropertyVetoException)7 Ssl (org.glassfish.grizzly.config.dom.Ssl)7 List (java.util.List)6 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)5 ArrayList (java.util.ArrayList)4 PortUnification (org.glassfish.grizzly.config.dom.PortUnification)4 ProtocolChain (org.glassfish.grizzly.config.dom.ProtocolChain)4 ProtocolFinder (org.glassfish.grizzly.config.dom.ProtocolFinder)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4