use of com.orientechnologies.common.console.ODefaultConsoleReader in project orientdb by orientechnologies.
the class OServer method createDefaultServerUsers.
protected void createDefaultServerUsers() throws IOException {
if (serverSecurity != null && !serverSecurity.arePasswordsStored())
return;
// ORIENTDB_ROOT_PASSWORD ENV OR JVM SETTING
String rootPassword = OSystemVariableResolver.resolveVariable(ROOT_PASSWORD_VAR);
if (rootPassword != null) {
rootPassword = rootPassword.trim();
if (rootPassword.isEmpty())
rootPassword = null;
}
if (rootPassword == null && !serverCfg.existsUser(OServerConfiguration.DEFAULT_ROOT_USER)) {
try {
// WAIT ANY LOG IS PRINTED
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println();
System.out.println();
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | WARNING: FIRST RUN CONFIGURATION |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | This is the first time the server is running. Please type a |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | password of your choice for the 'root' user or leave it blank |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | to auto-generate it. |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | To avoid this message set the environment variable or JVM |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | setting ORIENTDB_ROOT_PASSWORD to the root password to use. |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
final OConsoleReader console = new ODefaultConsoleReader();
// ASK FOR PASSWORD + CONFIRM
do {
System.out.print(OAnsiCode.format("\n$ANSI{yellow Root password [BLANK=auto generate it]: }"));
rootPassword = console.readPassword();
if (rootPassword != null) {
rootPassword = rootPassword.trim();
if (rootPassword.isEmpty())
rootPassword = null;
}
if (rootPassword != null) {
System.out.print(OAnsiCode.format("$ANSI{yellow Please confirm the root password: }"));
String rootConfirmPassword = console.readPassword();
if (rootConfirmPassword != null) {
rootConfirmPassword = rootConfirmPassword.trim();
if (rootConfirmPassword.isEmpty())
rootConfirmPassword = null;
}
if (!rootPassword.equals(rootConfirmPassword)) {
System.out.println(OAnsiCode.format("$ANSI{red ERROR: Passwords don't match, please reinsert both of them, or press ENTER to auto generate it}"));
} else
// PASSWORDS MATCH
break;
}
} while (rootPassword != null);
} else
OLogManager.instance().info(this, "Found ORIENTDB_ROOT_PASSWORD variable, using this value as root's password", rootPassword);
if (!serverCfg.existsUser(OServerConfiguration.DEFAULT_ROOT_USER)) {
addUser(OServerConfiguration.DEFAULT_ROOT_USER, rootPassword, "*");
}
if (!serverCfg.existsUser(OServerConfiguration.GUEST_USER)) {
addUser(OServerConfiguration.GUEST_USER, OServerConfiguration.GUEST_PASS, "connect,server.listDatabases,server.dblist");
}
}
use of com.orientechnologies.common.console.ODefaultConsoleReader in project orientdb by orientechnologies.
the class ODistributedAbstractPlugin method assignNodeName.
protected void assignNodeName() {
// ORIENTDB_NODE_NAME ENV VARIABLE OR JVM SETTING
nodeName = OSystemVariableResolver.resolveVariable(NODE_NAME_ENV);
if (nodeName != null) {
nodeName = nodeName.trim();
if (nodeName.isEmpty())
nodeName = null;
}
if (nodeName == null) {
try {
// WAIT ANY LOG IS PRINTED
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println();
System.out.println();
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | WARNING: FIRST DISTRIBUTED RUN CONFIGURATION |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | This is the first time that the server is running as |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | distributed. Please type the name you want to assign to the |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | current server node. |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | To avoid this message set the environment variable or JVM |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | setting ORIENTDB_NODE_NAME to the server node name to use. |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.print(OAnsiCode.format("\n$ANSI{yellow Node name [BLANK=auto generate it]: }"));
OConsoleReader reader = new ODefaultConsoleReader();
try {
nodeName = reader.readLine();
} catch (IOException e) {
}
if (nodeName != null) {
nodeName = nodeName.trim();
if (nodeName.isEmpty())
nodeName = null;
}
}
if (nodeName == null)
// GENERATE NODE NAME
this.nodeName = "node" + System.currentTimeMillis();
OLogManager.instance().warn(this, "Assigning distributed node name: %s", this.nodeName);
// SALVE THE NODE NAME IN CONFIGURATION
boolean found = false;
final OServerConfiguration cfg = serverInstance.getConfiguration();
for (OServerHandlerConfiguration h : cfg.handlers) {
if (h.clazz.equals(getClass().getName())) {
for (OServerParameterConfiguration p : h.parameters) {
if (p.name.equals("nodeName")) {
found = true;
p.value = this.nodeName;
break;
}
}
if (!found) {
h.parameters = OArrays.copyOf(h.parameters, h.parameters.length + 1);
h.parameters[h.parameters.length - 1] = new OServerParameterConfiguration("nodeName", this.nodeName);
}
try {
serverInstance.saveConfiguration();
} catch (IOException e) {
throw OException.wrapException(new OConfigurationException("Cannot save server configuration"), e);
}
break;
}
}
}
use of com.orientechnologies.common.console.ODefaultConsoleReader in project orientdb by orientechnologies.
the class OServer method askForEncryptionKey.
private boolean askForEncryptionKey(final String iDatabaseName) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
System.out.println();
System.out.println();
System.out.println(OAnsiCode.format("$ANSI{yellow +--------------------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format(String.format("$ANSI{yellow | INSERT THE KEY FOR THE ENCRYPTED DATABASE %-31s|}", "'" + iDatabaseName + "'")));
System.out.println(OAnsiCode.format("$ANSI{yellow +--------------------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | To avoid this message set the environment variable or JVM setting |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | 'storage.encryptionKey' to the key to use. |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow +--------------------------------------------------------------------------+}"));
System.out.print(OAnsiCode.format("\n$ANSI{yellow Database encryption key [BLANK=to skip opening]: }"));
final OConsoleReader reader = new ODefaultConsoleReader();
try {
String key = reader.readPassword();
if (key != null) {
key = key.trim();
if (!key.isEmpty()) {
OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.setValue(key);
return true;
}
}
} catch (IOException e) {
}
return false;
}
Aggregations