util/sasl.lua

changeset 3427
046a8cf304dd
parent 3373
cd6836586a6a
child 3441
d4f89802cf1e
equal deleted inserted replaced
3426:37b9b8e171b9 3427:046a8cf304dd
59 t_insert(backend_mechanism[backend_name], name); 59 t_insert(backend_mechanism[backend_name], name);
60 end 60 end
61 end 61 end
62 62
63 -- create a new SASL object which can be used to authenticate clients 63 -- create a new SASL object which can be used to authenticate clients
64 function new(realm, profile, forbidden) 64 function new(realm, profile)
65 local sasl_i = {profile = profile}; 65 local sasl_i = {profile = profile};
66 sasl_i.realm = realm; 66 sasl_i.realm = realm;
67 local s = setmetatable(sasl_i, method); 67 return setmetatable(sasl_i, method);
68 if forbidden == nil then forbidden = {} end
69 s:forbidden(forbidden)
70 return s;
71 end 68 end
72 69
73 -- get a fresh clone with the same realm, profiles and forbidden mechanisms 70 -- get a fresh clone with the same realm and profile
74 function method:clean_clone() 71 function method:clean_clone()
75 return new(self.realm, self.profile, self:forbidden()) 72 return new(self.realm, self.profile)
76 end
77
78 -- set the forbidden mechanisms
79 function method:forbidden( restrict )
80 if restrict then
81 -- set forbidden
82 self.restrict = set.new(restrict);
83 else
84 -- get forbidden
85 return array.collect(self.restrict:items());
86 end
87 end 73 end
88 74
89 -- get a list of possible SASL mechanims to use 75 -- get a list of possible SASL mechanims to use
90 function method:mechanisms() 76 function method:mechanisms()
91 local mechanisms = self.mechs; 77 local mechanisms = self.mechs;
92 if not mechanisms then 78 if not mechanisms then
93 mechanisms = {} 79 mechanisms = {}
94 for backend, f in pairs(self.profile) do 80 for backend, f in pairs(self.profile) do
95 if backend_mechanism[backend] then 81 if backend_mechanism[backend] then
96 for _, mechanism in ipairs(backend_mechanism[backend]) do 82 for _, mechanism in ipairs(backend_mechanism[backend]) do
97 if not self.restrict:contains(mechanism) then 83 mechanisms[mechanism] = true;
98 mechanisms[mechanism] = true;
99 end
100 end 84 end
101 end 85 end
102 end 86 end
103 self.mechs = mechanisms; 87 self.mechs = mechanisms;
104 end 88 end

mercurial