neo4j-core 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-server.rb +0 -1
- data/lib/neo4j-server/cypher_session.rb +5 -8
- metadata +3 -4
- data/lib/neo4j-server/cypher_authentication.rb +0 -125
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc288b3293def30d9acf103f70ca43e2d1cfebc9
|
4
|
+
data.tar.gz: 73225366c230a39f0dff61dd9e6497229251c478
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a8ad456a8528cf852f3c8ca451c3853bcd264f182ddd2baf6361318ec8d04fb3a2351b5fd714cc9eba17be197cbc14119faa5021d973dfb2d18a3b7a1c5f054
|
7
|
+
data.tar.gz: 738ce2b663d3d5fb483ead05725c5bc1a624452bab4341cf3dd2987be0bfab131e4cd68b176c15a23cd148d6309ed253fc33dad51bc7cd22e77554bae2e549cd
|
data/lib/neo4j-core/version.rb
CHANGED
data/lib/neo4j-server.rb
CHANGED
@@ -4,7 +4,6 @@ require 'faraday_middleware'
|
|
4
4
|
require 'neo4j-server/resource'
|
5
5
|
require 'neo4j-server/cypher_node'
|
6
6
|
require 'neo4j-server/cypher_label'
|
7
|
-
require 'neo4j-server/cypher_authentication'
|
8
7
|
require 'neo4j-server/cypher_session'
|
9
8
|
require 'neo4j-server/cypher_node_uncommited'
|
10
9
|
require 'neo4j-server/cypher_relationship'
|
@@ -10,11 +10,10 @@ module Neo4j
|
|
10
10
|
include Neo4j::Core::CypherTranslator
|
11
11
|
|
12
12
|
alias_method :super_query, :query
|
13
|
-
attr_reader :connection
|
13
|
+
attr_reader :connection
|
14
14
|
|
15
|
-
def initialize(data_url, connection
|
15
|
+
def initialize(data_url, connection)
|
16
16
|
@connection = connection
|
17
|
-
@auth = auth_obj if auth_obj
|
18
17
|
Neo4j::Session.register(self)
|
19
18
|
initialize_resource(data_url)
|
20
19
|
Neo4j::Session._notify_listeners(:session_available, self)
|
@@ -47,17 +46,15 @@ module Neo4j
|
|
47
46
|
extract_basic_auth(endpoint_url, params)
|
48
47
|
connection = params[:connection] || create_connection(params)
|
49
48
|
url = endpoint_url || 'http://localhost:7474'
|
50
|
-
auth_obj = CypherAuthentication.new(url, connection, params)
|
51
|
-
auth_obj.authenticate
|
52
49
|
response = connection.get(url)
|
53
50
|
fail "Server not available on #{url} (response code #{response.status})" unless response.status == 200
|
54
|
-
establish_session(response.body, connection
|
51
|
+
establish_session(response.body, connection)
|
55
52
|
end
|
56
53
|
|
57
|
-
def self.establish_session(root_data, connection
|
54
|
+
def self.establish_session(root_data, connection)
|
58
55
|
data_url = root_data['data']
|
59
56
|
data_url << '/' unless data_url.nil? || data_url.end_with?('/')
|
60
|
-
CypherSession.new(data_url, connection
|
57
|
+
CypherSession.new(data_url, connection)
|
61
58
|
end
|
62
59
|
|
63
60
|
def self.extract_basic_auth(url, params)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4j-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Ronge, Chris Grigg, Brian Underwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -240,7 +240,6 @@ files:
|
|
240
240
|
- lib/neo4j-embedded/property.rb
|
241
241
|
- lib/neo4j-embedded/to_java.rb
|
242
242
|
- lib/neo4j-server.rb
|
243
|
-
- lib/neo4j-server/cypher_authentication.rb
|
244
243
|
- lib/neo4j-server/cypher_label.rb
|
245
244
|
- lib/neo4j-server/cypher_node.rb
|
246
245
|
- lib/neo4j-server/cypher_node_uncommited.rb
|
@@ -287,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
286
|
version: '0'
|
288
287
|
requirements: []
|
289
288
|
rubyforge_project:
|
290
|
-
rubygems_version: 2.4.
|
289
|
+
rubygems_version: 2.4.5
|
291
290
|
signing_key:
|
292
291
|
specification_version: 4
|
293
292
|
summary: A basic library to work with the graph database Neo4j.
|
@@ -1,125 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module Server
|
3
|
-
# Neo4j 2.2 has an authentication layer. This class provides methods for interacting with it.
|
4
|
-
class CypherAuthentication
|
5
|
-
class InvalidPasswordError < RuntimeError; end
|
6
|
-
class PasswordChangeRequiredError < RuntimeError; end
|
7
|
-
class MissingCredentialsError < RuntimeError; end
|
8
|
-
|
9
|
-
attr_reader :connection, :url, :params, :token
|
10
|
-
|
11
|
-
# @param [String] url_string The server address with protocol and port.
|
12
|
-
# @param [Faraday::Connection] session_connection A Faraday::Connection object. This is either an existing object, likely the
|
13
|
-
# same object used by the server for data, or a new one created specifically for auth tasks.
|
14
|
-
# @param [Hash] params_hash Faraday connection options. In particularly, we're looking for basic_auth creds.
|
15
|
-
def initialize(url_string, session_connection = new_connection, params_hash = {})
|
16
|
-
@url = url_string
|
17
|
-
@connection = session_connection
|
18
|
-
@params = params_hash
|
19
|
-
end
|
20
|
-
|
21
|
-
# Set the username and password used to communicate with the server.
|
22
|
-
def basic_auth(username, password)
|
23
|
-
params[:basic_auth] ||= {}
|
24
|
-
params[:basic_auth][:username] = username
|
25
|
-
params[:basic_auth][:password] = password
|
26
|
-
end
|
27
|
-
|
28
|
-
# POSTs to the password change endpoint of the API. Does not invalidate tokens.
|
29
|
-
# @param [String] old_password The current password.
|
30
|
-
# @param [String] new_password The password you want to use.
|
31
|
-
# @return [Hash] The response from the server.
|
32
|
-
def change_password(old_password, new_password)
|
33
|
-
connection.post("#{url}/user/neo4j/password", 'password' => old_password, 'new_password' => new_password).body
|
34
|
-
end
|
35
|
-
|
36
|
-
# Uses the given username and password to obtain a token, then adds the token to the connection's parameters.
|
37
|
-
# @return [String] An access token provided by the server.
|
38
|
-
def authenticate
|
39
|
-
auth_response = auth_connection("#{url}/authentication")
|
40
|
-
auth_hash = if auth_response.status == 404 || auth_response.body.empty?
|
41
|
-
nil
|
42
|
-
elsif auth_response.body.is_a?(String)
|
43
|
-
JSON.parse(auth_response.body)['errors'][0]['code'] == 'Neo.ClientError.Security.AuthorizationFailed' ? auth_attempt : nil
|
44
|
-
else
|
45
|
-
auth_response
|
46
|
-
end
|
47
|
-
return nil if auth_hash.nil?
|
48
|
-
add_auth_headers(token_or_error(auth_hash))
|
49
|
-
end
|
50
|
-
|
51
|
-
# Invalidates the existing token, which will invalidate all conncetions using this token, applies for a new token, adds this into
|
52
|
-
# the connection headers.
|
53
|
-
# @param [String] password The current server password.
|
54
|
-
def reauthenticate(password)
|
55
|
-
invalidate_token(password)
|
56
|
-
add_auth_headers(token_or_error(auth_attempt))
|
57
|
-
end
|
58
|
-
|
59
|
-
# Requests a token from the authentication endpoint using the given username and password.
|
60
|
-
# @return [Faraday::Response] The server's response, to be interpreted.
|
61
|
-
def auth_attempt
|
62
|
-
begin
|
63
|
-
user = params[:basic_auth][:username]
|
64
|
-
pass = params[:basic_auth][:password]
|
65
|
-
rescue NoMethodError
|
66
|
-
raise MissingCredentialsError, 'Neo4j authentication is enabled, username/password are required but missing'
|
67
|
-
end
|
68
|
-
connection.post("#{url}/authentication", 'username' => user, 'password' => pass)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Takes a response object from the server and returns a token or fails with an error.
|
72
|
-
# TODO: more error states!
|
73
|
-
# @param [Farday::Response] auth_response The response after attempting authentication
|
74
|
-
# @return [String] An authentication token.
|
75
|
-
def token_or_error(auth_response)
|
76
|
-
begin
|
77
|
-
fail PasswordChangeRequiredError, "Server requires a password change, please visit #{url}" if auth_response.body['password_change_required']
|
78
|
-
fail InvalidPasswordError, "Neo4j server responded with: #{auth_response.body['errors'][0]['message']}" if auth_response.status.to_i == 422
|
79
|
-
rescue NoMethodError
|
80
|
-
raise 'Unexpected auth response, please open an issue at https://github.com/neo4jrb/neo4j-core/issues'
|
81
|
-
end
|
82
|
-
auth_response.body['authorization_token']
|
83
|
-
end
|
84
|
-
|
85
|
-
# Invalidates tokens as described at http://neo4j.com/docs/snapshot/rest-api-security.html#rest-api-invalidating-the-authorization-token
|
86
|
-
# @param [String] current_password The current password used to connect to the database
|
87
|
-
def invalidate_token(current_password)
|
88
|
-
connection.post("#{url}/user/neo4j/authorization_token", 'password' => current_password).body
|
89
|
-
end
|
90
|
-
|
91
|
-
# Stores an authentication token in the properly-formatted header.
|
92
|
-
# This does not do any checking that what it has been given is a token. Whatever param is given will be base64 encoded and used as the header.
|
93
|
-
# @param [String] token The authentication token provided by the database.
|
94
|
-
def add_auth_headers(token)
|
95
|
-
@token = token
|
96
|
-
connection.headers['Authorization'] = "Basic realm=\"Neo4j\" #{token_hash(token)}"
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
|
101
|
-
# Makes testing easier, we can stub this method to simulate different responses
|
102
|
-
def auth_connection(url)
|
103
|
-
connection.get(url)
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.new_connection
|
107
|
-
conn = Faraday.new do |b|
|
108
|
-
b.request :json
|
109
|
-
b.response :json, content_type: 'application/json'
|
110
|
-
b.use Faraday::Adapter::NetHttpPersistent
|
111
|
-
end
|
112
|
-
conn.headers = {'Content-Type' => 'application/json'}
|
113
|
-
conn
|
114
|
-
end
|
115
|
-
|
116
|
-
def new_connection
|
117
|
-
self.class.new_connection
|
118
|
-
end
|
119
|
-
|
120
|
-
def token_hash(token)
|
121
|
-
::Base64.strict_encode64(":#{token}")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|