[fix] Load libraries locally to avoid caching

This commit is contained in:
kload 2015-05-16 09:42:26 +02:00
parent 71e9ff1f68
commit 0ebddc079a
3 changed files with 24 additions and 15 deletions

View file

@ -7,7 +7,7 @@
-- --
-- Get the `cache` persistent shared table -- 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 -- Generate a unique token if it has not been generated yet
srvkey = cache:get("srvkey") srvkey = cache:get("srvkey")
@ -17,14 +17,10 @@ if not srvkey then
end end
-- Initialize and get configuration -- Initialize and get configuration
config = require "config" local conf = config.get_config()
conf = config.get_config()
-- Initialize the non-persistent cookie table
cookies = {}
-- Import helpers -- Import helpers
hlp = require "helpers" local hlp = require "helpers"
-- Just a note for the client to know that he passed through the SSO -- Just a note for the client to know that he passed through the SSO
ngx.header["X-SSO-WAT"] = "You've just been SSOed" ngx.header["X-SSO-WAT"] = "You've just been SSOed"
@ -99,8 +95,7 @@ then
-- current one, create a redirection with a CDA key -- current one, create a redirection with a CDA key
if not string.match(back_url, "^http[s]?://"..ngx.var.host.."/") if not string.match(back_url, "^http[s]?://"..ngx.var.host.."/")
and not string.match(back_url, ".*"..conf.login_arg.."=%d+$") then and not string.match(back_url, ".*"..conf.login_arg.."=%d+$") then
cda_key = random_string() local cda_key = hlp.set_cda_key()
cache:set(cda_key, ngx.var.cookie_SSOwAuthUser, 10)
if string.match(back_url, ".*?.*") then if string.match(back_url, ".*?.*") then
back_url = back_url.."&" back_url = back_url.."&"
else else

View file

@ -7,6 +7,11 @@
module('helpers', package.seeall) module('helpers', package.seeall)
local cache = ngx.shared.cache
local conf = config.get_config()
local cookies = {}
-- Read a FS stored file -- Read a FS stored file
function read_file(file) function read_file(file)
local f = io.open(file, "rb") local f = io.open(file, "rb")
@ -80,6 +85,14 @@ function uri_args_string (args)
end 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 -- Compute and set the authentication cookie
-- --
-- Sets 3 cookies containing: -- Sets 3 cookies containing:

View file

@ -15,12 +15,13 @@ script_path = string.sub(debug.getinfo(1).source, 2, -9)
package.path = package.path .. ";"..script_path.."?.lua" package.path = package.path .. ";"..script_path.."?.lua"
-- Load libraries -- Load libraries
json = require "json" local json = require "json"
lualdap = require "lualdap" local lualdap = require "lualdap"
math = require "math" local math = require "math"
hige = require "hige" local hige = require "hige"
lfs = require "lfs" local lfs = require "lfs"
socket = require "socket" local socket = require "socket"
local config = require "config"
-- Persistent shared table -- Persistent shared table
flashs = {} flashs = {}