2004-04-07 05:00:43 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
2004-08-20 00:36:50 +02:00
|
|
|
# PyLasso - High-level Python bindings for Lasso Library
|
2004-04-07 05:00:43 +02:00
|
|
|
#
|
2004-08-19 11:08:53 +02:00
|
|
|
# Copyright (C) 2004 Entr'ouvert
|
2004-07-22 08:42:41 +02:00
|
|
|
# http://lasso.entrouvert.org
|
2004-04-07 05:00:43 +02:00
|
|
|
#
|
2004-08-20 00:36:50 +02:00
|
|
|
# Author: Emmanuel Raviart <eraviart@entrouvert.com>
|
2004-04-07 05:00:43 +02:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
|
2004-04-07 05:00:43 +02:00
|
|
|
__docformat__ = "plaintext en"
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
|
2004-04-07 05:00:43 +02:00
|
|
|
import lassomod
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Constants
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
2004-08-20 16:47:40 +02:00
|
|
|
def _initConstants():
|
|
|
|
"""Copy constants from module lassomod.
|
|
|
|
|
|
|
|
They are copied in two forms :
|
|
|
|
|
|
|
|
- as a global variable, with the 'lasso' prefix removed and the first letter in lower case,
|
|
|
|
|
|
|
|
- as an item in a global dictionnary of all constants having the same prefix.
|
|
|
|
"""
|
|
|
|
|
|
|
|
constantPrefixes = (
|
|
|
|
'lassoHttpMethod', 'lassoLibConsent', 'lassoLibNameIDPolicyType',
|
|
|
|
'lassoLibProtocolProfile', 'lassoLoginProtocolProfile', 'lassoMessageType',
|
|
|
|
'lassoProviderType', 'lassoRequestType', 'lassoSamlAuthenticationMethod',
|
|
|
|
'lassoSignatureMethod')
|
|
|
|
globals_ = globals()
|
|
|
|
for constantName, constantValue in lassomod.__dict__.iteritems():
|
|
|
|
for contantPrefix in constantPrefixes:
|
|
|
|
if constantName.startswith(contantPrefix):
|
|
|
|
globals_[constantName[5].lower() + constantName[6:]] = constantValue
|
|
|
|
constantPlural = contantPrefix[5].lower() + contantPrefix[6:] + 's'
|
|
|
|
constantCore = constantName[len(contantPrefix)].lower() \
|
|
|
|
+ constantName[len(contantPrefix) + 1:]
|
|
|
|
if constantPlural in globals_:
|
|
|
|
globals_[constantPlural][constantCore] = constantValue
|
|
|
|
else:
|
|
|
|
globals_[constantPlural] = {constantCore: constantValue}
|
|
|
|
|
|
|
|
_initConstants()
|
2004-08-04 21:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
################################################################################
|
2004-08-20 00:36:50 +02:00
|
|
|
# Errors
|
2004-08-04 21:06:12 +02:00
|
|
|
################################################################################
|
|
|
|
|
2004-08-02 19:26:28 +02:00
|
|
|
|
2004-04-07 05:00:43 +02:00
|
|
|
class Error(Exception):
|
2004-08-06 17:40:51 +02:00
|
|
|
code = None # Use positive error codes for binding specific errors.
|
2004-08-04 21:55:17 +02:00
|
|
|
functionName = None
|
2004-08-04 21:06:12 +02:00
|
|
|
|
2004-08-04 21:55:17 +02:00
|
|
|
def __init__(self, functionName):
|
|
|
|
self.functionName = functionName
|
2004-08-04 21:06:12 +02:00
|
|
|
|
2004-04-07 05:00:43 +02:00
|
|
|
def __str__(self):
|
|
|
|
return repr(self.msg)
|
2004-08-04 21:06:12 +02:00
|
|
|
|
|
|
|
|
2004-08-04 21:55:17 +02:00
|
|
|
class ErrorUnknown(Error):
|
|
|
|
def __init__(self, code, functionName):
|
2004-08-06 14:08:50 +02:00
|
|
|
Error.__init__(self, functionName)
|
2004-08-04 21:55:17 +02:00
|
|
|
self.code = code
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Unknown error number %d in Lasso function %s' % (self.code, self.functionName)
|
|
|
|
|
|
|
|
|
2004-08-04 21:06:12 +02:00
|
|
|
class ErrorLassoAlreadyInitialized(Error):
|
2004-08-06 17:40:51 +02:00
|
|
|
code = 1
|
2004-08-04 21:06:12 +02:00
|
|
|
msg = 'Lasso already initialized'
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorLassoNotInitialized(Error):
|
2004-08-06 17:40:51 +02:00
|
|
|
code = 2
|
2004-08-04 21:06:12 +02:00
|
|
|
msg = 'Lasso not initialized or already shotdown'
|
|
|
|
|
2004-04-13 12:29:42 +02:00
|
|
|
|
2004-08-04 21:06:12 +02:00
|
|
|
class ErrorInstanceCreationFailed(Error):
|
2004-08-06 17:40:51 +02:00
|
|
|
code = 3
|
2004-08-04 21:06:12 +02:00
|
|
|
|
2004-08-19 11:08:53 +02:00
|
|
|
def __str__(self):
|
2004-08-04 21:06:12 +02:00
|
|
|
return 'Instance creation failed in Lasso function %s()' % self.functionName
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
|
|
|
|
class ErrorUnknownRequestType(Error):
|
|
|
|
code = 4
|
|
|
|
requestType = None
|
|
|
|
|
|
|
|
def __init__(self, functionName, requestType):
|
|
|
|
super(ErrorUnknownRequestType, self).__init__(functionName)
|
|
|
|
self.requestType = requestType
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Unknown request type (= %s) in Lasso function %s()' % (
|
|
|
|
self.requestType, self.functionName)
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorUnknownResponseType(Error):
|
|
|
|
code = 5
|
|
|
|
responseType = None
|
|
|
|
|
|
|
|
def __init__(self, functionName, responseType):
|
|
|
|
super(ErrorUnknownResponseType, self).__init__(functionName)
|
|
|
|
self.responseType = responseType
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return 'Unknown response type (= %s) in Lasso function %s()' % (
|
|
|
|
self.responseType, self.functionName)
|
|
|
|
|
2004-08-04 21:06:12 +02:00
|
|
|
|
2004-08-04 21:55:17 +02:00
|
|
|
def newError(code, functionName):
|
|
|
|
# FIXME: Use proper ErrorClass, when Lasso will have well defined error codes.
|
|
|
|
return ErrorUnknown(code, functionName)
|
|
|
|
|
|
|
|
|
2004-08-04 21:06:12 +02:00
|
|
|
################################################################################
|
2004-08-20 00:36:50 +02:00
|
|
|
# Common
|
2004-08-04 21:06:12 +02:00
|
|
|
################################################################################
|
|
|
|
|
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
_registeredClasses = {}
|
|
|
|
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
class _ObjectMixin(object):
|
|
|
|
"""Abstract mixin class"""
|
2004-04-27 17:34:34 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
|
|
|
|
|
|
|
lassomodClass = None
|
|
|
|
|
|
|
|
# Attributes
|
|
|
|
|
|
|
|
def get_parent(self):
|
|
|
|
parent = super(_ObjectMixin, self).parent
|
|
|
|
if parent is not None:
|
|
|
|
_setRegisteredClass(parent)
|
|
|
|
return parent
|
|
|
|
parent = property(get_parent)
|
|
|
|
|
|
|
|
# Methods
|
2004-08-04 21:06:12 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return '<Lasso %s instance wrapping %s>' % (self.__class__.__name__, self.this)
|
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
|
|
|
|
def _setRegisteredClass(instance):
|
|
|
|
cls = _registeredClasses.get(instance.__class__, None)
|
|
|
|
if cls is None and instance.__class__.__name__.endswith('Ptr'):
|
|
|
|
cls = _registeredClasses.get(instance.__class__.__bases__[0], None)
|
|
|
|
if cls is not None:
|
|
|
|
object.__setattr__(instance, '__class__', cls)
|
|
|
|
|
|
|
|
|
|
|
|
def registerClass(cls):
|
|
|
|
assert cls.lassomodClass
|
|
|
|
_registeredClasses[cls.lassomodClass] = cls
|
2004-04-07 05:00:43 +02:00
|
|
|
|
2004-08-02 19:26:28 +02:00
|
|
|
|
2004-05-03 00:25:37 +02:00
|
|
|
################################################################################
|
2004-08-20 00:36:50 +02:00
|
|
|
# Protocols
|
2004-05-03 00:25:37 +02:00
|
|
|
################################################################################
|
2004-08-04 21:06:12 +02:00
|
|
|
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
class AuthnRequest(_ObjectMixin, lassomod.LassoAuthnRequest):
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
|
|
|
|
|
|
|
lassomodClass = lassomod.LassoAuthnRequest
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
# Attributes
|
|
|
|
|
|
|
|
def set_affiliationID(self, affiliationID):
|
|
|
|
lassomod.lasso_lib_authn_request_set_affiliationID(self.parent, affiliationID)
|
|
|
|
affiliationID = property(None, set_affiliationID)
|
|
|
|
|
|
|
|
def set_assertionConsumerServiceID(self, assertionConsumerServiceID):
|
|
|
|
lassomod.lasso_lib_authn_request_set_assertionConsumerServiceID(
|
|
|
|
self.parent, assertionConsumerServiceID)
|
|
|
|
assertionConsumerServiceID = property(None, set_assertionConsumerServiceID)
|
|
|
|
|
2004-07-22 02:47:01 +02:00
|
|
|
def set_consent(self, consent):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_lib_authn_request_set_consent(self.parent, consent)
|
|
|
|
consent = property(None, set_consent)
|
2004-07-22 02:47:01 +02:00
|
|
|
|
2004-05-03 00:25:37 +02:00
|
|
|
def set_forceAuthn(self, forceAuthn):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_lib_authn_request_set_forceAuthn(self.parent, forceAuthn)
|
|
|
|
forceAuthn = property(None, set_forceAuthn)
|
2004-04-27 11:34:22 +02:00
|
|
|
|
2004-05-03 00:25:37 +02:00
|
|
|
def set_isPassive(self, isPassive):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_lib_authn_request_set_isPassive(self.parent, isPassive)
|
|
|
|
isPassive = property(None, set_isPassive)
|
2004-04-08 04:44:16 +02:00
|
|
|
|
2004-05-03 11:38:44 +02:00
|
|
|
def set_nameIDPolicy(self, nameIDPolicy):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_lib_authn_request_set_nameIDPolicy(self.parent, nameIDPolicy)
|
|
|
|
nameIDPolicy = property(None, set_nameIDPolicy)
|
2004-05-03 11:38:44 +02:00
|
|
|
|
2004-05-03 00:25:37 +02:00
|
|
|
def set_protocolProfile(self, protocolProfile):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_lib_authn_request_set_protocolProfile(self.parent, protocolProfile)
|
|
|
|
protocolProfile = property(None, set_protocolProfile)
|
2004-04-16 12:49:08 +02:00
|
|
|
|
2004-05-03 00:25:37 +02:00
|
|
|
def set_providerID(self, providerID):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_lib_authn_request_set_providerID(self.parent, providerID)
|
|
|
|
providerID = property(None, set_providerID)
|
2004-04-27 11:34:22 +02:00
|
|
|
|
2004-05-03 00:25:37 +02:00
|
|
|
def set_relayState(self, relayState):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_lib_authn_request_set_relayState(self.parent, relayState)
|
|
|
|
relayState = property(None, set_relayState)
|
2004-04-16 12:49:08 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
registerClass(AuthnRequest)
|
|
|
|
|
2004-05-13 17:18:24 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
class Request(_ObjectMixin, lassomod.LassoRequestPtr):
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
|
|
|
|
|
|
|
lassomodClass = lassomod.LassoRequestPtr
|
|
|
|
|
|
|
|
registerClass(Request)
|
2004-05-13 17:18:24 +02:00
|
|
|
|
2004-05-03 00:25:37 +02:00
|
|
|
|
|
|
|
################################################################################
|
2004-08-20 00:36:50 +02:00
|
|
|
# Profiles
|
2004-05-03 00:25:37 +02:00
|
|
|
################################################################################
|
|
|
|
|
2004-08-04 21:06:12 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
class Server(_ObjectMixin, lassomod.LassoServer):
|
|
|
|
# Constants
|
2004-07-09 18:07:36 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
lassomodClass = lassomod.LassoServer
|
2004-08-04 21:06:12 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
# Constructors
|
2004-07-10 03:33:56 +02:00
|
|
|
|
2004-08-20 13:31:58 +02:00
|
|
|
def __init__(self, metadata = None, public_key = None, private_key = None, certificate = None,
|
|
|
|
signature_method = signatureMethodRsaSha1):
|
|
|
|
super(Server, self).__init__(
|
|
|
|
metadata, public_key, private_key, certificate, signature_method)
|
|
|
|
|
2004-07-12 15:59:22 +02:00
|
|
|
def new_from_dump(cls, dump):
|
2004-08-20 00:36:50 +02:00
|
|
|
self = lassomod.lasso_server_new_from_dump(dump)
|
|
|
|
if self is None:
|
2004-08-04 21:06:12 +02:00
|
|
|
raise ErrorInstanceCreationFailed('lasso_server_new_from_dump')
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(self)
|
2004-08-20 00:36:50 +02:00
|
|
|
return self
|
2004-07-12 15:59:22 +02:00
|
|
|
new_from_dump = classmethod(new_from_dump)
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
# Methods
|
|
|
|
|
|
|
|
def add_provider(self, metadata, public_key = None, certificate = None):
|
|
|
|
errorCode = lassomod.lasso_server_add_provider(self, metadata, public_key, certificate)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_server_add_provider')
|
2004-07-09 18:30:49 +02:00
|
|
|
|
2004-07-12 15:59:22 +02:00
|
|
|
def dump(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
return lassomod.lasso_server_dump(self)
|
2004-07-13 02:19:21 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
registerClass(Server)
|
|
|
|
|
2004-07-30 17:34:29 +02:00
|
|
|
|
2004-08-20 02:13:35 +02:00
|
|
|
class Identity(_ObjectMixin, lassomod.LassoIdentity):
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
2004-08-20 02:13:35 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
lassomodClass = lassomod.LassoIdentity
|
|
|
|
|
|
|
|
# Constructors
|
2004-08-20 02:13:35 +02:00
|
|
|
|
|
|
|
def new_from_dump(cls, dump):
|
|
|
|
self = lassomod.lasso_identity_new_from_dump(dump)
|
|
|
|
if self is None:
|
|
|
|
raise ErrorInstanceCreationFailed('lasso_identity_new_from_dump')
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(self)
|
2004-08-20 02:13:35 +02:00
|
|
|
return self
|
|
|
|
new_from_dump = classmethod(new_from_dump)
|
|
|
|
|
|
|
|
# Methods
|
|
|
|
|
|
|
|
def dump(self):
|
|
|
|
return lassomod.lasso_identity_dump(self)
|
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
registerClass(Identity)
|
|
|
|
|
2004-08-20 02:13:35 +02:00
|
|
|
|
|
|
|
class Session(_ObjectMixin, lassomod.LassoSession):
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
2004-08-20 02:13:35 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
lassomodClass = lassomod.LassoSession
|
|
|
|
|
|
|
|
# Constructors
|
2004-08-20 02:13:35 +02:00
|
|
|
|
|
|
|
def new_from_dump(cls, dump):
|
|
|
|
self = lassomod.lasso_session_new_from_dump(dump)
|
|
|
|
if self is None:
|
|
|
|
raise ErrorInstanceCreationFailed('lasso_session_new_from_dump')
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(self)
|
2004-08-20 02:13:35 +02:00
|
|
|
return self
|
|
|
|
new_from_dump = classmethod(new_from_dump)
|
|
|
|
|
2004-08-20 11:37:47 +02:00
|
|
|
# Attributes
|
|
|
|
|
|
|
|
def get_authentication_method(self, remote_providerID = None):
|
|
|
|
return lassomod.lasso_session_get_authentication_method(self, remote_providerID)
|
|
|
|
authentication_method = property(get_authentication_method)
|
|
|
|
|
2004-08-20 02:13:35 +02:00
|
|
|
# Methods
|
|
|
|
|
|
|
|
def dump(self):
|
|
|
|
return lassomod.lasso_session_dump(self)
|
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
registerClass(Session)
|
|
|
|
|
2004-08-20 02:13:35 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
class _ProfileChild(object):
|
|
|
|
"""Abstract class for all Lasso objects that inherit from LassoProfile"""
|
2004-07-30 17:34:29 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
# Attributes
|
2004-07-30 17:34:29 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def get_identity(self):
|
2004-08-20 02:13:35 +02:00
|
|
|
identity = lassomod.lasso_profile_get_identity(self.parent)
|
|
|
|
if identity is not None:
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(identity)
|
2004-08-20 02:13:35 +02:00
|
|
|
return identity
|
2004-08-20 00:36:50 +02:00
|
|
|
def set_identity(self, identity):
|
|
|
|
lassomod.lasso_profile_set_identity(self.parent, identity)
|
|
|
|
identity = property(get_identity, set_identity)
|
|
|
|
|
|
|
|
def get_msg_body(self):
|
|
|
|
return self.parent.msg_body
|
|
|
|
msg_body = property(get_msg_body)
|
|
|
|
|
|
|
|
def get_msg_relayState(self):
|
|
|
|
return self.parent.msg_relayState
|
|
|
|
msg_relayState = property(get_msg_relayState)
|
|
|
|
|
|
|
|
def get_msg_url(self):
|
|
|
|
return self.parent.msg_url
|
|
|
|
msg_url = property(get_msg_url)
|
|
|
|
|
|
|
|
def get_nameIdentifier(self):
|
|
|
|
return self.parent.nameIdentifier
|
|
|
|
nameIdentifier = property(get_nameIdentifier)
|
|
|
|
|
|
|
|
def get_provider_type(self):
|
|
|
|
return self.parent.provider_type
|
|
|
|
provider_type = property(get_provider_type)
|
|
|
|
|
|
|
|
def set_remote_providerID(self, remote_providerID):
|
|
|
|
lassomod.lasso_profile_set_remote_providerID(self.parent, remote_providerID)
|
|
|
|
remote_providerID = property(None, set_remote_providerID)
|
|
|
|
|
|
|
|
def get_request(self):
|
|
|
|
request_type = self.request_type
|
|
|
|
if request_type == messageTypeAuthnRequest:
|
|
|
|
request = lassomod.lasso_profile_get_authn_request_ref(self.parent)
|
|
|
|
elif request_type == messageTypeRequest:
|
|
|
|
request = lassomod.lasso_profile_get_request_ref(self.parent)
|
|
|
|
else:
|
|
|
|
raise ErrorUnknownRequestType('lasso_profile_get_???_request', request_type)
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(request)
|
2004-08-20 00:36:50 +02:00
|
|
|
return request
|
|
|
|
request = property(get_request)
|
|
|
|
|
|
|
|
def get_request_type(self):
|
|
|
|
return self.parent.request_type
|
|
|
|
request_type = property(get_request_type)
|
|
|
|
|
|
|
|
def get_response(self):
|
|
|
|
response_type = self.response_type
|
|
|
|
if response_type == messageTypeAuthnResponse:
|
|
|
|
response = lassomod.lasso_profile_get_authn_response_ref(self.parent)
|
|
|
|
elif response_type == messageTypeResponse:
|
|
|
|
response = lassomod.lasso_profile_get_response_ref(self.parent)
|
|
|
|
else:
|
|
|
|
raise ErrorUnknownResponseType('lasso_profile_get_???_response', response_type)
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(response)
|
2004-08-20 00:36:50 +02:00
|
|
|
return response
|
|
|
|
response = property(get_response)
|
2004-07-26 20:07:52 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def set_response_status(self, response_status):
|
|
|
|
lassomod.lasso_profile_set_response_status(self.parent, response_status)
|
|
|
|
response_status = property(None, set_response_status)
|
2004-07-26 20:07:52 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def get_response_type(self):
|
|
|
|
return self.parent.response_type
|
|
|
|
response_type = property(get_response_type)
|
2004-07-26 20:07:52 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def get_server(self):
|
2004-08-20 02:13:35 +02:00
|
|
|
server = self.parent.server
|
|
|
|
if server is not None:
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(server)
|
2004-08-20 02:13:35 +02:00
|
|
|
return server
|
2004-08-20 00:36:50 +02:00
|
|
|
server = property(get_server)
|
2004-07-30 17:34:29 +02:00
|
|
|
|
|
|
|
def get_session(self):
|
2004-08-20 02:13:35 +02:00
|
|
|
session = lassomod.lasso_profile_get_session(self.parent)
|
|
|
|
if session is not None:
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(session)
|
2004-08-20 02:13:35 +02:00
|
|
|
return session
|
2004-08-20 00:36:50 +02:00
|
|
|
def set_session(self, session):
|
|
|
|
lassomod.lasso_profile_set_session(self.parent, session)
|
|
|
|
session = property(get_session, set_session)
|
|
|
|
|
2004-07-30 17:34:29 +02:00
|
|
|
def is_identity_dirty(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
return lassomod.lasso_profile_is_identity_dirty(self.parent)
|
|
|
|
identity_dirty = property(is_identity_dirty)
|
2004-07-30 17:34:29 +02:00
|
|
|
|
|
|
|
def is_session_dirty(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
return lassomod.lasso_profile_is_session_dirty(self.parent)
|
|
|
|
session_dirty = property(is_session_dirty)
|
2004-07-30 17:34:29 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
# Methods
|
2004-07-30 17:34:29 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def dump(self):
|
|
|
|
return lassomod.lasso_profile_dump(self.parent)
|
2004-07-26 20:07:52 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def set_identity_from_dump(self, dump):
|
|
|
|
lassomod.lasso_profile_set_identity_from_dump(self.parent, dump)
|
2004-07-30 17:34:29 +02:00
|
|
|
|
|
|
|
def set_session_from_dump(self, dump):
|
2004-08-20 00:36:50 +02:00
|
|
|
lassomod.lasso_profile_set_session_from_dump(self.parent, dump)
|
|
|
|
|
|
|
|
|
|
|
|
class Login(_ObjectMixin, lassomod.LassoLogin, _ProfileChild):
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
2004-08-20 00:36:50 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
lassomodClass = lassomod.LassoLogin
|
|
|
|
|
|
|
|
# Constructors
|
2004-07-10 03:33:56 +02:00
|
|
|
|
2004-08-04 12:10:10 +02:00
|
|
|
def new_from_dump(cls, server, dump):
|
2004-08-20 00:36:50 +02:00
|
|
|
self = lassomod.lasso_login_new_from_dump(server, dump)
|
|
|
|
if self is None:
|
2004-08-04 21:06:12 +02:00
|
|
|
raise ErrorInstanceCreationFailed('lasso_login_new_from_dump')
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(self)
|
2004-08-20 00:36:50 +02:00
|
|
|
return self
|
2004-07-12 00:29:40 +02:00
|
|
|
new_from_dump = classmethod(new_from_dump)
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
# Methods
|
|
|
|
|
2004-07-30 14:02:28 +02:00
|
|
|
def accept_sso(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_accept_sso(self)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_accept_sso')
|
2004-07-30 14:02:28 +02:00
|
|
|
|
2004-07-10 03:33:56 +02:00
|
|
|
def build_artifact_msg(self, authentication_result, authenticationMethod,
|
|
|
|
reauthenticateOnOrAfter, method):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_build_artifact_msg(
|
2004-08-04 21:55:17 +02:00
|
|
|
self, authentication_result, authenticationMethod, reauthenticateOnOrAfter, method)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_build_artifact_msg')
|
2004-07-10 03:33:56 +02:00
|
|
|
|
2004-08-20 19:43:07 +02:00
|
|
|
def build_authn_request_msg(self, remote_providerID, http_method):
|
|
|
|
errorCode = lassomod.lasso_login_build_authn_request_msg(
|
|
|
|
self, remote_providerID, http_method)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_build_authn_request_msg')
|
2004-07-10 03:33:56 +02:00
|
|
|
|
2004-07-12 00:29:40 +02:00
|
|
|
def build_authn_response_msg(self, authentication_result, authenticationMethod,
|
|
|
|
reauthenticateOnOrAfter):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_build_authn_response_msg(
|
2004-08-04 21:55:17 +02:00
|
|
|
self, authentication_result, authenticationMethod, reauthenticateOnOrAfter)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_build_authn_response_msg')
|
2004-07-12 00:29:40 +02:00
|
|
|
|
2004-07-11 02:18:26 +02:00
|
|
|
def build_request_msg(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_build_request_msg(self)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_build_request_msg')
|
2004-07-11 02:18:26 +02:00
|
|
|
|
2004-07-12 00:29:40 +02:00
|
|
|
def dump(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
return lassomod.lasso_login_dump(self)
|
2004-07-12 00:29:40 +02:00
|
|
|
|
2004-08-09 16:55:59 +02:00
|
|
|
def init_authn_request(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_init_authn_request(self)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_init_authn_request')
|
2004-07-10 03:33:56 +02:00
|
|
|
|
2004-08-20 19:43:07 +02:00
|
|
|
def init_from_authn_request_msg(self, authn_request_msg, authn_request_http_method):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_init_from_authn_request_msg(
|
2004-08-20 19:43:07 +02:00
|
|
|
self, authn_request_msg, authn_request_http_method)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_init_from_authn_request_msg')
|
2004-07-11 01:01:05 +02:00
|
|
|
|
2004-08-20 19:43:07 +02:00
|
|
|
def init_request(self, response_msg, response_http_method):
|
|
|
|
errorCode = lassomod.lasso_login_init_request(self, response_msg, response_http_method)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_init_request')
|
2004-07-11 02:18:26 +02:00
|
|
|
|
2004-07-11 01:01:05 +02:00
|
|
|
def must_authenticate(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
return lassomod.lasso_login_must_authenticate(self)
|
2004-07-11 01:01:05 +02:00
|
|
|
|
2004-07-14 15:29:42 +02:00
|
|
|
def process_authn_response_msg(self, authn_response_msg):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_process_authn_response_msg(self, authn_response_msg)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_process_authn_response_msg')
|
2004-07-14 15:29:42 +02:00
|
|
|
|
|
|
|
def process_request_msg(self, request_msg):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_process_request_msg(self, request_msg)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_process_request_msg')
|
2004-07-14 15:29:42 +02:00
|
|
|
|
2004-07-14 19:32:56 +02:00
|
|
|
def process_response_msg(self, response_msg):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_login_process_response_msg(self, response_msg)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_login_process_response_msg')
|
2004-07-14 15:29:42 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
registerClass(Login)
|
|
|
|
|
2004-07-10 03:33:56 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
class Logout(_ObjectMixin, lassomod.LassoLogout, _ProfileChild):
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
2004-08-20 00:36:50 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
lassomodClass = lassomod.LassoLogout
|
2004-08-20 00:36:50 +02:00
|
|
|
|
|
|
|
# Methods
|
2004-07-09 18:30:49 +02:00
|
|
|
|
|
|
|
def build_request_msg(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_logout_build_request_msg(self)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_logout_build_request_msg')
|
2004-07-09 18:30:49 +02:00
|
|
|
|
|
|
|
def build_response_msg(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_logout_build_response_msg(self)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_logout_build_response_msg')
|
2004-07-09 18:30:49 +02:00
|
|
|
|
2004-07-23 16:13:20 +02:00
|
|
|
def get_next_providerID(self):
|
2004-08-20 00:36:50 +02:00
|
|
|
return lassomod.lasso_logout_get_next_providerID(self)
|
2004-07-19 00:37:39 +02:00
|
|
|
|
2004-07-20 18:06:40 +02:00
|
|
|
def init_request(self, remote_providerID = None):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_logout_init_request(self, remote_providerID)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_logout_init_request')
|
2004-07-09 18:30:49 +02:00
|
|
|
|
2004-08-03 17:23:24 +02:00
|
|
|
def process_request_msg(self, request_msg, request_method):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_logout_process_request_msg(self, request_msg, request_method)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_logout_process_request_msg')
|
2004-07-25 11:24:26 +02:00
|
|
|
|
2004-07-14 00:55:20 +02:00
|
|
|
def process_response_msg(self, response_msg, response_method):
|
2004-08-20 00:36:50 +02:00
|
|
|
errorCode = lassomod.lasso_logout_process_response_msg(
|
|
|
|
self, response_msg, response_method)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_logout_process_response_msg')
|
2004-07-19 14:25:35 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def validate_request(self):
|
|
|
|
errorCode = lassomod.lasso_logout_validate_request(self)
|
2004-08-04 21:55:17 +02:00
|
|
|
if errorCode:
|
2004-08-20 00:36:50 +02:00
|
|
|
raise newError(errorCode, 'lasso_logout_validate_request')
|
2004-07-20 11:25:48 +02:00
|
|
|
|
2004-08-20 13:24:02 +02:00
|
|
|
registerClass(Logout)
|
|
|
|
|
2004-07-20 11:25:48 +02:00
|
|
|
|
2004-08-20 02:13:35 +02:00
|
|
|
class Lecp(_ObjectMixin, lassomod.LassoLecp):
|
2004-08-20 13:24:02 +02:00
|
|
|
# Constants
|
|
|
|
|
|
|
|
lassomodClass = lassomod.LassoLecp
|
|
|
|
|
2004-08-20 02:13:35 +02:00
|
|
|
# Attributes
|
|
|
|
|
|
|
|
def get_msg_body(self):
|
2004-08-20 13:24:02 +02:00
|
|
|
return self.parent.msg_body
|
2004-08-20 02:13:35 +02:00
|
|
|
msg_body = property(get_msg_body)
|
|
|
|
|
|
|
|
def get_msg_url(self):
|
2004-08-20 13:24:02 +02:00
|
|
|
return self.parent.msg_url
|
2004-08-20 02:13:35 +02:00
|
|
|
msg_url = property(get_msg_url)
|
|
|
|
|
|
|
|
def get_request(self):
|
2004-08-20 13:31:58 +02:00
|
|
|
return self.parent.request
|
2004-08-20 02:13:35 +02:00
|
|
|
request = property(get_request)
|
|
|
|
|
|
|
|
def get_request_type(self):
|
2004-08-20 13:24:02 +02:00
|
|
|
return self.parent.request_type
|
2004-08-20 02:13:35 +02:00
|
|
|
request_type = property(get_request_type)
|
|
|
|
|
|
|
|
# Constructors
|
|
|
|
|
|
|
|
def new_from_dump(cls, server, dump):
|
|
|
|
self = lassomod.lasso_lecp_new_from_dump(server, dump)
|
|
|
|
if self is None:
|
|
|
|
raise ErrorInstanceCreationFailed('lasso_lecp_new_from_dump')
|
2004-08-20 13:24:02 +02:00
|
|
|
_setRegisteredClass(self)
|
2004-08-20 02:13:35 +02:00
|
|
|
return self
|
|
|
|
new_from_dump = classmethod(new_from_dump)
|
|
|
|
|
|
|
|
# Methods
|
|
|
|
|
|
|
|
def build_authn_request_envelope_msg(self):
|
|
|
|
errorCode = lassomod.lasso_lecp_build_authn_request_envelope_msg(self)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_build_authn_request_envelope_msg')
|
|
|
|
|
|
|
|
def build_authn_request_msg(self, remote_providerID):
|
|
|
|
errorCode = lassomod.lasso_lecp_build_authn_request_msg(self, remote_providerID)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_build_authn_request_msg')
|
|
|
|
|
|
|
|
def build_authn_response_envelope_msg(self, authentication_result, authenticationMethod,
|
|
|
|
reauthenticateOnOrAfter):
|
|
|
|
errorCode = lassomod.lasso_lecp_build_authn_response_envelope_msg(
|
|
|
|
self, authentication_result, authenticationMethod, reauthenticateOnOrAfter)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_build_authn_response_envelope_msg')
|
|
|
|
|
|
|
|
def build_authn_response_msg(self):
|
|
|
|
errorCode = lassomod.lasso_lecp_build_authn_response_msg(self)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_build_authn_response_msg')
|
|
|
|
|
|
|
|
def init_authn_request(self):
|
|
|
|
errorCode = lassomod.lasso_lecp_init_authn_request(self)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_init_authn_request')
|
|
|
|
|
|
|
|
def init_from_authn_request_msg(self, authn_request_msg, authn_request_method):
|
|
|
|
errorCode = lassomod.lasso_lecp_init_from_authn_request_msg(
|
|
|
|
self, authn_request_msg, authn_request_method)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_init_from_authn_request_msg')
|
|
|
|
|
|
|
|
def process_authn_request_envelope_msg(self, request_msg):
|
|
|
|
errorCode = lassomod.lasso_lecp_process_authn_request_envelope_msg(self, request_msg)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_process_authn_request_envelope_msg')
|
|
|
|
|
|
|
|
def process_authn_response_envelope_msg(self, response_msg):
|
|
|
|
errorCode = lassomod.lasso_lecp_process_authn_response_envelope_msg(self, response_msg)
|
|
|
|
if errorCode:
|
|
|
|
raise newError(errorCode, 'lasso_lecp_process_authn_response_envelope_msg')
|
|
|
|
|
|
|
|
def set_identity_from_dump(self, dump):
|
2004-08-20 13:31:58 +02:00
|
|
|
return self.parent.set_identity_from_dump(dump)
|
2004-08-20 02:13:35 +02:00
|
|
|
|
|
|
|
def set_session_from_dump(self, dump):
|
2004-08-20 13:31:58 +02:00
|
|
|
return self.parent.set_session_from_dump(dump)
|
2004-08-20 13:24:02 +02:00
|
|
|
|
|
|
|
registerClass(Lecp)
|
|
|
|
|
|
|
|
|
|
|
|
get_request_type_from_soap_msg = lassomod.lasso_profile_get_request_type_from_soap_msg
|
2004-08-20 02:13:35 +02:00
|
|
|
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
################################################################################
|
|
|
|
# Module Initialization
|
|
|
|
################################################################################
|
2004-07-20 11:25:48 +02:00
|
|
|
|
2004-08-04 17:04:38 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
_initialized = False
|
2004-07-30 17:36:55 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def init():
|
|
|
|
"""Initialize Lasso library."""
|
|
|
|
global _initialized
|
|
|
|
if _initialized:
|
|
|
|
raise ErrorLassoAlreadyInitialized()
|
|
|
|
_initialized = True
|
|
|
|
lassomod.lasso_init()
|
2004-07-25 11:24:26 +02:00
|
|
|
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
def shutdown():
|
|
|
|
"""Shutdown Lasso Library."""
|
|
|
|
global _initialized
|
|
|
|
if not _initialized:
|
|
|
|
raise ErrorLassoNotInitialized()
|
|
|
|
_initialized = False
|
|
|
|
lassomod.lasso_shutdown()
|
2004-07-25 11:24:26 +02:00
|
|
|
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
################################################################################
|
|
|
|
# Module Test
|
|
|
|
################################################################################
|
2004-08-04 21:55:17 +02:00
|
|
|
|
2004-08-02 19:26:28 +02:00
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import os
|
2004-08-02 19:26:28 +02:00
|
|
|
|
|
|
|
init()
|
2004-08-20 16:47:40 +02:00
|
|
|
|
|
|
|
# Lasso constants have two forms.
|
|
|
|
assert libNameIDPolicyTypeFederated == libNameIDPolicyTypes['federated']
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
dataDirectoryPath = '../tests/data'
|
|
|
|
server = Server(
|
|
|
|
os.path.join(dataDirectoryPath, 'sp1-la/metadata.xml'),
|
|
|
|
os.path.join(dataDirectoryPath, 'sp1-la/public-key.pem'),
|
|
|
|
os.path.join(dataDirectoryPath, 'sp1-la/private-key-raw.pem'),
|
|
|
|
os.path.join(dataDirectoryPath, 'sp1-la/certificate.pem'),
|
|
|
|
signatureMethodRsaSha1)
|
|
|
|
server.add_provider(
|
|
|
|
os.path.join(dataDirectoryPath, 'idp1-la/metadata.xml'),
|
|
|
|
os.path.join(dataDirectoryPath, 'idp1-la/public-key.pem'),
|
|
|
|
os.path.join(dataDirectoryPath, 'idp1-la/certificate.pem'))
|
2004-08-20 13:24:02 +02:00
|
|
|
|
|
|
|
# We override one of the binding classes.
|
|
|
|
class MyAuthnRequest(AuthnRequest):
|
|
|
|
def __repr__(self):
|
|
|
|
return 'This is my own class for AuthnRequest!'
|
|
|
|
registerClass(MyAuthnRequest)
|
|
|
|
|
2004-08-20 00:36:50 +02:00
|
|
|
login = Login(server)
|
|
|
|
login.init_authn_request()
|
2004-08-20 13:24:02 +02:00
|
|
|
print 'Class overriding works:', login.request
|
2004-08-20 00:36:50 +02:00
|
|
|
login.request.set_isPassive(False)
|
2004-08-20 11:37:47 +02:00
|
|
|
login.request.set_nameIDPolicy(libNameIDPolicyTypeFederated)
|
|
|
|
login.request.set_consent(libConsentObtained)
|
2004-08-20 19:43:07 +02:00
|
|
|
login.build_authn_request_msg('https://idp1/metadata', httpMethodRedirect)
|
2004-08-20 13:24:02 +02:00
|
|
|
print 'Redirect URL =', login.msg_url
|
2004-08-20 00:36:50 +02:00
|
|
|
shutdown()
|
|
|
|
else:
|
|
|
|
if not _initialized:
|
|
|
|
init()
|