1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# $Id$
#
# PyLasso - Python bindings for Lasso Library
#
# Copyright (C) 2003-2004 Easter-eggs, Valery Febvre
# http://lasso.labs.libre-entreprise.org
#
# Author: Valery Febvre <vfebvre@easter-eggs.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
__docformat__ = "plaintext en"
import lassomod
from lasso_strings import *
class Error(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return repr(self.msg)
def init():
"""
"""
return lassomod.init()
def shutdown():
"""
Shutdown Lasso Library
"""
return lassomod.shutdown()
################################################################################
# xml : low level classes
################################################################################
class Node:
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
## #self._o = lassomod.(size)
## if self._o is None: raise Error('lasso_node_new() failed')
def dump(self, encoding="utf8", format=1):
return lassomod.node_dump(self, encoding, format)
def destroy(self):
lassomod.node_unref(self)
def get_attr_value(self, name):
return lassomod.node_get_attr_value(self, name)
def get_child(self, name):
obj = lassomod.node_get_child(self, name)
if obj:
return Node(_obj=obj)
return None
def get_content(self):
return lassomod.node_get_content(self)
def url_encode(self, sign_method, private_key_file):
return lassomod.node_url_encode(self, sign_method, private_key_file)
def soap_envelop(self):
return lassomod.node_soap_envelop(self)
def verify_signature(self, certificate_file):
return lassomod.node_verify_signature(self, certificate_file)
class SamlAssertion(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.saml_assertion_new()
if _obj is None: raise Error('lasso_saml_assertion_new() failed')
Node.__init__(self, _obj=_obj)
def add_authenticationStatement(self, authenticationStatement):
lassomod.saml_assertion_add_authenticationStatement(self,
authenticationStatement)
class SamlAuthenticationStatement(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.saml_authentication_statement_new()
if _obj is None: raise Error('lasso_saml_authentication_statement_new() failed')
Node.__init__(self, _obj=_obj)
class LibAuthenticationStatement(SamlAuthenticationStatement):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_authentication_statement_new()
if _obj is None: raise Error('lasso_saml_authentication_statement_new() failed')
SamlAuthenticationStatement.__init__(self, _obj=_obj)
def set_sessionIndex(self, sessionIndex):
lassomod.lib_authentication_statement_set_sessionIndex(self, sessionIndex)
class LibAuthnRequest(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_authn_request_new()
if _obj is None: raise Error('lasso_lib_authn_request_new() failed')
Node.__init__(self, _obj=_obj)
def set_forceAuthn(self, forceAuthn):
lassomod.lib_authn_request_set_forceAuthn(self, forceAuthn)
def set_isPassive(self, isPassive):
lassomod.lib_authn_request_set_isPassive(self, isPassive)
def set_nameIDPolicy(self, nameIDPolicy):
lassomod.lib_authn_request_set_nameIDPolicy(self, nameIDPolicy)
def set_protocolProfile(self, protocolProfile):
lassomod.lib_authn_request_set_protocolProfile(self, protocolProfile)
def set_relayState(self, relayState):
lassomod.lib_authn_request_set_relayState(self, relayState)
class LibFederationTerminationNotification(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_federation_termination_notification_new()
if _obj is None:
raise Error('lasso_lib_federation_termination_notification_new() failed')
Node.__init__(self, _obj=_obj)
def set_consent(self, consent):
lassomod.lib_federation_termination_notification_set_consent(self, consent)
class LibLogoutRequest(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_logout_request_new()
if _obj is None: raise Error('lasso_lib_logout_request_new() failed')
Node.__init__(self, _obj=_obj)
def set_consent(self, consent):
lassomod.lib_logout_request_set_consent(self, consent)
def set_nameIdentifier(self, nameIdentifier):
lassomod.lib_logout_request_set_nameIdentifier(self, nameIdentifier)
def set_providerID(self, providerID):
lassomod.lib_logout_request_set_providerID(self, providerID)
def set_relayState(self, relayState):
lassomod.lib_logout_request_set_relayState(self, relayState)
def set_sessionIndex(self, sessionIndex):
lassomod.lib_logout_request_set_sessionIndex(self, sessionIndex)
class LibLogoutResponse(Node):
def __init__(self, _obj = None):
if _obj!=None:
self._o = _obj
return
_obj = lassomod.lib_logout_response_new()
if _obj is None: raise Error('lasso_lib_logout_response_new() failed')
Node.__init__(self, _obj = _obj)
class LibNameIdentifierMappingRequest(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_name_identifier_mapping_request_new()
if _obj is None:
raise Error('lasso_lib_name_identifier_mapping_request_new() failed')
Node.__init__(self, _obj=_obj)
def set_consent(self, consent):
lassomod.lib_name_identifier_mapping_request_set_consent(self, consent)
class LibNameIdentifierMappingResponse(Node):
def __init__(self, _obj = None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_name_identifier_mapping_response_new()
if _obj is None:
raise Error('lasso_lib_name_identifier_mapping_response_new() failed')
Node.__init__(self, _obj=_obj)
class LibRegisterNameIdentifierRequest(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_register_name_identifier_request_new()
if _obj is None:
raise Error('lasso_lib_register_name_identifier_request_new() failed')
Node.__init__(self, _obj=_obj)
class LibRegisterNameIdentifierResponse(Node):
def __init__(self, _obj = None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.lib_register_name_identifier_response_new()
if _obj is None:
raise Error('lasso_lib_register_name_identifier_response_new() failed')
Node.__init__(self, _obj=_obj)
class SamlNameIdentifier(Node):
def __init__(self, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.saml_name_identifier_new()
if _obj is None: raise Error('lasso_saml_authentication_statement_new() failed')
Node.__init__(self, _obj=_obj)
def set_format(self, format):
lassomod.saml_name_identifier_set_format(self, format)
def set_nameQualifier(self, nameQualifier):
lassomod.saml_name_identifier_set_nameQualifier(self, nameQualifier)
################################################################################
# protocols : high level classes
################################################################################
def authn_request_get_protocolProfile(query):
return lassomod.authn_request_get_protocolProfile(query)
class AuthnRequest(LibAuthnRequest):
def __init__(self, providerID, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.authn_request_new(providerID)
if _obj is None: raise Error('lasso_authn_request_new() failed')
LibAuthnRequest.__init__(self, _obj=_obj)
def set_requestAuthnContext(self, authnContextClassRefs=None,
authnContextStatementRefs=None,
authnContextComparison=None):
lassomod.authn_request_set_requestAuthnContext(self,
authnContextClassRefs,
authnContextStatementRefs,
authnContextComparison)
def set_scoping(self, proxyCount):
lassomod.authn_request_set_scoping(self, proxyCount)
class AuthnResponse(Node):
def __init__(self, _obj):
"""
"""
self._o = _obj
Node.__init__(self, _obj=_obj)
def new_from_dump(cls, buffer):
obj = lassomod.authn_response_new_from_dump(buffer)
return AuthnResponse(obj)
new_from_dump = classmethod(new_from_dump)
def new_from_request_query(cls, query, providerID):
obj = lassomod.authn_response_new_from_request_query(query, providerID)
return AuthnResponse(obj)
new_from_request_query = classmethod(new_from_request_query)
def __isprivate(self, name):
return name == '_o'
def __getattr__(self, name):
if self.__isprivate(name):
return self.__dict__[name]
if name[:2] == "__" and name[-2:] == "__" and name != "__members__":
raise AttributeError, name
ret = lassomod.authn_response_getattr(self, name)
if ret is None:
raise AttributeError, name
if name == "request":
ret = AuthnRequest(None, _obj=ret)
return ret
def add_assertion(self, assertion, private_key_file, certificate_file):
lassomod.authn_response_add_assertion(self, assertion,
private_key_file,
certificate_file)
def must_authenticate(self, is_authenticated):
return lassomod.authn_response_must_authenticate(self,
is_authenticated)
def process_authentication_result(self, authentication_result):
lassomod.authn_response_process_authentication_result(self,
authentication_result)
def verify_signature(self, public_key_file, private_key_file):
return lassomod.authn_response_verify_signature(self, public_key_file,
private_key_file)
class FederationTerminationNotification(LibFederationTerminationNotification):
def __init__(self, obj):
"""
"""
self._o = obj
LibFederationTerminationNotification.__init__(self, _obj=self._o)
def new(cls, providerID, nameIdentifier, nameQualifier, format):
obj = lassomod.federation_termination_notification_new(providerID, nameIdentifier, nameQualifier, format)
return FederationTerminationNotification(obj)
new = classmethod(new)
def new_from_soap(cls, envelope):
obj = lassomod.federation_termination_notification_new_from_soap(envelope)
return FederationTerminationNotification(obj)
new_from_soap = classmethod(new_from_soap)
def new_from_query(cls, query):
obj = lassomod.federation_termination_notification_new_from_query(query)
return FederationTerminationNotification(obj)
new_from_query = classmethod(new_from_query)
class LogoutRequest(LibLogoutRequest):
def __init__(self, _obj):
"""
"""
self._o = _obj
LibLogoutRequest.__init__(self, _obj = self._o)
def new(cls, providerID, nameIdentifier, nameQualifier, format):
obj = lassomod.logout_request_new(providerID, nameIdentifier, nameQualifier, format)
return LogoutRequest(obj)
new = classmethod(new)
def new_from_soap(cls, envelope):
obj = lassomod.logout_request_new_from_soap(envelope)
return LogoutRequest(obj)
new_from_soap = classmethod(new_from_soap)
def new_from_query(cls, query):
obj = lassomod.logout_request_new_from_query(query)
return LogoutRequest(obj)
new_from_query = classmethod(new_from_query)
class LogoutResponse(LibLogoutResponse):
def __init__(self, _obj):
"""
"""
self._o = _obj
LibLogoutResponse.__init__(self, _obj = self._o)
def new_from_request_soap(cls, envelope, providerID, status_code_value):
obj = lassomod.logout_response_new_from_request_soap(envelope, providerID, status_code_value)
return LogoutResponse(obj)
new_from_request_soap = classmethod(new_from_request_soap)
def new_from_soap(cls, envelope):
obj = lassomod.logout_response_new_from_soap(envelope)
return LogoutResponse(obj)
new_from_soap = classmethod(new_from_soap)
def new_from_dump(cls, dump):
obj = lassomod.logout_response_new_from_dump(dump)
return LogoutResponse(obj)
new_from_dump = classmethod(new_from_dump)
def new_from_request_query(cls, query, providerID, status_code_value):
obj = lassomod.logout_response_new_from_request_query(query, providerID, status_code_value)
return LogoutResponse(obj);
new_from_request_query = classmethod(new_from_request_query)
def new_from_query(cls, query):
obj = lassomod.logout_response_new_from_query(query)
return LogoutResponse(obj);
new_from_query = classmethod(new_from_query)
class NameIdentifierMappingRequest(LibNameIdentifierMappingRequest):
def __init__(self, _obj):
"""
"""
self._o = _obj
LibNameIdentifierMappingRequest.__init__(self, _obj = self._o)
def new(cls, providerID, nameIdentifier, nameQualifier, format):
obj = lassomod.name_identifier_mapping_request_new(providerID, nameIdentifier, nameQualifier, format)
return NameIdentifierMappingRequest(obj)
new = classmethod(new)
def new_from_soap(cls, envelope):
obj = lassomod.name_identifier_mapping_request_new_from_soap(envelope)
return NameIdentifierMappingRequest(obj)
new_from_soap = classmethod(new_from_soap)
def new_from_query(cls, query):
obj = lassomod.name_identifier_mapping_request_new_from_query(query)
return NameIdentifierMappingRequest(obj)
new_from_query = classmethod(new_from_query)
class NameIdentifierMappingResponse(LibNameIdentifierMappingResponse):
def __init__(self, _obj):
"""
"""
self._o = _obj
LibNameIdentifierMappingResponse.__init__(self, _obj = self._o)
def new_from_request_soap(cls, envelope, providerID, status_code_value):
obj = lassomod.name_identifier_mapping_response_new_from_request_soap(envelope, providerID, status_code_value)
return NameIdentifierMappingResponse(obj)
new_from_request_soap = classmethod(new_from_request_soap)
def new_from_soap(cls, envelope):
obj = lassomod.name_identifier_mapping_response_new_from_soap(envelope)
return NameIdentifierMappingResponse(obj)
new_from_soap = classmethod(new_from_soap)
def new_from_dump(cls, dump):
obj = lassomod.name_identifier_mapping_response_new_from_dump(dump)
return NameIdentifierMappingResponse(obj)
new_from_dump = classmethod(new_from_dump)
def new_from_request_query(cls, query, providerID, status_code_value):
obj = lassomod.name_identifier_mapping_response_new_from_request_query(query, providerID, status_code_value)
return NameIdentifierMappingResponse(obj);
new_from_request_query = classmethod(new_from_request_query)
def new_from_query(cls, query):
obj = lassomod.name_identifier_mapping_response_new_from_query(query)
return NameIdentifierMappingResponse(obj);
new_from_query = classmethod(new_from_query)
class RegisterNameIdentifierRequest(LibRegisterNameIdentifierRequest):
def __init__(self, _obj):
"""
"""
self._o = _obj
LibRegisterNameIdentifierRequest.__init__(self, _obj = self._o)
def new(cls, providerID,
idpNameIdentifier, idpNameQualifier, idpFormat,
spNameIdentifier, spNameQualifier, spFormat,
oldNameIdentifier, oldNameQualifier, oldFormat):
obj = lassomod.register_name_identifier_request_new(providerID,
idpNameIdentifier, idpNameQualifier, idpFormat,
spNameIdentifier, spNameQualifier, spFormat,
oldNameIdentifier, oldNameQualifier, oldFormat)
return RegisterNameIdentifierRequest(obj)
new = classmethod(new)
def new_from_soap(cls, envelope):
obj = lassomod.register_name_identifier_request_new_from_soap(envelope)
return RegisterNameIdentifierRequest(obj)
new_from_soap = classmethod(new_from_soap)
def new_from_query(cls, query):
obj = lassomod.register_name_identifier_request_new_from_query(query)
return RegisterNameIdentifierRequest(obj)
new_from_query = classmethod(new_from_query)
def rename_attributes_for_encoded_query(self):
lassomod.register_name_identifier_request_rename_attributes_for_query(self)
class RegisterNameIdentifierResponse(LibRegisterNameIdentifierResponse):
def __init__(self, _obj):
"""
"""
self._o = _obj
LibRegisterNameIdentifierResponse.__init__(self, _obj = self._o)
def new_from_request_soap(cls, envelope, providerID, status_code_value):
obj = lassomod.register_name_identifier_response_new_from_request_soap(envelope, providerID, status_code_value)
return RegisterNameIdentifierResponse(obj)
new_from_request_soap = classmethod(new_from_request_soap)
def new_from_soap(cls, envelope):
obj = lassomod.register_name_identifier_response_new_from_soap(envelope)
return RegisterNameIdentifierResponse(obj)
new_from_soap = classmethod(new_from_soap)
def new_from_dump(cls, dump):
obj = lassomod.register_name_identifier_response_new_from_dump(dump)
return RegisterNameIdentifierResponse(obj)
new_from_dump = classmethod(new_from_dump)
def new_from_request_query(cls, query, providerID, status_code_value):
obj = lassomod.register_name_identifier_response_new_from_request_query(query, providerID, status_code_value)
return RegisterNameIdentifierResponse(obj);
new_from_request_query = classmethod(new_from_request_query)
def new_from_query(cls, query):
obj = lassomod.register_name_identifier_response_new_from_query(query)
return RegisterNameIdentifierResponse(obj);
new_from_query = classmethod(new_from_query)
################################################################################
# elements
################################################################################
class Assertion(SamlAssertion):
def __init__(self, issuer, requestID, _obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.assertion_new(issuer, requestID)
if _obj is None: raise Error('lasso_assertion_new() failed')
SamlAssertion.__init__(self, _obj=_obj)
class AuthenticationStatement(Node):
def __init__(self,
authenticationMethod,
reauthenticateOnOrAfter,
nameIdentifier,
nameQualifier,
format,
idp_nameIdentifier,
idp_nameQualifier,
idp_format,
_obj=None):
"""
"""
if _obj != None:
self._o = _obj
return
_obj = lassomod.authentication_statement_new(authenticationMethod,
reauthenticateOnOrAfter,
nameIdentifier,
nameQualifier,
format,
idp_nameIdentifier,
idp_nameQualifier,
idp_format)
if _obj is None:
raise Error('lasso_authentication_statement_new() failed')
Node.__init__(self, _obj=_obj)
|