Skip to content

Commit

Permalink
Merge pull request #335 from pe4cey/logs
Browse files Browse the repository at this point in the history
Avoid multiple 'logged in' logs in security log when using Bolt
  • Loading branch information
oskarhane committed Nov 22, 2016
2 parents af720f3 + 6848cdb commit fd0a927
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 80 deletions.
7 changes: 1 addition & 6 deletions app/scripts/init/statusCheck.coffee
Expand Up @@ -29,12 +29,7 @@ angular.module('neo4jApp').run([
timer = null
$scope.check = ->
$timeout.cancel(timer)
# There is something wrong with the XHR implementation in IE10:
# It will return 304 (not modified) even if the server goes down as long as
# the URL is the same. So we need a unique URL every time in order for it
# to detect request error
ts = (new Date()).getTime()
Server.addresses('?t='+ts).success(
Server.addresses().success(
(r) ->
$scope.offline = no
timer = $timeout($scope.check, Settings.heartbeat * 1000)
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/services/Auth.coffee
Expand Up @@ -41,7 +41,7 @@ angular.module('neo4jApp.services')
that = @
@current_password = password
setConnectionAuthData username, password
promise = @makeRequest(withoutCredentials = no, retainConnection = yes)
promise = @makeRequest(withoutCredentials = no)
promise.then(
(r) ->
ConnectionStatusService.setConnected yes
Expand All @@ -56,7 +56,7 @@ angular.module('neo4jApp.services')
authorizationRequired: ->
#Make call without auth headers
q = $q.defer()
p = @makeRequest(withoutCredentials = yes, retainConnection = yes)
p = @makeRequest(withoutCredentials = yes)
p.then(
(r) ->
##Success, no auth required
Expand Down Expand Up @@ -104,7 +104,7 @@ angular.module('neo4jApp.services')
isConnected: (retainConnection = no) ->
that = @
q = $q.defer()
p = @makeRequest(withoutCredentials = no, retainConnection)
p = @makeRequest(withoutCredentials = no)
p.then(
(rr) ->
ConnectionStatusService.setConnected yes
Expand All @@ -117,8 +117,8 @@ angular.module('neo4jApp.services')
)
q.promise

makeRequest: (withoutCredentials = no, retainConnection = no) ->
ProtocolFactory.utils().makeRequest(withoutCredentials, retainConnection)
makeRequest: (withoutCredentials = no) ->
ProtocolFactory.utils().makeRequest(withoutCredentials)

forget: ->
if @getCurrentUser()
Expand Down
91 changes: 30 additions & 61 deletions app/scripts/services/Bolt.coffee
Expand Up @@ -105,28 +105,33 @@ angular.module('neo4jApp.services')
drivers


testConnection = (withoutCredentials = no, driver = null) ->
testConnection = (withoutCredentials = no) ->
q = $q.defer()
driver = driver || getDriverObj(withoutCredentials).getDirectDriver()
driver.onError = (e) ->
driver.close()
if e instanceof Event and e.type is 'error'
q.reject getSocketErrorObj()
else if e.code and e.message # until Neo4jError is in drivers public API
q.reject buildErrorObj(e.code, e.message)
else if e.fields && e.fields[0]
q.reject e
driver.onCompleted = (m) ->
driver.close()
q.resolve m
driver.session()
unless _driversObj
driversObj = getDriverObj(withoutCredentials)
driver = driversObj.getDirectDriver()
driver.onError = (e) ->
driversObj.close()
_driversObj = null
if e instanceof Event and e.type is 'error'
q.reject getSocketErrorObj()
else if e.code and e.message # until Neo4jError is in drivers public API
q.reject buildErrorObj(e.code, e.message)
else if e.fields && e.fields[0]
q.reject e
driver.onCompleted = (m) ->
_driversObj = driversObj
session.close()
q.resolve m
session = driver.session()
else
q.resolve {}
q.promise

connect = (withoutCredentials = no) ->
clearConnection()
q = $q.defer()
testConnection(withoutCredentials).then((r) ->
_driversObj = getDriverObj withoutCredentials
q.resolve r
,(e) -> q.reject e
)
Expand All @@ -136,20 +141,6 @@ angular.module('neo4jApp.services')
_driversObj.close() if _driversObj?
_driversObj = null

beginTransaction = (opts) ->
q = $q.defer()
statement = opts[0]?.statement || ''
parameters = opts[0]?.parameters || {}
session = _driversObj.getRoutedDriver.session(bolt.session.WRITE)
if not session
tx = null
q.reject getSocketErrorObj()
else
tx = session.beginTransaction()
q.resolve() unless statement
tx.run(statement, parameters).then((r)-> q.resolve(r)).catch((e)-> q.reject(e)) if statement
return {tx: tx, session: session, promise: q.promise}

transaction = (opts, session, tx) ->
statement = opts[0]?.statement || ''
parameters = opts[0]?.parameters || {}
Expand All @@ -158,37 +149,16 @@ angular.module('neo4jApp.services')
$rootScope.check()
q.reject getSocketErrorObj()
else
if tx
# We need to look for error messages from
# the commit() call even though run()
# reported a successful operation
p = tx.run statement, parameters
p.then((r) ->
if tx # The tx might have been terminated
tx.commit().then((txr) ->
session.close()
q.resolve r
).catch((txe) ->
checkConnectionError(txe)
q.reject txe
)
else
session.close()
q.resolve r
).catch((e) ->
checkConnectionError(txe)
q.reject e
)
else
p = session.run statement, parameters
p.then((r) ->
session.close()
q.resolve r
).catch((e) ->
checkConnectionError(e)
q.reject e
)
{tx: tx, promise: q.promise, session: session}
p = session.run statement, parameters
p.then((r) ->
session.close()
q.resolve r
).catch((e) ->
session.close()
checkConnectionError(e)
q.reject e
)
{ promise: q.promise, session: session}

routedWriteTransaction = (query, parameters = {}) ->
statements = if query then [{statement: query, parameters: parameters}] else []
Expand Down Expand Up @@ -461,7 +431,6 @@ angular.module('neo4jApp.services')
runQueryOnCluster: runQueryOnCluster,
testConnection: testConnection,
connect: connect,
beginTransaction: beginTransaction,
transaction: transaction,
boltTransaction: routedWriteTransaction,
routedWriteTransaction: routedWriteTransaction,
Expand Down
5 changes: 1 addition & 4 deletions app/scripts/services/CypherTransactionBolt.coffee
Expand Up @@ -70,7 +70,6 @@ angular.module('neo4jApp.services')
@requests = []
delegate = null
@session = null
@tx = null

_requestDone: (promise) ->
that = @
Expand All @@ -86,7 +85,6 @@ angular.module('neo4jApp.services')
_onError: () ->

_reset: ->
@tx = null
@session = null

begin: () ->
Expand All @@ -104,8 +102,7 @@ angular.module('neo4jApp.services')
params = Utils.findNumberInVal params, [transformFn]
UDC.increment('cypher_attempts')
q = $q.defer()
{tx, promise, session} = Bolt.routedWriteTransaction(query, params)
@tx = tx
{ promise, session } = Bolt.routedWriteTransaction(query, params)
@session = session
promise.then((r) ->
$rootScope.bolt_connection_failure = no
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/services/Server.coffee
Expand Up @@ -164,7 +164,7 @@ angular.module('neo4jApp.services')
status: (params = '')->
# User a smaller timeout for status requests so IE10 detects when the
# server goes down faster.
@options "#{Settings.endpoint.rest}/", { timeout: (Settings.heartbeat * 1000)}
@get "#{Settings.endpoint.discover}/", { skipAuthHeader: yes, timeout: (Settings.heartbeat * 1000)}

log: (path) ->
@get(path).then((r)-> console.log (r))
Expand Down
5 changes: 2 additions & 3 deletions app/scripts/services/UtilityBolt.coffee
Expand Up @@ -172,19 +172,18 @@ angular.module('neo4jApp.services')
.catch((e) -> q.reject Bolt.constructResult e)
q.promise

makeRequest: (withoutCredentials, retainConnection) ->
makeRequest: (withoutCredentials) ->
q = $q.defer()
r = Bolt.testConnection withoutCredentials
r.then((r) ->
Bolt.connect() if retainConnection
if (r.credentials_expired)
errObj = {data: {}}
errObj.data.password_change = 'true'
errObj.status = 403
q.reject errObj
else
$rootScope.bolt_connection_failure = no
return q.resolve({})
q.resolve({})
,(err) ->
errObj = Bolt.constructResult err
if errObj.data.errors[0].code is 'Socket.Error' || errObj.data.errors[0].message.indexOf('WebSocket connection failure') == 0
Expand Down

0 comments on commit fd0a927

Please sign in to comment.