Search in sources :

Example 1 with DasConfig

use of com.sun.enterprise.config.serverbeans.DasConfig in project Payara by payara.

the class XMLPermissionsHandler method configureAppDeclaredPermissions.

private void configureAppDeclaredPermissions(File base) throws XMLStreamException, FileNotFoundException {
    File permissionsXml = new File(base.getAbsolutePath(), PermissionXMLParser.PERMISSIONS_XML);
    if (permissionsXml.exists()) {
        FileInputStream fi = null;
        try {
            // this one uses the Node approach
            PermissionsDeploymentDescriptorFile pddf = new PermissionsDeploymentDescriptorFile();
            if (serviceLocator != null) {
                dasConfig = serviceLocator.getService(DasConfig.class);
                if (dasConfig != null) {
                    String xmlValidationLevel = dasConfig.getDeployXmlValidation();
                    if (xmlValidationLevel.equals("none"))
                        pddf.setXMLValidation(false);
                    else
                        pddf.setXMLValidation(true);
                    pddf.setXMLValidationLevel(xmlValidationLevel);
                }
            }
            fi = new FileInputStream(permissionsXml);
            PermissionsDescriptor pd = (PermissionsDescriptor) pddf.read(fi);
            declaredPermXml = pd.getDeclaredPermissions();
        } catch (SAXParseException e) {
            throw new SecurityException(e);
        } catch (IOException e) {
            throw new SecurityException(e);
        } finally {
            if (fi != null) {
                try {
                    fi.close();
                } catch (IOException e) {
                }
            }
        }
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("App declared permission = " + declaredPermXml);
        }
    }
}
Also used : PermissionsDescriptor(com.sun.enterprise.deployment.PermissionsDescriptor) PermissionsDeploymentDescriptorFile(com.sun.enterprise.deployment.io.PermissionsDeploymentDescriptorFile) SAXParseException(org.xml.sax.SAXParseException) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig) IOException(java.io.IOException) PermissionsDeploymentDescriptorFile(com.sun.enterprise.deployment.io.PermissionsDeploymentDescriptorFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with DasConfig

use of com.sun.enterprise.config.serverbeans.DasConfig in project Payara by payara.

the class DynamicReloadService method changed.

public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    /*
         * Deal with any changes to the DasConfig that might affect whether
         * the reloader should be stopped or started or rescheduled with a
         * different frequency.  Those change are handled here, by this
         * class.
         */
    /* Record any events we tried to process but could not. */
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    Boolean newEnabled = null;
    Integer newPollIntervalInSeconds = null;
    for (PropertyChangeEvent event : events) {
        String propName = event.getPropertyName();
        if (event.getSource() instanceof DasConfig) {
            if (configPropertyNames.contains(propName) && (event.getOldValue().equals(event.getNewValue()))) {
                logger.fine("[DynamicReload] Ignoring reconfig of " + propName + " from " + event.getOldValue() + " to " + event.getNewValue());
                continue;
            }
            if (propName.equals("dynamic-reload-enabled")) {
                /*
                     * Either start the currently stopped reloader or stop the
                     * currently running one.
                     */
                newEnabled = Boolean.valueOf((String) event.getNewValue());
            } else if (propName.equals("dynamic-reload-poll-interval-in-seconds")) {
                try {
                    newPollIntervalInSeconds = new Integer((String) event.getNewValue());
                } catch (NumberFormatException ex) {
                    String reason = ex.getClass().getName() + " " + ex.getLocalizedMessage();
                    logger.log(Level.WARNING, reason);
                }
            }
        }
    }
    if (newEnabled != null) {
        if (newEnabled) {
            start(newPollIntervalInSeconds == null ? getPollIntervalInSeconds(activeDasConfig) : newPollIntervalInSeconds);
        } else {
            stop();
        }
    } else {
        if (newPollIntervalInSeconds != null && isEnabled(activeDasConfig)) {
            /*
                 * There is no change in whether the reloader should be running, only
                 * in how often it should run.  If it is not running now don't
                 * start it.  If it is running now, restart it to use the new
                 * polling interval.
                 */
            reschedule(newPollIntervalInSeconds);
        }
    }
    return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig)

Example 3 with DasConfig

use of com.sun.enterprise.config.serverbeans.DasConfig in project Payara by payara.

the class AutoDeployService method changed.

@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    if (autoDeployer == null) {
        return null;
    }
    /* Record any events we tried to process but could not. */
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    Boolean newEnabled = null;
    Integer newPollingIntervalInSeconds = null;
    for (PropertyChangeEvent event : events) {
        if (event.getSource() instanceof DasConfig) {
            String propName = event.getPropertyName();
            if (configPropertyNames.contains(propName) && event.getOldValue().equals(event.getNewValue())) {
                deplLogger.fine("[AutoDeploy] Ignoring reconfig of " + propName + " from " + event.getOldValue() + " to " + event.getNewValue());
                continue;
            }
            /*
                 * Substitute any placeholders in the new and old values.
                 */
            final String oldValue = replaceTokens((String) event.getOldValue(), System.getProperties());
            final String newValue = replaceTokens((String) event.getNewValue(), System.getProperties());
            if (propName.equals("autodeploy-enabled")) {
                /*
                     * Either start the currently stopped autodeployer or stop the
                     * currently running one.
                     */
                newEnabled = Boolean.valueOf(newValue);
                deplLogger.fine("[AutoDeploy] Reconfig - enabled changed to " + newEnabled);
            } else if (propName.equals("autodeploy-polling-interval-in-seconds")) {
                try {
                    newPollingIntervalInSeconds = new Integer(newValue);
                    deplLogger.fine("[AutoDeploy] Reconfig - polling interval (seconds) changed from " + oldValue + " to " + newPollingIntervalInSeconds);
                } catch (NumberFormatException ex) {
                    deplLogger.log(Level.WARNING, CONFIGURATION_CHANGE_ERROR, new Object[] { propName, oldValue, newValue, ex.getClass().getName(), ex.getLocalizedMessage() });
                }
            } else if (propName.equals("autodeploy-dir")) {
                String newDir = newValue;
                try {
                    autoDeployer.setDirectory(newDir);
                    deplLogger.fine("[AutoDeploy] Reconfig - directory changed from " + oldValue + " to " + newDir);
                } catch (AutoDeploymentException ex) {
                    deplLogger.log(Level.WARNING, CONFIGURATION_CHANGE_ERROR, new Object[] { propName, oldValue, newValue, ex.getClass().getName(), ex.getLocalizedMessage() });
                }
            } else if (propName.equals("autodeploy-verifier-enabled")) {
                boolean newVerifierEnabled = Boolean.parseBoolean(newValue);
                autoDeployer.setVerifierEnabled(newVerifierEnabled);
                deplLogger.fine("[AutoDeploy] Reconfig - verifierEnabled changed from " + Boolean.parseBoolean(oldValue) + " to " + newVerifierEnabled);
            } else if (propName.equals("autodeploy-jsp-precompilation-enabled")) {
                boolean newJspPrecompiled = Boolean.parseBoolean(newValue);
                autoDeployer.setJspPrecompilationEnabled(newJspPrecompiled);
                deplLogger.fine("[AutoDeploy] Reconfig - jspPrecompilationEnabled changed from " + Boolean.parseBoolean(oldValue) + " to " + newJspPrecompiled);
            }
        }
    }
    if (newEnabled != null) {
        if (newEnabled) {
            startAutoDeployer(newPollingIntervalInSeconds == null ? getPollingIntervalInSeconds() : newPollingIntervalInSeconds);
        } else {
            stopAutoDeployer();
        }
    } else {
        if ((newPollingIntervalInSeconds != null) && isAutoDeployEnabled()) {
            /*
                 * There is no change in whether the autodeployer should be running, only
                 * in how often it should run.  If it is not running now don't
                 * start it.  If it is running now, restart it to use the new
                 * polling interval.
                 */
            rescheduleAutoDeployer(newPollingIntervalInSeconds);
        }
    }
    return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig)

Example 4 with DasConfig

use of com.sun.enterprise.config.serverbeans.DasConfig in project Payara by payara.

the class PermissionsXMLLoader method getPermissionsDeploymentDescriptorFile.

private PermissionsDeploymentDescriptorFile getPermissionsDeploymentDescriptorFile() {
    PermissionsDeploymentDescriptorFile descriptorFile = new PermissionsDeploymentDescriptorFile();
    if (serviceLocator == null) {
        return descriptorFile;
    }
    dasConfig = serviceLocator.getService(DasConfig.class);
    if (dasConfig == null) {
        return descriptorFile;
    }
    String xmlValidationLevel = dasConfig.getDeployXmlValidation();
    if (xmlValidationLevel.equals("none")) {
        descriptorFile.setXMLValidation(false);
    } else {
        descriptorFile.setXMLValidation(true);
    }
    descriptorFile.setXMLValidationLevel(xmlValidationLevel);
    return descriptorFile;
}
Also used : PermissionsDeploymentDescriptorFile(com.sun.enterprise.deployment.io.PermissionsDeploymentDescriptorFile) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig)

Aggregations

DasConfig (com.sun.enterprise.config.serverbeans.DasConfig)4 PermissionsDeploymentDescriptorFile (com.sun.enterprise.deployment.io.PermissionsDeploymentDescriptorFile)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 ArrayList (java.util.ArrayList)2 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)2 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)2 PermissionsDescriptor (com.sun.enterprise.deployment.PermissionsDescriptor)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 SAXParseException (org.xml.sax.SAXParseException)1