Commit 60f00894 authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2437] [Lua] Inclusão de operação na biblioteca de acesso para criar a...

[OPENBUS-2437] [Lua] Inclusão de operação na biblioteca de acesso para criar a cadeia resultante de uma chamada para um dado login válido.

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/02_00_00@157493 ae0415b3-e90b-0410-900d-d0be9363c56b
parent c9cb3779
......@@ -358,10 +358,11 @@ function Connection:resetCaches()
self.signedChainOf = memoize(function(chain) return LRUCache() end, "k")
end
local NullChain = {}
function Connection:signChainFor(target, chain)
if target == BusLogin then return chain end
local access = self.AccessControl
local cache = self.signedChainOf[chain]
local cache = self.signedChainOf[chain or NullChain]
local joined = cache:get(target)
while joined == nil do
joined = access:signChainFor(target)
......@@ -372,7 +373,7 @@ function Connection:signChainFor(target, chain)
minor = loginconst.NoLoginCode,
}
end
cache = self.signedChainOf[chain]
cache = self.signedChainOf[chain or NullChain]
if unmarshalChain(self, joined).caller.id == login.id then
cache:put(target, joined)
break
......@@ -589,8 +590,10 @@ function Context:__init()
self.connectionOf = setmetatable({}, WeakKeys) -- [thread]=connection
self.types.LoginAuthenticationInfo =
self.orb.types:lookup_id(logintypes.LoginAuthenticationInfo)
self.context = self -- to execute 'BaseInterceptor.unmarshalCredential(self)'
self.legacy = true -- to execute 'BaseInterceptor.unmarshalCredential(self)'
-- following necessary to execute 'BaseInterceptor.unmarshalCredential(self)'
self.context = self
self.legacy = true
self.unmarshalSignedChain = BaseInterceptor.unmarshalSignedChain
end
function Context:sendrequest(request)
......@@ -741,6 +744,18 @@ function Context:getOfferRegistry()
return getCoreFacet(conn, "OfferRegistry", "offer_registry")
end
function Context:makeChainFor(loginId)
local conn = self:getCurrentConnection()
if conn == nil or conn.login == nil then
sysexthrow.NO_PERMISSION{
completed = "COMPLETED_NO",
minor = loginconst.NoLoginCode,
}
end
local signed = conn:signChainFor(loginId, self:getJoinedChain())
return conn:unmarshalSignedChain(signed)
end
-- allow login operations to be performed without credentials
......
......@@ -227,6 +227,23 @@ function Interceptor:resetCaches()
}
end
function Interceptor:unmarshalSignedChain(chain)
local encoded = chain.encoded
if encoded ~= "" then
local context = self.context
local types = context.types
local orb = context.orb
local decoder = orb:newdecoder(chain.encoded)
local decoded = decoder:get(types.CallChain)
local originators = decoded.originators
originators.n = nil -- remove field 'n' created by OiL unmarshal
chain.originators = originators
chain.caller = decoded.caller
chain.target = decoded.target
return chain
end
end
function Interceptor:unmarshalCredential(contexts)
local context = self.context
local types = context.types
......@@ -234,19 +251,7 @@ function Interceptor:unmarshalCredential(contexts)
local data = contexts[CredentialContextId]
if data ~= nil then
local credential = orb:newdecoder(data):get(types.CredentialData)
local chain = credential.chain
local encoded = chain.encoded
if encoded == "" then
credential.chain = nil
else
local decoder = orb:newdecoder(encoded)
local decoded = decoder:get(types.CallChain)
local originators = decoded.originators
originators.n = nil -- remove field 'n' created by OiL unmarshal
chain.originators = originators
chain.caller = decoded.caller
chain.target = decoded.target
end
credential.chain = self:unmarshalSignedChain(credential.chain)
return credential
end
if self.legacy ~= nil then
......
local _G = require "_G"
local assert = _G.assert
local error = _G.error
local ipairs = _G.ipairs
local pairs = _G.pairs
local pcall = _G.pcall
local type = _G.type
local coroutine = require "coroutine"
local string = require "string"
local io = require "io"
local uuid = require "uuid"
local giop = require "oil.corba.giop"
local cothread = require "cothread"
local openbus = require "openbus"
local libidl = require "openbus.idl"
local idl = require "openbus.core.idl"
local msg = require "openbus.util.messages"
local log = require "openbus.util.logger"
local sysex = giop.SystemExceptionIDs
bushost, busport, verbose = ...
require "openbus.test.configs"
syskey = assert(openbus.readKeyFile(syskey))
local smalltime = .1
local connprops = { accesskey = openbus.newKey() }
local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
assert(OpenBusContext.orb == orb)
do log:TEST("Make chains for active logins")
local conn1 = OpenBusContext:createConnection(bushost, busport, connprops)
conn1:loginByPassword(user, password)
local conn2 = OpenBusContext:createConnection(bushost, busport, connprops)
conn2:loginByCertificate(system, syskey)
OpenBusContext:setDefaultConnection(conn1)
local chain1to2 = OpenBusContext:makeChainFor(conn2.login.id)
assert(chain1to2.target == conn2.login.entity)
assert(chain1to2.caller.id == conn1.login.id)
assert(chain1to2.caller.entity == conn1.login.entity)
assert(#chain1to2.originators == 0)
OpenBusContext:joinChain(chain1to2)
local ok, ex = pcall(OpenBusContext.makeChainFor, OpenBusContext, conn1.login.id)
assert(not ok)
assert(ex._repid == sysex.NO_PERMISSION)
assert(ex.completed == "COMPLETED_NO")
assert(ex.minor == idl.const.services.access_control.InvalidChainCode)
OpenBusContext:setDefaultConnection(conn2)
local chain1to2to1 = OpenBusContext:makeChainFor(conn1.login.id)
assert(chain1to2to1.target == conn1.login.entity)
assert(chain1to2to1.caller.id == conn2.login.id)
assert(chain1to2to1.caller.entity == conn2.login.entity)
assert(chain1to2to1.originators[1].id == conn1.login.id)
assert(chain1to2to1.originators[1].entity == conn1.login.entity)
OpenBusContext:exitChain()
OpenBusContext:setDefaultConnection(nil)
conn1:logout()
conn2:logout()
end
do log:TEST("Fail to make chain for invalid logins")
local conn = OpenBusContext:createConnection(bushost, busport, connprops)
conn:loginByPassword(user, password)
OpenBusContext:setDefaultConnection(conn)
local ok, ex = pcall(OpenBusContext.makeChainFor, OpenBusContext, "invalid login")
assert(not ok)
assert(ex._repid == idl.types.services.access_control.InvalidLogins)
assert(ex.loginIds[1] == "invalid login")
OpenBusContext:setDefaultConnection(nil)
conn:logout()
end
do log:TEST("Fail to make chain without login")
local ok, ex = pcall(OpenBusContext.makeChainFor, OpenBusContext, "invalid login")
assert(not ok)
assert(ex._repid == sysex.NO_PERMISSION)
assert(ex.completed == "COMPLETED_NO")
assert(ex.minor == idl.const.services.access_control.NoLoginCode)
local conn = OpenBusContext:createConnection(bushost, busport, connprops)
OpenBusContext:setDefaultConnection(conn)
local ok, ex = pcall(OpenBusContext.makeChainFor, OpenBusContext, "invalid login")
assert(not ok)
assert(ex._repid == sysex.NO_PERMISSION)
assert(ex.completed == "COMPLETED_NO")
assert(ex.minor == idl.const.services.access_control.NoLoginCode)
conn:loginByPassword(user, password)
conn:logout()
local ok, ex = pcall(OpenBusContext.makeChainFor, OpenBusContext, "invalid login")
assert(not ok)
assert(ex._repid == sysex.NO_PERMISSION)
assert(ex.completed == "COMPLETED_NO")
assert(ex.minor == idl.const.services.access_control.NoLoginCode)
OpenBusContext:setDefaultConnection(nil)
end
orb:shutdown()
......@@ -15,6 +15,7 @@ openbus/test/util/database \
openbus/test/LoginLogout \
openbus/test/Concurrency \
openbus/test/NoLoginIceptorCalls \
openbus/test/MakeChainFor \
openbus/test/assistant/LoginLogout \
openbus/test/assistant/Concurrency \
openbus/test/assistant/NoLoginIceptorCalls \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment