nicomp
nicomp

Reputation: 4647

How to change initial password when programmatically creating a Neo4j DB in Java

I need to programmatically create a Neo4j DB and then change the initial password. Creating the DB works, but I don't know how to change the password.

        String graphDBFilePath = Config.getNeo4jFilesPath_Absolute() + "/" + schemaName;        // This is an absolute path. Do not let Neo4j see it.
        GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( new File(graphDBFilePath) ); // See http://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/GraphDatabaseService.html

        // This transaction works
        try (Transaction tx = graphDb.beginTx()) {
            Node myNode = graphDb.createNode();
            myNode.setProperty( "name", "my node");
            tx.success();
        }
         // This transaction throws an error
         Transaction tx = graphDb.beginTx();
         try {
             graphDb.execute("CALL dbms.changePassword(\'Spoon_XL\')");     // "Invalid attempt to change the password" error
             tx.success();
         } catch (Exception ex) {
                Log.logError("createNewGraphDB() Change Initial Password: " + ex.getLocalizedMessage());
         } finally {tx.close(); graphDb.shutdown();}

Upvotes: 0

Views: 160

Answers (1)

Tom Geudens
Tom Geudens

Reputation: 2656

This may be version dependent (and I don't know what version you are running), but I think the procedure is actually dbms.security.changePassword

Hope this helps, Tom

Upvotes: 1

Related Questions