Search in sources :

Example 1 with OServerConfigurationManager

use of com.orientechnologies.orient.server.config.OServerConfigurationManager in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method dropServerUser.

@SuppressWarnings("unchecked")
@ConsoleCommand(description = "Drop a server user. For more information look at http://orientdb.com/docs/last/Security.html#orientdb-server-security", onlineHelp = "Console-Command-Drop-Server-User")
public void dropServerUser(@ConsoleParameter(name = "user-name", description = "User name") String iServerUserName) {
    if (iServerUserName == null || iServerUserName.length() == 0)
        throw new IllegalArgumentException("User name 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);
        if (!serverCfg.existsUser(iServerUserName)) {
            error("\nServer user '%s' not found in configuration", iServerUserName);
            return;
        }
        serverCfg.dropUser(iServerUserName);
        serverCfg.saveConfiguration();
        message("\nServer user '%s' dropped 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)

Example 2 with OServerConfigurationManager

use of com.orientechnologies.orient.server.config.OServerConfigurationManager in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method listServerUsers.

@SuppressWarnings("unchecked")
@ConsoleCommand(description = "Display all the server user names. For more information look at http://orientdb.com/docs/last/Security.html#orientdb-server-security", onlineHelp = "Console-Command-List-Server-User")
public void listServerUsers() {
    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);
        message("\nSERVER USERS\n");
        final Set<OServerUserConfiguration> users = serverCfg.getUsers();
        if (users.isEmpty())
            message("\nNo users found");
        else
            for (OServerUserConfiguration u : users) {
                message("\n- '%s', permissions: %s", u.name, u.resources);
            }
    } catch (Exception e) {
        error("\nError on loading %s file: %s", serverCfgFile, e.toString());
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OServerUserConfiguration(com.orientechnologies.orient.server.config.OServerUserConfiguration) 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)

Example 3 with OServerConfigurationManager

use of com.orientechnologies.orient.server.config.OServerConfigurationManager 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)

Example 4 with OServerConfigurationManager

use of com.orientechnologies.orient.server.config.OServerConfigurationManager in project orientdb by orientechnologies.

the class HookInstallServerTest method before.

@Before
public void before() throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ClassNotFoundException, NullPointerException, IOException, IllegalArgumentException, SecurityException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
    server = new OServer();
    OServerConfigurationManager ret = new OServerConfigurationManager(this.getClass().getClassLoader().getResourceAsStream("com/orientechnologies/orient/server/network/orientdb-server-config.xml"));
    OServerHookConfiguration hc = new OServerHookConfiguration();
    hc.clazz = MyHook.class.getName();
    ret.getConfiguration().hooks = new ArrayList<OServerHookConfiguration>();
    ret.getConfiguration().hooks.add(hc);
    server.startup(ret.getConfiguration());
    server.activate();
    OServerAdmin admin = new OServerAdmin("remote:localhost");
    admin.connect("root", "D2AFD02F20640EC8B7A5140F34FCA49D2289DB1F0D0598BB9DE8AAA75A0792F3");
    admin.createDatabase("test", "nothign", "memory");
    admin.close();
}
Also used : OServerHookConfiguration(com.orientechnologies.orient.server.config.OServerHookConfiguration) OServerConfigurationManager(com.orientechnologies.orient.server.config.OServerConfigurationManager) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) Before(org.junit.Before)

Aggregations

OServerConfigurationManager (com.orientechnologies.orient.server.config.OServerConfigurationManager)4 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 OSystemException (com.orientechnologies.common.exception.OSystemException)3 OIOException (com.orientechnologies.common.io.OIOException)3 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)3 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)3 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)3 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)1 OServerHookConfiguration (com.orientechnologies.orient.server.config.OServerHookConfiguration)1 OServerUserConfiguration (com.orientechnologies.orient.server.config.OServerUserConfiguration)1 Before (org.junit.Before)1