1
- #!/usr/bin/env python
1
+ # !/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
3
#
4
- # Copyright (C) 2009-2011 Umeå University
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
4
18
5
"""Contains classes and functions that a SAML2.0 Service Provider (SP) may use
19
6
to conclude its tasks.
26
13
from saml2 import BINDING_HTTP_POST
27
14
from saml2 import BINDING_SOAP
28
15
29
- from saml2 .ident import decode
16
+ from saml2 .ident import decode , code
30
17
from saml2 .httpbase import HTTPError
31
18
from saml2 .s_utils import sid
32
19
from saml2 .s_utils import status_message_factory
48
35
from cgi import parse_qs
49
36
50
37
import logging
38
+
51
39
logger = logging .getLogger (__name__ )
52
40
53
41
@@ -118,7 +106,7 @@ def global_logout(self, name_id, reason="", expire=None, sign=None):
118
106
# find out which IdPs/AAs I should notify
119
107
entity_ids = self .users .issuers_of_info (name_id )
120
108
return self .do_logout (name_id , entity_ids , reason , expire , sign )
121
-
109
+
122
110
def do_logout (self , name_id , entity_ids , reason , expire , sign = None ,
123
111
expected_binding = None ):
124
112
"""
@@ -138,7 +126,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
138
126
# Do the local logout anyway
139
127
self .local_logout (name_id )
140
128
return 0 , "504 Gateway Timeout" , [], []
141
-
129
+
142
130
not_done = entity_ids [:]
143
131
responses = {}
144
132
@@ -165,7 +153,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
165
153
req_id , request = self .create_logout_request (
166
154
destination , entity_id , name_id = name_id , reason = reason ,
167
155
expire = expire )
168
-
156
+
169
157
#to_sign = []
170
158
if binding .startswith ("http://" ):
171
159
sign = True
@@ -197,12 +185,12 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
197
185
198
186
else :
199
187
self .state [req_id ] = {"entity_id" : entity_id ,
200
- "operation" : "SLO" ,
201
- "entity_ids" : entity_ids ,
202
- "name_id" : name_id ,
203
- "reason" : reason ,
204
- "not_on_of_after" : expire ,
205
- "sign" : sign }
188
+ "operation" : "SLO" ,
189
+ "entity_ids" : entity_ids ,
190
+ "name_id" : code ( name_id ) ,
191
+ "reason" : reason ,
192
+ "not_on_of_after" : expire ,
193
+ "sign" : sign }
206
194
207
195
responses [entity_id ] = (binding , http_info )
208
196
not_done .remove (entity_id )
@@ -213,7 +201,7 @@ def do_logout(self, name_id, entity_ids, reason, expire, sign=None,
213
201
if not_done :
214
202
# upstream should try later
215
203
raise LogoutError ("%s" % (entity_ids ,))
216
-
204
+
217
205
return responses
218
206
219
207
def local_logout (self , name_id ):
@@ -231,7 +219,7 @@ def is_logged_in(self, name_id):
231
219
"""
232
220
identity = self .users .get_identity (name_id )[0 ]
233
221
return bool (identity )
234
-
222
+
235
223
def handle_logout_response (self , response ):
236
224
""" handles a Logout response
237
225
@@ -247,11 +235,12 @@ def handle_logout_response(self, response):
247
235
logger .info ("issuer: %s" % issuer )
248
236
del self .state [response .in_response_to ]
249
237
if status ["entity_ids" ] == [issuer ]: # done
250
- self .local_logout (status ["name_id" ])
238
+ self .local_logout (decode ( status ["name_id" ]) )
251
239
return 0 , "200 Ok" , [("Content-type" , "text/html" )], []
252
240
else :
253
241
status ["entity_ids" ].remove (issuer )
254
- return self .do_logout (status ["name_id" ], status ["entity_ids" ],
242
+ return self .do_logout (decode (status ["name_id" ]),
243
+ status ["entity_ids" ],
255
244
status ["reason" ], status ["not_on_or_after" ],
256
245
status ["sign" ])
257
246
0 commit comments