Skip to content

Commit 644b77e

Browse files
author
rohe
committed
Merge branch 'master' of github.com:rohe/pysaml2
2 parents 138edca + 6c8e086 commit 644b77e

File tree

3 files changed

+68
-48
lines changed

3 files changed

+68
-48
lines changed

example/idp2/idp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,6 @@ def application(environ, start_response):
10351035
# ----------------------------------------------------------------------------
10361036

10371037
if __name__ == '__main__':
1038-
from wsgiref.simple_server import make_server
1039-
10401038
parser = argparse.ArgumentParser()
10411039
parser.add_argument('-p', dest='path', help='Path to configuration file.')
10421040
parser.add_argument('-v', dest='valid',

src/saml2/httpbase.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class HTTPError(SAMLError):
5959
pass
6060

6161

62+
TIME_FORMAT = ["%d-%b-%Y %H:%M:%S %Z", "%d-%b-%y %H:%M:%S %Z",
63+
"%d %b %Y %H:%M:%S %Z"]
64+
65+
6266
def _since_epoch(cdate):
6367
"""
6468
:param cdate: date format 'Wed, 06-Jun-2012 01:34:34 GMT'
@@ -70,20 +74,20 @@ def _since_epoch(cdate):
7074
return utc_now()
7175

7276
cdate = cdate[5:] # assume short weekday, i.e. do not support obsolete RFC 1036 date format
73-
try:
74-
t = time.strptime(cdate, "%d-%b-%Y %H:%M:%S %Z") # e.g. 18-Apr-2014 12:30:51 GMT
75-
except ValueError:
77+
t = -1
78+
for time_format in TIME_FORMAT :
7679
try:
77-
t = time.strptime(cdate, "%d-%b-%y %H:%M:%S %Z") # e.g. 18-Apr-14 12:30:51 GMT
80+
t = time.strptime(cdate, time_format) # e.g. 18-Apr-2014 12:30:51 GMT
7881
except ValueError:
79-
try:
80-
t = time.strptime(cdate, "%d %b %Y %H:%M:%S %Z") # e.g. 18 Apr 2014 12:30:51 GMT
81-
except ValueError:
82-
raise (Exception, 'ValueError: Date "{0}" does not match any of '.format(cdate) + \
83-
'"%d-%b-%Y %H:%M:%S %Z", ' + \
84-
'"%d-%b-%y %H:%M:%S %Z", ' + \
85-
'"%d %b %Y %H:%M:%S %Z".')
86-
#return int(time.mktime(t))
82+
pass
83+
else:
84+
break
85+
86+
if t == -1:
87+
raise (Exception,
88+
'ValueError: Date "{0}" does not match any of: {1}'.format(
89+
cdate,TIME_FORMAT))
90+
8791
return calendar.timegm(t)
8892

8993

@@ -199,7 +203,7 @@ def set_cookie(self, kaka, request):
199203
name=std_attr["name"])
200204
except ValueError:
201205
pass
202-
elif morsel["expires"] and morsel["expires"] < utc_now():
206+
elif std_attr["expires"] and std_attr["expires"] < utc_now():
203207
try:
204208
self.cookiejar.clear(domain=std_attr["domain"],
205209
path=std_attr["path"],

src/saml2/samlp.py

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def status_detail_type__from_string(xml_string):
9898

9999

100100
class AuthnContextComparisonType_(SamlBase):
101-
"""The urn:oasis:names:tc:SAML:2.0:protocol:AuthnContextComparisonType element """
101+
"""The urn:oasis:names:tc:SAML:2.0:protocol:AuthnContextComparisonType
102+
element """
102103

103104
c_tag = 'AuthnContextComparisonType'
104105
c_namespace = NAMESPACE
@@ -135,12 +136,12 @@ def __init__(self,
135136
text=None,
136137
extension_elements=None,
137138
extension_attributes=None,
138-
):
139+
):
139140
SamlBase.__init__(self,
140141
text=text,
141142
extension_elements=extension_elements,
142143
extension_attributes=extension_attributes,
143-
)
144+
)
144145
self.format = format
145146
self.sp_name_qualifier = sp_name_qualifier
146147
self.allow_create = allow_create
@@ -375,7 +376,9 @@ def __init__(self,
375376

376377

377378
class AssertionIDRequestType_(RequestAbstractType_):
378-
"""The urn:oasis:names:tc:SAML:2.0:protocol:AssertionIDRequestType element """
379+
"""
380+
The urn:oasis:names:tc:SAML:2.0:protocol:AssertionIDRequestType element
381+
"""
379382

380383
c_tag = 'AssertionIDRequestType'
381384
c_namespace = NAMESPACE
@@ -422,16 +425,18 @@ def assertion_id_request_type__from_string(xml_string):
422425

423426

424427
class SubjectQueryAbstractType_(RequestAbstractType_):
425-
"""The urn:oasis:names:tc:SAML:2.0:protocol:SubjectQueryAbstractType element """
428+
"""
429+
The urn:oasis:names:tc:SAML:2.0:protocol:SubjectQueryAbstractType element
430+
"""
426431

427432
c_tag = 'SubjectQueryAbstractType'
428433
c_namespace = NAMESPACE
429434
c_children = RequestAbstractType_.c_children.copy()
430435
c_attributes = RequestAbstractType_.c_attributes.copy()
431436
c_child_order = RequestAbstractType_.c_child_order[:]
432437
c_cardinality = RequestAbstractType_.c_cardinality.copy()
433-
c_children['{urn:oasis:names:tc:SAML:2.0:assertion}Subject'] = ('subject',
434-
saml.Subject)
438+
c_children['{urn:oasis:names:tc:SAML:2.0:assertion}Subject'] = (
439+
'subject', saml.Subject)
435440
c_child_order.extend(['subject'])
436441

437442
def __init__(self,
@@ -463,7 +468,8 @@ def __init__(self,
463468

464469

465470
class RequestedAuthnContextType_(SamlBase):
466-
"""The urn:oasis:names:tc:SAML:2.0:protocol:RequestedAuthnContextType element """
471+
"""The urn:oasis:names:tc:SAML:2.0:protocol:RequestedAuthnContextType
472+
element """
467473

468474
c_tag = 'RequestedAuthnContextType'
469475
c_namespace = NAMESPACE
@@ -473,8 +479,8 @@ class RequestedAuthnContextType_(SamlBase):
473479
c_cardinality = SamlBase.c_cardinality.copy()
474480
c_children[
475481
'{urn:oasis:names:tc:SAML:2.0:assertion}AuthnContextClassRef'] = (
476-
'authn_context_class_ref',
477-
[saml.AuthnContextClassRef])
482+
'authn_context_class_ref',
483+
[saml.AuthnContextClassRef])
478484
c_cardinality['authn_context_class_ref'] = {"min": 0}
479485
c_children['{urn:oasis:names:tc:SAML:2.0:assertion}AuthnContextDeclRef'] = (
480486
'authn_context_decl_ref',
@@ -555,7 +561,8 @@ def attribute_query_type__from_string(xml_string):
555561

556562

557563
class AuthzDecisionQueryType_(SubjectQueryAbstractType_):
558-
"""The urn:oasis:names:tc:SAML:2.0:protocol:AuthzDecisionQueryType element """
564+
"""The urn:oasis:names:tc:SAML:2.0:protocol:AuthzDecisionQueryType
565+
element """
559566

560567
c_tag = 'AuthzDecisionQueryType'
561568
c_namespace = NAMESPACE
@@ -863,7 +870,9 @@ def subject_query_from_string(xml_string):
863870

864871

865872
class RequestedAuthnContext(RequestedAuthnContextType_):
866-
"""The urn:oasis:names:tc:SAML:2.0:protocol:RequestedAuthnContext element """
873+
"""
874+
The urn:oasis:names:tc:SAML:2.0:protocol:RequestedAuthnContext element
875+
"""
867876

868877
c_tag = 'RequestedAuthnContext'
869878
c_namespace = NAMESPACE
@@ -958,7 +967,9 @@ def artifact_resolve_from_string(xml_string):
958967

959968

960969
class ManageNameIDRequestType_(RequestAbstractType_):
961-
"""The urn:oasis:names:tc:SAML:2.0:protocol:ManageNameIDRequestType element """
970+
"""
971+
The urn:oasis:names:tc:SAML:2.0:protocol:ManageNameIDRequestType element
972+
"""
962973

963974
c_tag = 'ManageNameIDRequestType'
964975
c_namespace = NAMESPACE
@@ -1090,19 +1101,20 @@ def __init__(self,
10901101
text=None,
10911102
extension_elements=None,
10921103
extension_attributes=None):
1093-
SubjectQueryAbstractType_.__init__(self,
1094-
subject=subject,
1095-
issuer=issuer,
1096-
signature=signature,
1097-
extensions=extensions,
1098-
id=id,
1099-
version=version,
1100-
issue_instant=issue_instant,
1101-
destination=destination,
1102-
consent=consent,
1103-
text=text,
1104-
extension_elements=extension_elements,
1105-
extension_attributes=extension_attributes)
1104+
SubjectQueryAbstractType_.__init__(
1105+
self,
1106+
subject=subject,
1107+
issuer=issuer,
1108+
signature=signature,
1109+
extensions=extensions,
1110+
id=id,
1111+
version=version,
1112+
issue_instant=issue_instant,
1113+
destination=destination,
1114+
consent=consent,
1115+
text=text,
1116+
extension_elements=extension_elements,
1117+
extension_attributes=extension_attributes)
11061118
self.requested_authn_context = requested_authn_context
11071119
self.session_index = session_index
11081120

@@ -1293,7 +1305,8 @@ def __init__(self,
12931305
self.protocol_binding = protocol_binding
12941306
self.assertion_consumer_service_index = assertion_consumer_service_index
12951307
self.assertion_consumer_service_url = assertion_consumer_service_url
1296-
self.attribute_consuming_service_index = attribute_consuming_service_index
1308+
self.attribute_consuming_service_index = \
1309+
attribute_consuming_service_index
12971310
self.provider_name = provider_name
12981311

12991312

@@ -1326,7 +1339,7 @@ class StatusType_(SamlBase):
13261339
c_child_order = SamlBase.c_child_order[:]
13271340
c_cardinality = SamlBase.c_cardinality.copy()
13281341
# Added further down to avoid undefined references
1329-
#c_children['{urn:oasis:names:tc:SAML:2.0:protocol}StatusCode'] = (
1342+
# c_children['{urn:oasis:names:tc:SAML:2.0:protocol}StatusCode'] = (
13301343
# 'status_code', StatusCode)
13311344
c_children['{urn:oasis:names:tc:SAML:2.0:protocol}StatusMessage'] = (
13321345
'status_message', StatusMessage)
@@ -1535,7 +1548,9 @@ def logout_response_from_string(xml_string):
15351548

15361549

15371550
class NameIDMappingResponseType_(StatusResponseType_):
1538-
"""The urn:oasis:names:tc:SAML:2.0:protocol:NameIDMappingResponseType element """
1551+
"""
1552+
The urn:oasis:names:tc:SAML:2.0:protocol:NameIDMappingResponseType element
1553+
"""
15391554

15401555
c_tag = 'NameIDMappingResponseType'
15411556
c_namespace = NAMESPACE
@@ -1621,7 +1636,8 @@ def artifact_response_from_string(xml_string):
16211636

16221637

16231638
class NameIDMappingResponse(NameIDMappingResponseType_):
1624-
"""The urn:oasis:names:tc:SAML:2.0:protocol:NameIDMappingResponse element """
1639+
"""The urn:oasis:names:tc:SAML:2.0:protocol:NameIDMappingResponse element
1640+
"""
16251641

16261642
c_tag = 'NameIDMappingResponse'
16271643
c_namespace = NAMESPACE
@@ -1635,7 +1651,7 @@ def name_id_mapping_response_from_string(xml_string):
16351651
return saml2.create_class_from_xml_string(NameIDMappingResponse, xml_string)
16361652

16371653

1638-
#..................
1654+
# ..................
16391655
# ['StatusCodeType', 'StatusCode']
16401656
class StatusCodeType_(SamlBase):
16411657
"""The urn:oasis:names:tc:SAML:2.0:protocol:StatusCodeType element """
@@ -1713,7 +1729,8 @@ def status_code_from_string(xml_string):
17131729
AuthnQueryType_.c_tag: authn_query_type__from_string,
17141730
RequestedAuthnContext.c_tag: requested_authn_context_from_string,
17151731
RequestedAuthnContextType_.c_tag: requested_authn_context_type__from_string,
1716-
AuthnContextComparisonType_.c_tag: authn_context_comparison_type__from_string,
1732+
AuthnContextComparisonType_.c_tag:
1733+
authn_context_comparison_type__from_string,
17171734
AttributeQuery.c_tag: attribute_query_from_string,
17181735
AttributeQueryType_.c_tag: attribute_query_type__from_string,
17191736
AuthzDecisionQuery.c_tag: authz_decision_query_from_string,
@@ -1751,7 +1768,8 @@ def status_code_from_string(xml_string):
17511768
NameIDMappingRequest.c_tag: name_id_mapping_request_from_string,
17521769
NameIDMappingRequestType_.c_tag: name_id_mapping_request_type__from_string,
17531770
NameIDMappingResponse.c_tag: name_id_mapping_response_from_string,
1754-
NameIDMappingResponseType_.c_tag: name_id_mapping_response_type__from_string,
1771+
NameIDMappingResponseType_.c_tag:
1772+
name_id_mapping_response_type__from_string,
17551773
}
17561774

17571775
ELEMENT_BY_TAG = {

0 commit comments

Comments
 (0)