summaryrefslogtreecommitdiffstats
path: root/python/examples/logout.py
blob: b8e86431d6c18499449123322fa1e82f2b377dc0 (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
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
#! /usr/bin/env python

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

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

sp1user_dump = "<LassoUser><LassoAssertions><LassoAssertion RemoteProviderID=\"https://identity-provider:2003/liberty-alliance/metadata\"><Assertion AssertionID=\"C9DS8CD7CSD6CDSCKDKCS\"></Assertion></LassoAssertion></LassoAssertions><LassoIdentities><LassoIdentity RemoteProviderID=\"https://identity-provider:2003/liberty-alliance/metadata\"><LassoRemoteNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">11111111111111111111111111</NameIdentifier></LassoRemoteNameIdentifier></LassoIdentity></LassoIdentities></LassoUser>"

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

sp2user_dump = "<LassoUser><LassoAssertions><LassoAssertion RemoteProviderID=\"https://identity-provider:2003/liberty-alliance/metadata\"><Assertion AssertionID=\"4IK43JCJSDCSDKCSCSDL\"></Assertion></LassoAssertion></LassoAssertions><LassoIdentities><LassoIdentity RemoteProviderID=\"https://identity-provider:2003/liberty-alliance/metadata\"><LassoRemoteNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">222222222222222222222222</NameIdentifier></LassoRemoteNameIdentifier></LassoIdentity></LassoIdentities></LassoUser>"

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

idpuser_dump = "<LassoUser><LassoAssertions><LassoAssertion RemoteProviderID=\"https://service-provider1:2003/liberty-alliance/metadata\"><Assertion AssertionID=\"C9DS8CD7CSD6CDSCKDKCS\"></Assertion></LassoAssertion><LassoAssertion RemoteProviderID=\"https://service-provider2:2003/liberty-alliance/metadata\"><Assertion AssertionID=\"4IK43JCJSDCSDKCSCSDL\"></Assertion></LassoAssertion></LassoAssertions><LassoIdentities><LassoIdentity RemoteProviderID=\"https://service-provider1:2003/liberty-alliance/metadata\"><LassoLocalNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">11111111111111111111111111</NameIdentifier></LassoLocalNameIdentifier></LassoIdentity><LassoIdentity RemoteProviderID=\"https://service-provider2:2003/liberty-alliance/metadata\"><LassoLocalNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">222222222222222222222222</NameIdentifier></LassoLocalNameIdentifier></LassoIdentity></LassoIdentities></LassoUser>"



# SP1 build a request :
sp1user = lasso.User.new_from_dump(sp1user_dump)

sp1logout = lasso.Logout.new(sp1server, lasso.providerTypeSp)

sp1logout.set_user_from_dump(sp1user_dump)

sp1logout.init_request()

request = sp1logout.request
request.set_relayState("http://relaystate.com")

sp1logout.build_request_msg()

msg_url  = sp1logout.msg_url
msg_body = sp1logout.msg_body

sp1logout.destroy()

# IDP process request and return a response :
idpuser = lasso.User.new_from_dump(idpuser_dump)
idplogout = lasso.Logout.new(idpserver, lasso.providerTypeIdp)

if lasso.get_request_type_from_soap_msg(msg_body)==lasso.requestTypeLogout:
    print "it's a logout request !"

#fake response, only for test !
response_msg_body = "<Envelope><LogoutResponse><ProviderID>https://service-provider2:2003/liberty-alliance/metadata</ProviderID><Status><StatusCode Value=\"Samlp:Success\"></StatusCode></Status></LogoutResponse></Envelope>"

idplogout.load_request_msg(msg_body, lasso.httpMethodSoap)
nameIdentifier = idplogout.nameIdentifier
print "get the user dump from NameIdentifier : ", nameIdentifier
idplogout.set_user_from_dump(idpuser_dump)
idplogout.process_request()

print "RelayState :", idplogout.msg_relayState

next_provider_id = idplogout.get_next_providerID()
while next_provider_id:
    idplogout.init_request(next_provider_id)
    idplogout.build_request_msg()

    print "send soap msg to url", idplogout.msg_url
    # remote SP send back a LogoutResponse, process it.
    idplogout.process_response_msg(response_msg_body, lasso.httpMethodSoap)

    next_provider_id = idplogout.get_next_providerID()

idplogout.build_response_msg()

print "End of logout"