将身份验证令牌添加到 Spring 数据 Neo4j Rest
Adding Authentication Token to Spring Data Neo4j Rest
如何将 Neo4j Server 创建的身份验证令牌添加到 Spring Neo4j Rest 配置
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="spring-data-context.xml" />
<bean id="graphDatabaseService"
class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg index="0" value="http://localhost:7474/db/data" />
</bean>
</beans>
已结束使用 Jersey 客户端的 HttpBasicAuthFilter
你的参数应该是这样的:
public static final String DATABASE_ENDPOINT = "http://localhost:7474/db/data";
public static final String DATABASE_USERNAME = "neo4j";
public static final String DATABASE_PASSWORD = "3c0a0a6ea1sdsdsdsdsdsdsdsdf2a94d";
private String callRest(String query) {
final String cypherUrl = ENDPOINT + "/cypher";
Client c = Client.create();
c.addFilter(new HTTPBasicAuthFilter(USERNAME, PASSWORD));
WebResource resource = c.resource(cypherUrl);
String request = "{\"query\":\"" + query + "\"}";
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON).entity(request)
.post(ClientResponse.class);
String object = response.getEntity(String.class);
response.close();
return object;
}
最新的 Jersey 客户端可以通过将其添加到您的 mvn pom 中找到,如果它不在您的依赖关系树中。
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.3</version>
</dependency>
根据 SpringRestGraphDatabase class,还有两个参数可以传递给构造函数,即用户名和密码。
以下是您应该如何配置它。
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data"/>
<constructor-arg name="user" value="neo4j"/>
<constructor-arg name="password" value="******"/>
</bean>
如何将 Neo4j Server 创建的身份验证令牌添加到 Spring Neo4j Rest 配置
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="spring-data-context.xml" />
<bean id="graphDatabaseService"
class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg index="0" value="http://localhost:7474/db/data" />
</bean>
</beans>
已结束使用 Jersey 客户端的 HttpBasicAuthFilter
你的参数应该是这样的:
public static final String DATABASE_ENDPOINT = "http://localhost:7474/db/data";
public static final String DATABASE_USERNAME = "neo4j";
public static final String DATABASE_PASSWORD = "3c0a0a6ea1sdsdsdsdsdsdsdsdf2a94d";
private String callRest(String query) {
final String cypherUrl = ENDPOINT + "/cypher";
Client c = Client.create();
c.addFilter(new HTTPBasicAuthFilter(USERNAME, PASSWORD));
WebResource resource = c.resource(cypherUrl);
String request = "{\"query\":\"" + query + "\"}";
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON).entity(request)
.post(ClientResponse.class);
String object = response.getEntity(String.class);
response.close();
return object;
}
最新的 Jersey 客户端可以通过将其添加到您的 mvn pom 中找到,如果它不在您的依赖关系树中。
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.3</version>
</dependency>
根据 SpringRestGraphDatabase class,还有两个参数可以传递给构造函数,即用户名和密码。 以下是您应该如何配置它。
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data"/>
<constructor-arg name="user" value="neo4j"/>
<constructor-arg name="password" value="******"/>
</bean>