Search in sources :

Example 41 with OConfigurationException

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());
            }
        }
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) IOException(java.io.IOException) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 42 with OConfigurationException

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();
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 43 with OConfigurationException

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());
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OServerConfigurationManager(com.orientechnologies.orient.server.config.OServerConfigurationManager) OSystemException(com.orientechnologies.common.exception.OSystemException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Aggregations

OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)43 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)16 IOException (java.io.IOException)12 OException (com.orientechnologies.common.exception.OException)9 File (java.io.File)8 OIOException (com.orientechnologies.common.io.OIOException)5 OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 OSystemException (com.orientechnologies.common.exception.OSystemException)3 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)3 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)3 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)3 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OStorage (com.orientechnologies.orient.core.storage.OStorage)2 OETLProcessHaltedException (com.orientechnologies.orient.etl.OETLProcessHaltedException)2 OServerConfigurationManager (com.orientechnologies.orient.server.config.OServerConfigurationManager)2 OServerNetworkListener (com.orientechnologies.orient.server.network.OServerNetworkListener)2 KeyStore (java.security.KeyStore)2