1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 serializable keycards used for authentication
24 """
25
26 from twisted.cred.credentials import ICredentials
27 from twisted.spread import pb
28 from zope.interface import implements
29
30 from flumotion.twisted import credentials
31
32 __version__ = "$Rev: 7640 $"
33 _statesEnum = ['REFUSED', 'REQUESTING', 'AUTHENTICATED']
34
35 (REFUSED,
36 REQUESTING,
37 AUTHENTICATED) = range(3)
38
39
40 -class Keycard(pb.Copyable, pb.RemoteCopy):
41 """
42 I am the base class for keycards which together with credentials are
43 a serializable object used in authentication inside Flumotion.
44
45 @ivar bouncerName: name of the bouncer to authenticate against; set by
46 requester
47 @type bouncerName: str
48 @ivar requesterId: avatarId of the requester
49 @type requesterId: str
50 @ivar avatarId: avatarId preferred by requester
51 @type avatarId: str
52 @ivar id: id of keycard decided by bouncer after authenticating
53 @type id: object
54 @ivar duration: duration for which the keycard is valid, or 0 for
55 unlimited
56 @type duration: int
57 @ivar domain: requester can pass a domain id to the bouncer
58 @type domain: str
59 @ivar state: state the keycard is in
60 @type state: int
61 """
62 implements(ICredentials)
63
72
73
74
75 - def setDomain(self, domain):
76 """
77 Set the domain of the requester on the keycard.
78
79 @type domain: string
80 """
81 import warnings
82 warnings.warn('Set the domain on the keycard directly.',
83 DeprecationWarning, stacklevel=2)
84
85 self.domain = domain
86
88 """
89 Return a dictionary of the viewable data on the keycard that can be
90 used to identify the keycard.
91 It doesn't include sensitive information though.
92
93 Subclasses should override to add additional information.
94 """
95 return {'id': self.id,
96 'requester': self.requesterId,
97 'domain': self.domain}
98
100 return "<%s for requesterId %r in state %s>" % (
101 self.__class__.__name__,
102 self.requesterId, _statesEnum[self.state])
103
104
107
108 pb.setUnjellyableForClass(KeycardGeneric, KeycardGeneric)
109
110
111
112
113 UCPP = credentials.UsernameCryptPasswordPlaintext
114
115
117 """
118 I am a keycard with a username, plaintext password and IP address.
119 I get authenticated against a crypt password.
120 """
121
122 - def __init__(self, username, password, address):
126
132
137
138 pb.setUnjellyableForClass(KeycardUACPP, KeycardUACPP)
139
140
141
142
143
144 UCPCC = credentials.UsernameCryptPasswordCryptChallenger
145
146
148 """
149 I am a keycard with a username and IP address.
150 I get authenticated through challenge/response on a crypt password.
151 """
152
157
163
168
169 pb.setUnjellyableForClass(KeycardUACPCC, KeycardUACPCC)
170
171
173 """
174 I am a keycard with a token and IP address and a path (optional).
175 I get authenticated by token and maybe IP address.
176 """
177
178 - def __init__(self, token, address, path=None):
183
185 d = Keycard.getData(self)
186 d['token'] = self.token
187 d['address'] = self.address
188 d['path'] = self.path
189 return d
190
192 return "<%s %s token %s for path %s @%s for reqId %r in state %s>" % (
193 self.__class__.__name__, self.id, self.token, self.path,
194 self.address, self.requesterId, _statesEnum[self.state])
195
196 pb.setUnjellyableForClass(KeycardToken, KeycardToken)
197
198
200 """
201 I am a keycard with a token and IP address and a path (optional).
202 I get authenticated by HTTP request GET parameters and maybe IP address.
203
204 @type address: C{str}
205 @ivar address: The HTTP client IP address.
206 @type path: C{str}
207 @ivar path: The path requested by the HTTP client.
208 """
209
210 - def __init__(self, arguments, address, path=None):
215
217 d = Keycard.getData(self)
218 d['arguments'] = self.arguments
219 d['address'] = self.address
220 d['path'] = self.path
221 return d
222
224 return "<%s %s for path %s @%s for reqId %r in state %s>" % (
225 self.__class__.__name__, self.id, self.path,
226 self.address, self.requesterId, _statesEnum[self.state])
227
228 pb.setUnjellyableForClass(KeycardHTTPGetArguments, KeycardHTTPGetArguments)
229
230
231 USPCC = credentials.UsernameSha256PasswordCryptChallenger
232
233
235 """
236 I am a keycard with a username and IP address.
237 I get authenticated through challenge/response on a SHA-256 password.
238 """
239
244
250
255
256 pb.setUnjellyableForClass(KeycardUASPCC, KeycardUASPCC)
257
258
275
276 pb.setUnjellyableForClass(KeycardHTTPDigest, KeycardHTTPDigest)
277
278
279
280
281
289
290 pb.setUnjellyableForClass(HTTPDigestKeycard, HTTPDigestKeycard)
291