Search in sources :

Example 1 with ODefaultConsoleReader

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");
    }
}
Also used : OConsoleReader(com.orientechnologies.common.console.OConsoleReader) ODefaultConsoleReader(com.orientechnologies.common.console.ODefaultConsoleReader)

Example 2 with ODefaultConsoleReader

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;
        }
    }
}
Also used : OServerConfiguration(com.orientechnologies.orient.server.config.OServerConfiguration) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OConsoleReader(com.orientechnologies.common.console.OConsoleReader) ODefaultConsoleReader(com.orientechnologies.common.console.ODefaultConsoleReader) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) OServerHandlerConfiguration(com.orientechnologies.orient.server.config.OServerHandlerConfiguration) OIOException(com.orientechnologies.common.io.OIOException)

Example 3 with ODefaultConsoleReader

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;
}
Also used : OConsoleReader(com.orientechnologies.common.console.OConsoleReader) ODefaultConsoleReader(com.orientechnologies.common.console.ODefaultConsoleReader) IOException(java.io.IOException)

Aggregations

OConsoleReader (com.orientechnologies.common.console.OConsoleReader)3 ODefaultConsoleReader (com.orientechnologies.common.console.ODefaultConsoleReader)3 OIOException (com.orientechnologies.common.io.OIOException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 OServerConfiguration (com.orientechnologies.orient.server.config.OServerConfiguration)1 OServerHandlerConfiguration (com.orientechnologies.orient.server.config.OServerHandlerConfiguration)1 OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)1 IOException (java.io.IOException)1