use of org.jvnet.hk2.config.types.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;
}
use of org.jvnet.hk2.config.types.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;
}
use of org.jvnet.hk2.config.types.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)));
}
use of org.jvnet.hk2.config.types.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)));
}
use of org.jvnet.hk2.config.types.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 }));
}
Aggregations