Search in sources :

Example 6 with Property

use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.

the class VirtualServer method configureRemoteHostFilterValve.

/**
 * Configures the Remote Host Filter valve of this VirtualServer.
 *
 * This valve enforces request acceptance/denial based on the name of the
 * remote host from where the request originated.
 */
void configureRemoteHostFilterValve() {
    Property allow = vsBean.getProperty("allowRemoteHost");
    Property deny = vsBean.getProperty("denyRemoteHost");
    String allowStr = null;
    String denyStr = null;
    if (allow != null) {
        allowStr = allow.getValue();
    }
    if (deny != null) {
        denyStr = deny.getValue();
    }
    configureRemoteHostFilterValve(allowStr, denyStr);
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 7 with Property

use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.

the class VirtualServer method configureRedirect.

/**
 * Configures this VirtualServer with its redirect properties.
 */
void configureRedirect() {
    vsPipeline.clearRedirects();
    List<Property> props = vsBean.getProperty();
    if (props == null) {
        return;
    }
    for (Property prop : props) {
        String propName = prop.getName();
        String propValue = prop.getValue();
        if (propName == null || propValue == null) {
            _logger.log(Level.WARNING, LogFacade.NULL_VIRTUAL_SERVER_PROPERTY, getID());
            continue;
        }
        if (!propName.startsWith("redirect_")) {
            continue;
        }
        /*
             * Validate the prop value
             */
        String from = null;
        String url = null;
        String urlPrefix = null;
        String escape = null;
        String[] redirectParams = propValue.split(" ");
        for (int j = 0; j < redirectParams.length; j++) {
            if (redirectParams[j].startsWith("from=")) {
                if (from != null) {
                    _logger.log(Level.WARNING, LogFacade.REDIRECT_MULTIPLE_ELEMENT, new Object[] { propValue, getID(), "from" });
                }
                from = redirectParams[j].substring("from=".length());
            }
            if (redirectParams[j].startsWith("url=")) {
                if (url != null) {
                    _logger.log(Level.WARNING, LogFacade.REDIRECT_MULTIPLE_ELEMENT, new Object[] { propValue, getID(), "url" });
                }
                url = redirectParams[j].substring("url=".length());
            }
            if (redirectParams[j].startsWith("url-prefix=")) {
                if (urlPrefix != null) {
                    _logger.log(Level.WARNING, LogFacade.REDIRECT_MULTIPLE_ELEMENT, new Object[] { propValue, getID(), "url-prefix" });
                }
                urlPrefix = redirectParams[j].substring("url-prefix=".length());
            }
            if (redirectParams[j].startsWith("escape=")) {
                if (escape != null) {
                    _logger.log(Level.WARNING, LogFacade.REDIRECT_MULTIPLE_ELEMENT, new Object[] { propValue, getID(), "escape" });
                }
                escape = redirectParams[j].substring("escape=".length());
            }
        }
        if (from == null || from.length() == 0) {
            _logger.log(Level.WARNING, LogFacade.REDIRECT_MULTIPLE_ELEMENT, new Object[] { propValue, getID() });
        }
        // Either url or url-prefix (but not both!) must be present
        if ((url == null || url.length() == 0) && (urlPrefix == null || urlPrefix.length() == 0)) {
            _logger.log(Level.WARNING, LogFacade.REDIRECT_MISSING_URL_OR_URL_PREFIX, new Object[] { propValue, getID() });
        }
        if (url != null && url.length() > 0 && urlPrefix != null && urlPrefix.length() > 0) {
            _logger.log(Level.WARNING, LogFacade.REDIRECT_BOTH_URL_AND_URL_PREFIX, new Object[] { propValue, getID() });
        }
        boolean escapeURI = true;
        if (escape != null) {
            if ("yes".equalsIgnoreCase(escape)) {
                escapeURI = true;
            } else if ("no".equalsIgnoreCase(escape)) {
                escapeURI = false;
            } else {
                _logger.log(Level.WARNING, LogFacade.REDIRECT_INVALID_ESCAPE, new Object[] { propValue, getID() });
            }
        }
        vsPipeline.addRedirect(from, url, urlPrefix, escapeURI);
    }
    if (vsPipeline.hasRedirects()) {
        if (pipeline != vsPipeline) {
            // Enable custom pipeline
            setPipeline(vsPipeline);
        }
    } else if (isActive && pipeline != origPipeline) {
        setPipeline(origPipeline);
    }
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 8 with Property

use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.

the class WebContainer method configureHttpServiceProperties.

/**
 * Configure http-service properties.
 *
 * @param httpService
 * @param connector
 * @deprecated most of these properties are handled elsewhere.  validate and remove outdated properties checks
 */
public void configureHttpServiceProperties(HttpService httpService, PECoyoteConnector connector) {
    // Configure Connector with <http-service> properties
    List<Property> httpServiceProps = httpService.getProperty();
    // Set default ProxyHandler impl, may be overriden by
    // proxyHandler property
    connector.setProxyHandler(new ProxyHandlerImpl());
    globalSSOEnabled = ConfigBeansUtilities.toBoolean(httpService.getSsoEnabled());
    globalAccessLoggingEnabled = ConfigBeansUtilities.toBoolean(httpService.getAccessLoggingEnabled());
    globalAccessLogWriteInterval = httpService.getAccessLog().getWriteIntervalSeconds();
    globalAccessLogBufferSize = httpService.getAccessLog().getBufferSizeBytes();
    if (httpServiceProps != null) {
        for (Property httpServiceProp : httpServiceProps) {
            String propName = httpServiceProp.getName();
            String propValue = httpServiceProp.getValue();
            if (connector.configureHttpListenerProperty(propName, propValue)) {
                continue;
            }
            if ("connectionTimeout".equals(propName)) {
                connector.setConnectionTimeout(Integer.parseInt(propValue));
            } else if ("tcpNoDelay".equals(propName)) {
                connector.setTcpNoDelay(ConfigBeansUtilities.toBoolean(propValue));
            } else if ("traceEnabled".equals(propName)) {
                connector.setAllowTrace(ConfigBeansUtilities.toBoolean(propValue));
            } else if ("ssl-session-timeout".equals(propName)) {
                connector.setSslSessionTimeout(propValue);
            } else if ("ssl3-session-timeout".equals(propName)) {
                connector.setSsl3SessionTimeout(propValue);
            } else if ("ssl-cache-entries".equals(propName)) {
                connector.setSslSessionCacheSize(propValue);
            } else if ("proxyHandler".equals(propName)) {
                connector.setProxyHandler(propValue);
            } else {
                String msg = rb.getString(LogFacade.INVALID_HTTP_SERVICE_PROPERTY);
                logger.log(Level.WARNING, MessageFormat.format(msg, httpServiceProp.getName()));
                ;
            }
        }
    }
}
Also used : Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty)

Example 9 with Property

use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.

the class WebContainer method updateHost.

/**
 * Updates a virtual-server element.
 *
 * @param vsBean the virtual-server config bean.
 */
public void updateHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean) throws LifecycleException {
    if (org.glassfish.api.web.Constants.ADMIN_VS.equals(vsBean.getId())) {
        return;
    }
    final VirtualServer vs = (VirtualServer) getEngine().findChild(vsBean.getId());
    if (vs == null) {
        logger.log(Level.WARNING, LogFacade.CANNOT_UPDATE_NON_EXISTENCE_VS, vsBean.getId());
        return;
    }
    boolean updateListeners = false;
    // Only update connectors if virtual-server.http-listeners is changed dynamically
    if (vs.getNetworkListeners() == null) {
        if (vsBean.getNetworkListeners() == null) {
            updateListeners = false;
        } else {
            updateListeners = true;
        }
    } else if (vs.getNetworkListeners().equals(vsBean.getNetworkListeners())) {
        updateListeners = false;
    } else {
        List<String> vsList = StringUtils.parseStringList(vs.getNetworkListeners(), ",");
        List<String> vsBeanList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
        for (String vsBeanName : vsBeanList) {
            if (!vsList.contains(vsBeanName)) {
                updateListeners = true;
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogFacade.UPDATE_LISTENER, new Object[] { vsBeanName, vs.getNetworkListeners() });
                }
                break;
            }
        }
    }
    // Must retrieve the old default-web-module before updating the
    // virtual server with the new vsBean, because default-web-module is
    // read from vsBean
    String oldDefaultWebModule = vs.getDefaultWebModuleID();
    vs.setBean(vsBean);
    String vsLogFile = vsBean.getLogFile();
    vs.setLogFile(vsLogFile, logLevel, logServiceFile);
    vs.configureState();
    vs.clearAliases();
    vs.configureAliases();
    // support both docroot property and attribute
    String docroot = vsBean.getPropertyValue("docroot");
    if (docroot == null) {
        docroot = vsBean.getDocroot();
    }
    if (docroot != null) {
        // Only update docroot if it is modified
        if (!vs.getDocRoot().getAbsolutePath().equals(docroot)) {
            updateDocroot(docroot, vs, vsBean);
        }
    }
    List<Property> props = vs.getProperties();
    for (Property prop : props) {
        updateHostProperties(vsBean, prop.getName(), prop.getValue(), securityService, vs);
    }
    vs.configureSingleSignOn(globalSSOEnabled, webContainerFeatureFactory, isSsoFailoverEnabled());
    vs.reconfigureAccessLog(globalAccessLogBufferSize, globalAccessLogWriteInterval, habitat, domain, globalAccessLoggingEnabled);
    // old listener names
    List<String> oldListenerList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
    String[] oldListeners = (oldListenerList != null) ? oldListenerList.toArray(new String[oldListenerList.size()]) : new String[0];
    // new listener config
    HashSet<NetworkListener> networkListeners = new HashSet<NetworkListener>();
    if (oldListenerList != null) {
        for (String listener : oldListeners) {
            boolean found = false;
            for (NetworkListener httpListener : serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
                if (httpListener.getName().equals(listener)) {
                    networkListeners.add(httpListener);
                    found = true;
                    break;
                }
            }
            if (!found) {
                String msg = rb.getString(LogFacade.LISTENER_REFERENCED_BY_HOST_NOT_EXIST);
                msg = MessageFormat.format(msg, listener, vs.getName());
                logger.log(Level.SEVERE, msg);
            }
        }
        // Update the port numbers with which the virtual server is
        // associated
        configureHostPortNumbers(vs, networkListeners);
    } else {
        // The virtual server is not associated with any http listeners
        vs.setNetworkListenerNames(new String[0]);
    }
    // have been removed from its http-listeners attribute
    for (String oldListener : oldListeners) {
        boolean found = false;
        for (NetworkListener httpListener : networkListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was removed
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (oldListener.equals(conn.getName())) {
                    try {
                        conn.getMapperListener().unregisterHost(vs.getJmxName());
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // have been added to its http-listeners attribute
    for (NetworkListener httpListener : networkListeners) {
        boolean found = false;
        for (String oldListener : oldListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was added
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (httpListener.getName().equals(conn.getName())) {
                    if (!conn.isAvailable()) {
                        conn.start();
                    }
                    try {
                        conn.getMapperListener().registerHost(vs);
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // passing in "null" as the default context path
    if (oldDefaultWebModule != null) {
        updateDefaultWebModule(vs, oldListeners, null);
    }
    /*
         * Add default web module if one has been configured for the
         * virtual server. If the module declared as the default web module
         * has already been deployed at the root context, we don't have
         * to do anything.
         */
    WebModuleConfig wmInfo = vs.getDefaultWebModule(domain, habitat.<WebArchivist>getService(WebArchivist.class), appRegistry);
    if ((wmInfo != null) && (wmInfo.getContextPath() != null) && !"".equals(wmInfo.getContextPath()) && !"/".equals(wmInfo.getContextPath())) {
        // Remove dummy context that was created off of docroot, if such
        // a context exists
        removeDummyModule(vs);
        updateDefaultWebModule(vs, vs.getNetworkListenerNames(), wmInfo);
    } else {
        WebModuleConfig wmc = vs.createSystemDefaultWebModuleIfNecessary(habitat.<WebArchivist>getService(WebArchivist.class));
        if (wmc != null) {
            loadStandaloneWebModule(vs, wmc);
        }
    }
    if (updateListeners) {
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, LogFacade.VS_UPDATED_NETWORK_LISTENERS, new Object[] { vs.getName(), vs.getNetworkListeners(), vsBean.getNetworkListeners() });
        }
        /*
             * Need to update connector and mapper restart is required
             * when virtual-server.http-listeners is changed dynamically
             */
        List<NetworkListener> httpListeners = serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener();
        if (httpListeners != null) {
            for (NetworkListener httpListener : httpListeners) {
                updateConnector(httpListener, habitat.<HttpService>getService(HttpService.class));
            }
        }
    }
}
Also used : PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) Connector(org.apache.catalina.Connector) LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) HashSet(java.util.HashSet)

Example 10 with Property

use of org.jvnet.hk2.config.ConfigModel.Property in project Payara by payara.

the class WebContainer method createHost.

/**
 * Creates a Host from a virtual-server config bean.
 *
 * @param vsBean          The virtual-server configuration bean
 * @param httpService     The http-service element.
 * @param securityService The security-service element
 * @return
 */
public VirtualServer createHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean, HttpService httpService, SecurityService securityService) {
    String vs_id = vsBean.getId();
    String docroot = vsBean.getPropertyValue("docroot");
    if (docroot == null) {
        docroot = vsBean.getDocroot();
    }
    validateDocroot(docroot, vs_id, vsBean.getDefaultWebModule());
    VirtualServer vs = createHost(vs_id, vsBean, docroot, null);
    // cache control
    Property cacheProp = vsBean.getProperty("setCacheControl");
    if (cacheProp != null) {
        vs.configureCacheControl(cacheProp.getValue());
    }
    PEAccessLogValve accessLogValve = vs.getAccessLogValve();
    boolean startAccessLog = accessLogValve.configure(vs_id, vsBean, httpService, domain, habitat, webContainerFeatureFactory, globalAccessLogBufferSize, globalAccessLogWriteInterval);
    if (startAccessLog && vs.isAccessLoggingEnabled(globalAccessLoggingEnabled)) {
        vs.addValve((GlassFishValve) accessLogValve);
    }
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, LogFacade.VIRTUAL_SERVER_CREATED, vs_id);
    }
    /*
         * We must configure the Host with its associated port numbers and
         * alias names before adding it as an engine child and thereby
         * starting it, because a MapperListener, which is associated with
         * an HTTP listener and receives notifications about Host
         * registrations, relies on these Host properties in order to determine
         * whether a new Host needs to be added to the HTTP listener's Mapper.
         */
    configureHost(vs, securityService);
    vs.setDomain(domain);
    vs.setServices(habitat);
    vs.setClassLoaderHierarchy(clh);
    // Add Host to Engine
    engine.addChild(vs);
    ObservableBean virtualServerBean = (ObservableBean) ConfigSupport.getImpl(vsBean);
    virtualServerBean.addListener(configListener);
    return vs;
}
Also used : ObservableBean(org.jvnet.hk2.config.ObservableBean) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty)

Aggregations

Property (org.jvnet.hk2.config.types.Property)149 PropertyVetoException (java.beans.PropertyVetoException)30 HashMap (java.util.HashMap)27 Properties (java.util.Properties)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 ArrayList (java.util.ArrayList)18 ActionReport (org.glassfish.api.ActionReport)17 Map (java.util.Map)15 File (java.io.File)13 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)12 Config (com.sun.enterprise.config.serverbeans.Config)11 List (java.util.List)11 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)10 HttpService (com.sun.enterprise.config.serverbeans.HttpService)9 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)9 Server (com.sun.enterprise.config.serverbeans.Server)8 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 Application (com.sun.enterprise.config.serverbeans.Application)7 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)7