@Override public void error(final String message, final Object... args) { // clean up error messages to remove redundant/irrelevant content if (!message.contains("Unrecognized command")) { super.error(message.replaceFirst("(?s)!Wrong syntax.*Expected", "Syntax"), args); } } }
@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()); } }
@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()); } }
@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()); } }