sparkyspider
sparkyspider

Reputation: 13519

Spring-Data-Neo4J: How do log into the remote server?

I'm using Spring-Data-Neo4j 4.0.0.M1, and trying to connect to the server. I'm getting an exception:

Caused by: org.apache.http.client.HttpResponseException: Unauthorized

I have a password on the server interface, but I'm not sure how to tell Spring about it.

@Configuration
@EnableNeo4jRepositories(basePackages = "com.noxgroup.nitro.persistence")
@EnableTransactionManagement
public class MyConfiguration extends Neo4jConfiguration {

    @Bean
    public Neo4jServer neo4jServer () {
        /*** I was quite surprised not to see an overloaded parameter here ***/ 
        return new RemoteServer("http://localhost:7474");
    }

    @Bean
    public SessionFactory getSessionFactory() {
        return new SessionFactory("org.my.software.domain");
    }

    @Bean
    ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
        return new ApplicationListener<BeforeSaveEvent>() {
            @Override
            public void onApplicationEvent(BeforeSaveEvent event) {
                if (event.getEntity() instanceof User) {
                    User user = (User) event.getEntity();
                    user.encodePassword();
                }
            }
        };
    }
}

Side Note

4.0.0 Milestone 1 is absolutely fantastic. If anyone is using 3.x.x, I'd recommend checking it out!

Upvotes: 2

Views: 557

Answers (1)

Luanne
Luanne

Reputation: 19373

The username and password are passed currently via system properties

e.g.

-Drun.jvmArguments="-Dusername=<usr> -Dpassword=<pwd>"

or

 System.setProperty("username", "neo4j");
 System.setProperty("password", "password");

https://jira.spring.io/browse/DATAGRAPH-627 is open (not targeted for 4.0 RC1 though), please feel free to add comments/vote it up

Upvotes: 5

Related Questions