use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.
the class OMailPlugin method configure.
private void configure() {
final File f = new File(OSystemVariableResolver.resolveSystemVariables(configFile));
if (f.exists()) {
// READ THE FILE
try {
final String configurationContent = OIOUtils.readFileAsString(f);
configuration = new ODocument().fromJSON(configurationContent);
} catch (IOException e) {
throw OException.wrapException(new OConfigurationException("Cannot load Mail configuration file '" + configFile + "'. Mail Plugin will be disabled"), e);
}
} else {
try {
f.getParentFile().mkdirs();
f.createNewFile();
OIOUtils.writeFile(f, configuration.toJSON("prettyPrint"));
OLogManager.instance().info(this, "Mail plugin: migrated configuration to file '%s'", f);
} catch (IOException e) {
throw OException.wrapException(new OConfigurationException("Cannot create Mail plugin configuration file '" + configFile + "'. Mail Plugin will be disabled"), e);
}
}
profiles.clear();
Collection<Map<String, Object>> profilesInDocs = configuration.field("profiles");
for (Map<String, Object> profile : profilesInDocs) {
String name = (String) profile.get("name");
OMailProfile p = profiles.get(name);
if (p == null) {
p = new OMailProfile();
profiles.put(name, p);
}
for (String s : profile.keySet()) {
if (!s.equalsIgnoreCase("name")) {
p.put(s, profile.get(s).toString());
}
}
}
}
use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.
the class OMailPlugin method changeConfig.
@Override
public void changeConfig(ODocument document) {
ODocument oldConfig = configuration;
configuration = document;
try {
writeConfiguration();
} catch (IOException e) {
configuration = oldConfig;
throw OException.wrapException(new OConfigurationException("Cannot Write Mail configuration file '" + configFile + "'. Restoring old configuration."), e);
}
configure();
}
use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method setServerUser.
@SuppressWarnings("unchecked")
@ConsoleCommand(description = "Set a server user. If the user already exists, the password and permissions are updated. For more information look at http://orientdb.com/docs/last/Security.html#orientdb-server-security", onlineHelp = "Console-Command-Set-Server-User")
public void setServerUser(@ConsoleParameter(name = "user-name", description = "User name") String iServerUserName, @ConsoleParameter(name = "user-password", description = "User password") String iServerUserPasswd, @ConsoleParameter(name = "user-permissions", description = "Permissions, look at http://orientdb.com/docs/last/Security.html#servers-resources") String iPermissions) {
if (iServerUserName == null || iServerUserName.length() == 0)
throw new IllegalArgumentException("User name null or empty");
if (iPermissions == null || iPermissions.length() == 0)
throw new IllegalArgumentException("User permissions null or empty");
final File serverCfgFile = new File("../config/orientdb-server-config.xml");
if (!serverCfgFile.exists())
throw new OConfigurationException("Cannot access to file " + serverCfgFile);
try {
final OServerConfigurationManager serverCfg = new OServerConfigurationManager(serverCfgFile);
final String defAlgo = OGlobalConfiguration.SECURITY_USER_PASSWORD_DEFAULT_ALGORITHM.getValueAsString();
final String hashedPassword = OSecurityManager.instance().createHash(iServerUserPasswd, defAlgo, true);
serverCfg.setUser(iServerUserName, hashedPassword, iPermissions);
serverCfg.saveConfiguration();
message("\nServer user '%s' set correctly", iServerUserName);
} catch (Exception e) {
error("\nError on loading %s file: %s", serverCfgFile, e.toString());
}
}
Aggregations