diff --git a/access.lua b/access.lua index 8ef415d..4636017 100644 --- a/access.lua +++ b/access.lua @@ -7,7 +7,7 @@ -- -- Get the `cache` persistent shared table -cache = ngx.shared.cache +local cache = ngx.shared.cache -- Generate a unique token if it has not been generated yet srvkey = cache:get("srvkey") @@ -17,14 +17,10 @@ if not srvkey then end -- Initialize and get configuration -config = require "config" -conf = config.get_config() - --- Initialize the non-persistent cookie table -cookies = {} +local conf = config.get_config() -- Import helpers -hlp = require "helpers" +local hlp = require "helpers" -- Just a note for the client to know that he passed through the SSO ngx.header["X-SSO-WAT"] = "You've just been SSOed" @@ -99,8 +95,7 @@ then -- current one, create a redirection with a CDA key if not string.match(back_url, "^http[s]?://"..ngx.var.host.."/") and not string.match(back_url, ".*"..conf.login_arg.."=%d+$") then - cda_key = random_string() - cache:set(cda_key, ngx.var.cookie_SSOwAuthUser, 10) + local cda_key = hlp.set_cda_key() if string.match(back_url, ".*?.*") then back_url = back_url.."&" else diff --git a/helpers.lua b/helpers.lua index 696af76..a663399 100644 --- a/helpers.lua +++ b/helpers.lua @@ -7,6 +7,11 @@ module('helpers', package.seeall) +local cache = ngx.shared.cache +local conf = config.get_config() +local cookies = {} + + -- Read a FS stored file function read_file(file) local f = io.open(file, "rb") @@ -80,6 +85,14 @@ function uri_args_string (args) end +-- Set the Cross-Domain-Authentication key for a specific user +function set_cda_key () + local cda_key = random_string() + cache:set(cda_key, ngx.var.cookie_SSOwAuthUser, 10) + return cda_key +end + + -- Compute and set the authentication cookie -- -- Sets 3 cookies containing: diff --git a/init.lua b/init.lua index cbbe0e5..24d0f9b 100644 --- a/init.lua +++ b/init.lua @@ -15,12 +15,13 @@ script_path = string.sub(debug.getinfo(1).source, 2, -9) package.path = package.path .. ";"..script_path.."?.lua" -- Load libraries -json = require "json" -lualdap = require "lualdap" -math = require "math" -hige = require "hige" -lfs = require "lfs" -socket = require "socket" +local json = require "json" +local lualdap = require "lualdap" +local math = require "math" +local hige = require "hige" +local lfs = require "lfs" +local socket = require "socket" +local config = require "config" -- Persistent shared table flashs = {}