Search in sources :

Example 51 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class SecurityUpgradeService method postConstruct.

public void postConstruct() {
    for (Config config : configs.getConfig()) {
        SecurityService service = config.getSecurityService();
        if (service != null) {
            upgradeJACCProvider(service);
        }
    }
    // Clear up the old policy files for applications
    String instanceRoot = env.getInstanceRoot().getAbsolutePath();
    File genPolicyDir = new File(instanceRoot, DIR_GENERATED_POLICY);
    if (genPolicyDir != null) {
        File[] applicationDirs = genPolicyDir.listFiles();
        if (applicationDirs != null) {
            for (File policyDir : applicationDirs) {
                deleteFile(policyDir);
            }
        }
    }
    for (Config config : configs.getConfig()) {
        SecurityService service = config.getSecurityService();
        List<AuthRealm> authRealms = service.getAuthRealm();
        try {
            for (AuthRealm authRealm : authRealms) {
                if (JDBC_REALM_CLASSNAME.equals(authRealm.getClassname())) {
                    Property digestAlgoProp = authRealm.getProperty(PARAM_DIGEST_ALGORITHM);
                    if (digestAlgoProp != null) {
                        String digestAlgo = digestAlgoProp.getValue();
                        if (digestAlgo == null || digestAlgo.isEmpty()) {
                            digestAlgoProp.setValue("MD5");
                        }
                    } else {
                        ConfigSupport.apply(new SingleConfigCode<AuthRealm>() {

                            public Object run(AuthRealm updatedAuthRealm) throws PropertyVetoException, TransactionFailure {
                                Property prop1 = updatedAuthRealm.createChild(Property.class);
                                prop1.setName(PARAM_DIGEST_ALGORITHM);
                                prop1.setValue("MD5");
                                updatedAuthRealm.getProperty().add(prop1);
                                return null;
                            }
                        }, authRealm);
                    }
                }
            }
        } catch (PropertyVetoException pve) {
            _logger.log(Level.SEVERE, SecurityLoggerInfo.securityUpgradeServiceException, pve);
            throw new RuntimeException(pve);
        } catch (TransactionFailure tf) {
            _logger.log(Level.SEVERE, SecurityLoggerInfo.securityUpgradeServiceException, tf);
            throw new RuntimeException(tf);
        }
    }
    if (requiresSecureAdmin()) {
        _logger.log(Level.WARNING, SecurityLoggerInfo.securityUpgradeServiceWarning);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) File(java.io.File) Property(org.jvnet.hk2.config.types.Property)

Example 52 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class RealmsManager method setDefaultDigestAlgorithm.

private void setDefaultDigestAlgorithm() {
    SecurityService service = config.getSecurityService();
    if (service == null) {
        return;
    }
    List<Property> props = service.getProperty();
    if (props == null) {
        return;
    }
    Iterator<Property> propsIterator = props.iterator();
    while (propsIterator != null && propsIterator.hasNext()) {
        Property prop = propsIterator.next();
        if (prop != null && DEFAULT_DIGEST_ALGORITHM.equals(prop.getName())) {
            this.defaultDigestAlgorithm = prop.getValue();
            break;
        }
    }
}
Also used : SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) Property(org.jvnet.hk2.config.types.Property)

Example 53 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class ConfigApiTest method getHabitat.

/**
 * Returns a configured Habitat with the configuration.
 *
 * @return a configured Habitat
 */
public ServiceLocator getHabitat() {
    ServiceLocator habitat = Utils.instance.getHabitat(this);
    assertNotNull("Transactions service from Configuration subsystem is null", habitat.getService(Transactions.class));
    return habitat;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Transactions(org.jvnet.hk2.config.Transactions)

Example 54 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class UpgradeLogging method doUpgrade.

private void doUpgrade(Config config) {
    // v3 uses logging.properties to configure the logging facility.
    // move all log-service elements to logging.properties
    final LogService logService = config.getLogService();
    // check if null and exit
    if (logService == null)
        return;
    try {
        RepositoryConfig rc = new RepositoryConfig();
        String configDir = rc.getRepositoryRoot() + File.separator + rc.getRepositoryName() + File.separator + rc.getInstanceName() + File.separator + "config";
        PEFileLayout layout = new PEFileLayout(rc);
        File src = new File(layout.getTemplatesDir(), PEFileLayout.LOGGING_PROPERTIES_FILE);
        File dest = new File(configDir, PEFileLayout.LOGGING_PROPERTIES_FILE);
        if (!dest.exists())
            FileUtils.copy(src, dest);
    } catch (IOException ioe) {
        getLogger().log(Level.SEVERE, FAIL_CREATE_LOG_PROPS, ioe);
    }
    try {
        // Get the logLevels
        ModuleLogLevels mll = logService.getModuleLogLevels();
        Map<String, String> logLevels = mll.getAllLogLevels();
        String file = logService.getFile();
        String payaraNotificationFile = logService.getPayaraNotificationFile();
        String instanceRoot = System.getProperty("com.sun.aas.instanceRoot");
        if (file.contains(instanceRoot)) {
            file = file.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
        }
        if (payaraNotificationFile.contains(instanceRoot)) {
            payaraNotificationFile = payaraNotificationFile.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
        }
        logLevels.put("file", file);
        logLevels.put("payara-notification-file", payaraNotificationFile);
        logLevels.put("use-system-logging", logService.getUseSystemLogging());
        // this can have multiple values so need to add
        logLevels.put("log-handler", logService.getLogHandler());
        logLevels.put("log-filter", logService.getLogFilter());
        logLevels.put("log-to-file", logService.getLogToFile());
        logLevels.put("payara-notification-log-to-file", logService.getPayaraNotificationLogToFile());
        logLevels.put("log-to-console", logService.getLogToConsole());
        logLevels.put("log-rotation-limit-in-bytes", logService.getLogRotationLimitInBytes());
        logLevels.put("payara-notification-log-rotation-limit-in-bytes", logService.getPayaraNotificationLogRotationLimitInBytes());
        logLevels.put("log-rotation-timelimit-in-minutes", logService.getLogRotationTimelimitInMinutes());
        logLevels.put("payara-notification-log-rotation-timelimit-in-minutes", logService.getPayaraNotificationLogRotationTimelimitInMinutes());
        logLevels.put("alarms", logService.getAlarms());
        logLevels.put("retain-error-statistics-for-hours", logService.getRetainErrorStatisticsForHours());
        final Map<String, String> m = new HashMap<String, String>(logLevels);
        ConfigSupport.apply(new SingleConfigCode<Config>() {

            public Object run(Config c) throws PropertyVetoException, TransactionFailure {
                try {
                    // update logging.properties
                    logConfig.updateLoggingProperties(m);
                    c.setLogService(null);
                } catch (IOException e) {
                    getLogger().log(Level.SEVERE, FAIL_UPDATE_LOG_PROPS, e);
                }
                return null;
            }
        }, config);
    } catch (TransactionFailure tf) {
        getLogger().log(Level.SEVERE, FAIL_UPGRADE_LOG_SERVICE, tf);
        throw new RuntimeException(tf);
    }
}
Also used : RepositoryConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) HashMap(java.util.HashMap) RepositoryConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) File(java.io.File)

Example 55 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class TemplateRestResource method buildPath.

/**
 * This method will build the path string as needed by ConfigModularityUtils.getOwningObject().
 * There is a mismatch between what the method expects and the way the REST URIs are constructed.
 * For example, for the transaction-service element, the REST URI, stripped of the HTTP and
 * server context information, looks like this:
 * /domain/configs/config/server-config/transaction-service.  The format expected by the
 * getOwningObject(), however, looks like this:
 * domain/configs/server-config/transaction-service. In the REST URIs, if there is a collection of
 * Named items, the type of the collection is inserted into the URI ("config" here) followed by
 * the name of the particular instance ("server-config").  In building the path, we must identify
 * Named instances and insert the name of the instance rather than the type.  We apply this logic
 * as we recurse up to the top of the Dom tree to finish building the path desired.
 * @param node
 * @return
 */
private String buildPath(Dom node) {
    final Dom parentNode = node.parent();
    String part = node.model.getTagName();
    String name = node.attribute("name");
    if (name != null) {
        part = name;
    }
    return (parentNode != null) ? (buildPath(parentNode) + "/" + part) : part;
}
Also used : Dom(org.jvnet.hk2.config.Dom)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)25 PropertyVetoException (java.beans.PropertyVetoException)21 ActionReport (org.glassfish.api.ActionReport)16 Property (org.jvnet.hk2.config.types.Property)16 Config (com.sun.enterprise.config.serverbeans.Config)14 ArrayList (java.util.ArrayList)8 File (java.io.File)7 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 Service (org.jvnet.hk2.annotations.Service)5 Resources (com.sun.enterprise.config.serverbeans.Resources)4 List (java.util.List)4 Test (org.junit.Test)4 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)4 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)4 Cluster (com.sun.enterprise.config.serverbeans.Cluster)3 Domain (com.sun.enterprise.config.serverbeans.Domain)3 HttpService (com.sun.enterprise.config.serverbeans.HttpService)3 Resource (com.sun.enterprise.config.serverbeans.Resource)3