Search in sources :

Example 41 with Property

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

the class CopyConfig method copyConfig.

public Config copyConfig(Configs configs, Config config, String destConfigName, Logger logger) throws PropertyVetoException, TransactionFailure {
    final Config destCopy = (Config) config.deepCopy(configs);
    if (systemproperties != null) {
        final Properties properties = GenericCrudCommand.convertStringToProperties(systemproperties, ':');
        for (final Object key : properties.keySet()) {
            final String propName = (String) key;
            // cannot update a system property so remove it first
            List<SystemProperty> sysprops = destCopy.getSystemProperty();
            for (SystemProperty sysprop : sysprops) {
                if (propName.equals(sysprop.getName())) {
                    sysprops.remove(sysprop);
                    break;
                }
            }
            SystemProperty newSysProp = destCopy.createChild(SystemProperty.class);
            newSysProp.setName(propName);
            newSysProp.setValue(properties.getProperty(propName));
            destCopy.getSystemProperty().add(newSysProp);
        }
    }
    final String configName = destConfigName;
    destCopy.setName(configName);
    configs.getConfig().add(destCopy);
    copyOfConfig = destCopy;
    String srcConfig = "";
    srcConfig = config.getName();
    File configConfigDir = new File(env.getConfigDirPath(), configName);
    for (Config c : configs.getConfig()) {
        File existingConfigConfigDir = new File(env.getConfigDirPath(), c.getName());
        if (!c.getName().equals(configName) && configConfigDir.equals(existingConfigConfigDir)) {
            throw new TransactionFailure(localStrings.getLocalString("config.duplicate.dir", "Config {0} is trying to use the same directory as config {1}", configName, c.getName()));
        }
    }
    try {
        if (!(new File(configConfigDir, "docroot").mkdirs() && new File(configConfigDir, "lib/ext").mkdirs())) {
            throw new IOException(localStrings.getLocalString("config.mkdirs", "error creating config specific directories"));
        }
        String srcConfigLoggingFile = env.getInstanceRoot().getAbsolutePath() + File.separator + "config" + File.separator + srcConfig + File.separator + ServerEnvironmentImpl.kLoggingPropertiesFileName;
        File src = new File(srcConfigLoggingFile);
        if (!src.exists()) {
            src = new File(env.getConfigDirPath(), ServerEnvironmentImpl.kLoggingPropertiesFileName);
        }
        File dest = new File(configConfigDir, ServerEnvironmentImpl.kLoggingPropertiesFileName);
        FileUtils.copy(src, dest);
    } catch (Exception e) {
        logger.log(Level.WARNING, ConfigApiLoggerInfo.copyConfigError, e.getLocalizedMessage());
    }
    return destCopy;
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException)

Example 42 with Property

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

the class LDAPRealmPropertyCheckValidator method isValid.

public boolean isValid(final AuthRealm realm, final ConstraintValidatorContext constraintValidatorContext) {
    if (realm.getClassname().equals(LDAP_REALM)) {
        Property jaas_context = realm.getProperty("jaas-context");
        Property dn = realm.getProperty("base-dn");
        Property url = realm.getProperty("directory");
        if (jaas_context == null || jaas_context.getName().equals(""))
            return false;
        if (url == null || url.getName().equals(""))
            return false;
        if (dn == null || dn.getName().equals(""))
            return false;
    }
    return true;
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 43 with Property

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

the class PropertiesBagResource method clearThenSaveProperties.

protected ActionReportResult clearThenSaveProperties(List<Map<String, String>> properties) {
    RestActionReporter ar = new RestActionReporter();
    ar.setActionDescription("property");
    try {
        TranslatedConfigView.doSubstitution.set(Boolean.FALSE);
        Map<String, Property> existing = getExistingProperties();
        deleteMissingProperties(existing, properties);
        Map<String, String> data = new LinkedHashMap<String, String>();
        for (Map<String, String> property : properties) {
            Property existingProp = existing.get(property.get("name"));
            String unescapedName = Object.class.cast(property.get("name")).toString();
            String escapedName = getEscapedPropertyName(unescapedName);
            String value = Object.class.cast(property.get("value")).toString();
            String unescapedValue = value.replaceAll("\\\\", "");
            String description = null;
            if (property.get(description) != null) {
                description = Object.class.cast(property.get("description")).toString();
            }
            // the prop name can not contain .
            // need to remove the . test when http://java.net/jira/browse/GLASSFISH-15418  is fixed
            boolean canSaveDesc = !((Object) property.get("name")).toString().contains(".");
            if ((existingProp == null) || !unescapedValue.equals(existingProp.getValue())) {
                data.put(escapedName, ((Object) property.get("value")).toString());
                if (canSaveDesc && (description != null)) {
                    data.put(escapedName + ".description", ((Object) description).toString());
                }
            }
            // update the description only if not null/blank
            if ((description != null) && (existingProp != null)) {
                if (!"".equals(description) && (!description.equals(existingProp.getDescription()))) {
                    if (canSaveDesc) {
                        data.put(escapedName + ".description", description);
                    }
                }
            }
        }
        if (!data.isEmpty()) {
            Util.applyChanges(data, uriInfo, getSubject());
        }
        String successMessage = localStrings.getLocalString("rest.resource.update.message", "\"{0}\" updated successfully.", new Object[] { uriInfo.getAbsolutePath() });
        ar.setSuccess();
        ar.setMessage(successMessage);
    } catch (Exception ex) {
        if (ex.getCause() instanceof ValidationException) {
            ar.setFailure();
            ar.setFailureCause(ex);
            ar.setMessage(ex.getLocalizedMessage());
        } else {
            logger.log(Level.FINE, "Error processing properties", ex);
            throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR);
        }
    } finally {
        TranslatedConfigView.doSubstitution.set(Boolean.TRUE);
    }
    return new ActionReportResult("properties", ar, new OptionsResult(Util.getResourceName(uriInfo)));
}
Also used : ValidationException(javax.validation.ValidationException) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) WebApplicationException(javax.ws.rs.WebApplicationException) ValidationException(javax.validation.ValidationException) WebApplicationException(javax.ws.rs.WebApplicationException) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Property(org.jvnet.hk2.config.types.Property)

Example 44 with Property

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

the class PropertiesBagResource method get.

@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Object get() {
    List<Dom> entities = getEntity();
    if (entities == null) {
        // empty dom list
        return new GetResultList(new ArrayList(), "", new String[][] {}, new OptionsResult(Util.getResourceName(uriInfo)));
    }
    RestActionReporter ar = new RestActionReporter();
    ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ar.setActionDescription("property");
    List properties = new ArrayList();
    for (Dom child : entities) {
        Map<String, String> entry = new HashMap<String, String>();
        entry.put("name", child.attribute("name"));
        entry.put("value", child.attribute("value"));
        String description = child.attribute("description");
        if (description != null) {
            entry.put("description", description);
        }
        properties.add(entry);
    }
    Properties extraProperties = new Properties();
    extraProperties.put("properties", properties);
    ar.setExtraProperties(extraProperties);
    return new ActionReportResult("properties", ar, new OptionsResult(Util.getResourceName(uriInfo)));
}
Also used : Dom(org.jvnet.hk2.config.Dom) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) GetResultList(org.glassfish.admin.rest.results.GetResultList) GetResultList(org.glassfish.admin.rest.results.GetResultList) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 45 with Property

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

the class GetGroupNamesCommand method getGroupNames.

private String[] getGroupNames(String realmName, String userName) throws NoSuchRealmException, BadRealmException, InvalidOperationException, NoSuchUserException {
    // account for updates to file-realm contents from outside this config
    // which are sharing the same keyfile
    realmsManager.refreshRealm(config.getName(), realmName);
    Realm r = realmsManager.getFromLoadedRealms(config.getName(), realmName);
    if (r != null) {
        return getGroupNames(r, userName);
    }
    List<AuthRealm> authRealmConfigs = config.getSecurityService().getAuthRealm();
    for (AuthRealm authRealm : authRealmConfigs) {
        if (realmName.equals(authRealm.getName())) {
            List<Property> propConfigs = authRealm.getProperty();
            Properties props = new Properties();
            for (Property p : propConfigs) {
                String value = p.getValue();
                props.setProperty(p.getName(), value);
            }
            r = Realm.instantiate(authRealm.getName(), authRealm.getClassname(), props, config.getName());
            return getGroupNames(r, userName);
        }
    }
    throw new NoSuchRealmException(_localStrings.getLocalString("NO_SUCH_REALM", "No Such Realm: {0}", new Object[] { realmName }));
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) Properties(java.util.Properties) AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Realm(com.sun.enterprise.security.auth.realm.Realm) Property(org.jvnet.hk2.config.types.Property)

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