summaryrefslogtreecommitdiffstats
path: root/python/examples/logout-from-idp.py
blob: 398b9695e3ab57b4d25179f96ab1bd2b53d3b499 (plain)
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
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.path.insert(0, '../')
import lasso

lasso.init()

# server :
server = lasso.Server.new("../../examples/idp.xml",
			  "../../examples/rsapub.pem", "../../examples/rsakey.pem", "../../examples/rsacert.pem",
			  lasso.signatureMethodRsaSha1)
server.add_provider("../../examples/sp1.xml", None, None)
server.add_provider("../../examples/sp2.xml", None, None)
server.add_provider("../../examples/sp3.xml", None, None)

# user :

sp1_identity = """<LassoIdentity RemoteProviderID="https://service-provider1:2003/liberty-alliance/metadata"><LassoRemoteNameIdentifier><NameIdentifier NameQualifier="https://identity-provider:2003/liberty-alliance/metadata" Format="federated">111111111111111111111111</NameIdentifier></LassoRemoteNameIdentifier><LassoLocalNameIdentifier><NameIdentifier NameQualifier="https://identity-provider:2003/liberty-alliance/metadata" Format="federated">222222222222222222222222</NameIdentifier></LassoLocalNameIdentifier></LassoIdentity>"""
sp1_assertion = """<LassoAssertion RemoteProviderID="https://service-provider1:2003/liberty-alliance/metadata"><Assertion AssertionID="1234567890"></Assertion></LassoAssertion>"""

sp2_identity = """<LassoIdentity RemoteProviderID="https://service-provider2:2003/liberty-alliance/metadata"><LassoRemoteNameIdentifier><NameIdentifier NameQualifier="https://identity-provider:2003/liberty-alliance/metadata" Format="federated">222222222222222222222</NameIdentifier></LassoRemoteNameIdentifier></LassoIdentity>"""
sp2_assertion = """<LassoAssertion RemoteProviderID="https://service-provider2:2003/liberty-alliance/metadata"><Assertion AssertionID="1234567890"></Assertion></LassoAssertion>"""

user_dump = """<LassoUser><LassoAssertions>%s%s</LassoAssertions><LassoIdentities>%s%s</LassoIdentities></LassoUser>""" % (
    sp1_assertion, sp2_assertion, sp1_identity, sp2_identity)
user = lasso.User.new_from_dump(user_dump);


print user.dump()

# requests :
logout = lasso.Logout.new(server, user, lasso.providerTypeIdp);
next_provider_id = user.get_next_assertion_remote_providerID();
while(next_provider_id):
    assertion = user.get_assertion(next_provider_id)

    logout.init_request(next_provider_id)
    logout.build_request_msg();

    # send the request with logout.msg_url and logout.msg_body
    print 'url : ', logout.msg_url
    print 'body : ', logout.msg_body

    user.remove_assertion(next_provider_id)
    next_provider_id = user.get_next_assertion_remote_providerID()

print "End of logout ..."
print "Dump of user environ :"
print user.dump()

user.destroy()

logout.destroy()