Skip to content

Commit 164605e

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 8b69c35 + 5332811 commit 164605e

32 files changed

+356
-170
lines changed
File renamed without changes.

example/idp2/idp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ def verify_request(self, query, binding):
225225
:param query: The SAML query, transport encoded
226226
:param binding: Which binding the query came in over
227227
"""
228+
resp_args = {}
228229
if not query:
229230
logger.info("Missing QUERY")
230231
resp = Unauthorized('Unknown user')
231-
return resp(self.environ, self.start_response)
232+
return resp_args, resp(self.environ, self.start_response)
232233

233234
if not self.req_info:
234235
self.req_info = IDP.parse_authn_request(query, binding)

src/saml2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ class Error(Exception):
124124
pass
125125

126126

127+
class SAMLError(Exception):
128+
pass
129+
130+
127131
class ExtensionElement(object):
128132
"""XML which is not part of the SAML specification,
129133
these are called extension elements. If a classes parser

src/saml2/assertion.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,18 @@ def get_attribute_restriction(self, sp_entity_id):
409409

410410
return restrictions
411411

412+
def entity_category_attributes(self, ec):
413+
if not self._restrictions:
414+
return None
415+
416+
ec_maps = self._restrictions["default"]["entity_categories"]
417+
for ec_map in ec_maps:
418+
try:
419+
return ec_map[ec]
420+
except KeyError:
421+
pass
422+
return []
423+
412424
def get_entity_categories_restriction(self, sp_entity_id, mds):
413425
if not self._restrictions:
414426
return None

src/saml2/attribute_converter.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020
from importlib import import_module
2121

2222
from saml2.s_utils import factory, do_ava
23-
from saml2 import saml, extension_elements_to_elements
23+
from saml2 import saml, extension_elements_to_elements, SAMLError
2424
from saml2.saml import NAME_FORMAT_URI
2525

2626

27-
class UnknownNameFormat(Exception):
27+
class UnknownNameFormat(SAMLError):
28+
pass
29+
30+
31+
class ConverterError(SAMLError):
2832
pass
2933

3034

@@ -182,7 +186,7 @@ def d_to_local_name(acs, attr):
182186
try:
183187
return attr["friendly_name"]
184188
except KeyError:
185-
raise Exception("Could not find local name for %s" % attr)
189+
raise ConverterError("Could not find local name for %s" % attr)
186190

187191

188192
class AttributeConverter(object):
@@ -224,7 +228,7 @@ def from_dict(self, mapdict):
224228
pass
225229

226230
if self._fro is None and self._to is None:
227-
raise Exception("Missing specifications")
231+
raise ConverterError("Missing specifications")
228232

229233
if self._fro is None or self._to is None:
230234
self.adjust()

src/saml2/authn.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from urlparse import parse_qs
44
from urlparse import urlsplit
55
import time
6+
from saml2 import SAMLError
67
from saml2.cipher import AES
78
from saml2.httputil import Response
89
from saml2.httputil import make_cookie
@@ -15,7 +16,11 @@
1516
logger = logging.getLogger(__name__)
1617

1718

18-
class AuthnFailure(Exception):
19+
class AuthnFailure(SAMLError):
20+
pass
21+
22+
23+
class EncodeError(SAMLError):
1924
pass
2025

2126

@@ -35,7 +40,7 @@ def verify(self, **kwargs):
3540

3641
def url_encode_params(params=None):
3742
if not isinstance(params, dict):
38-
raise Exception("You must pass in a dictionary!")
43+
raise EncodeError("You must pass in a dictionary!")
3944
params_list = []
4045
for k, v in params.items():
4146
if isinstance(v, list):
@@ -209,7 +214,7 @@ def __init__(self, methods=None):
209214

210215
def __call__(self, **kwargs):
211216
if not self.methods:
212-
raise Exception("No authentication methods defined")
217+
raise SAMLError("No authentication methods defined")
213218
elif len(self.methods) == 1:
214219
return self.methods[0]
215220
else:

src/saml2/cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import shelve
44
from saml2.ident import code, decode
5-
from saml2 import time_util
5+
from saml2 import time_util, SAMLError
66
import logging
77

88
logger = logging.getLogger(__name__)
@@ -12,11 +12,11 @@
1212
# timeout time.
1313

1414

15-
class ToOld(Exception):
15+
class ToOld(SAMLError):
1616
pass
1717

1818

19-
class CacheError(Exception):
19+
class CacheError(SAMLError):
2020
pass
2121

2222

src/saml2/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from saml2.request import LogoutRequest
2222
import saml2
2323

24-
from saml2 import saml
24+
from saml2 import saml, SAMLError
2525
from saml2 import BINDING_HTTP_REDIRECT
2626
from saml2 import BINDING_HTTP_POST
2727
from saml2 import BINDING_SOAP
@@ -386,7 +386,7 @@ def do_attribute_query(self, entityid, subject_id,
386386
else:
387387
srvs = self.metadata.attribute_service(entityid, binding)
388388
if srvs is []:
389-
raise Exception("No attribute service support at entity")
389+
raise SAMLError("No attribute service support at entity")
390390

391391
destination = destinations(srvs)[0]
392392

@@ -412,7 +412,7 @@ def do_attribute_query(self, entityid, subject_id,
412412
return self.apply_binding(binding, "%s" % query, destination,
413413
relay_state)
414414
else:
415-
raise Exception("Unsupported binding")
415+
raise SAMLError("Unsupported binding")
416416

417417
def handle_logout_request(self, request, name_id, binding, sign=False,
418418
relay_state=""):

src/saml2/client_base.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from saml2.s_utils import signature, UnravelError
4646
from saml2.s_utils import do_attributes
4747

48-
from saml2 import samlp, BINDING_SOAP
48+
from saml2 import samlp, BINDING_SOAP, SAMLError
4949
from saml2 import saml
5050
from saml2 import soap
5151
from saml2.population import Population
@@ -79,19 +79,19 @@
7979
MIME_PAOS = "application/vnd.paos+xml"
8080

8181

82-
class IdpUnspecified(Exception):
82+
class IdpUnspecified(SAMLError):
8383
pass
8484

8585

86-
class VerifyError(Exception):
86+
class VerifyError(SAMLError):
8787
pass
8888

8989

90-
class LogoutError(Exception):
90+
class LogoutError(SAMLError):
9191
pass
9292

9393

94-
class NoServiceDefined(Exception):
94+
class NoServiceDefined(SAMLError):
9595
pass
9696

9797

@@ -267,15 +267,16 @@ def create_authn_request(self, destination, vorg="", scoping=None,
267267
allow_create = "false"
268268

269269
# Profile stuff, should be configurable
270-
if nameid_format is None or \
271-
nameid_format == NAMEID_FORMAT_TRANSIENT:
270+
if nameid_format is None:
272271
name_id_policy = samlp.NameIDPolicy(
273272
allow_create=allow_create, format=NAMEID_FORMAT_TRANSIENT)
273+
elif nameid_format == "":
274+
name_id_policy = None
274275
else:
275276
name_id_policy = samlp.NameIDPolicy(allow_create=allow_create,
276277
format=nameid_format)
277278

278-
if vorg:
279+
if name_id_policy and vorg:
279280
try:
280281
name_id_policy.sp_name_qualifier = vorg
281282
name_id_policy.format = saml.NAMEID_FORMAT_PERSISTENT
@@ -502,7 +503,7 @@ def parse_authn_request_response(self, xmlstr, binding, outstanding=None):
502503
try:
503504
_ = self.config.entityid
504505
except KeyError:
505-
raise Exception("Missing entity_id specification")
506+
raise SAMLError("Missing entity_id specification")
506507

507508
resp = None
508509
if xmlstr:
@@ -524,7 +525,7 @@ def parse_authn_request_response(self, xmlstr, binding, outstanding=None):
524525
logger.error("%s" % exc)
525526
raise
526527

527-
logger.debug(">> %s", resp)
528+
#logger.debug(">> %s", resp)
528529

529530
if resp is None:
530531
return None

src/saml2/config.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from importlib import import_module
1212

13-
from saml2 import root_logger, BINDING_URI
13+
from saml2 import root_logger, BINDING_URI, SAMLError
1414
from saml2 import BINDING_SOAP
1515
from saml2 import BINDING_HTTP_REDIRECT
1616
from saml2 import BINDING_HTTP_POST
@@ -60,7 +60,8 @@
6060
"disable_ssl_certificate_validation",
6161
"referred_binding",
6262
"session_storage",
63-
"entity_category"
63+
"entity_category",
64+
"xmlsec_path"
6465
]
6566

6667
SP_ARGS = [
@@ -148,7 +149,7 @@
148149
}
149150

150151

151-
class ConfigurationError(Exception):
152+
class ConfigurationError(SAMLError):
152153
pass
153154

154155
# -----------------------------------------------------------------
@@ -161,6 +162,7 @@ def __init__(self, homedir="."):
161162
self._homedir = homedir
162163
self.entityid = None
163164
self.xmlsec_binary = None
165+
self.xmlsec_path = []
164166
self.debug = False
165167
self.key_file = None
166168
self.cert_file = None
@@ -174,7 +176,7 @@ def __init__(self, homedir="."):
174176
self.organization = None
175177
self.contact_person = None
176178
self.name_form = None
177-
self.nameid_form = None
179+
self.name_id_format = None
178180
self.virtual_organization = None
179181
self.logger = None
180182
self.only_use_keys_in_metadata = True
@@ -239,7 +241,7 @@ def load_complex(self, cnf, typ="", metadata_construction=False):
239241
acs = ac_factory()
240242

241243
if not acs:
242-
raise Exception("No attribute converters, something is wrong!!")
244+
raise ConfigurationError("No attribute converters, something is wrong!!")
243245

244246
_acs = self.getattr("attribute_converters", typ)
245247
if _acs:
@@ -326,7 +328,8 @@ def load_metadata(self, metadata_conf):
326328
acs = self.attribute_converters
327329

328330
if acs is None:
329-
raise Exception("Missing attribute converter specification")
331+
raise ConfigurationError(
332+
"Missing attribute converter specification")
330333

331334
try:
332335
ca_certs = self.ca_certs
@@ -390,7 +393,7 @@ def log_handler(self):
390393
elif args["socktype"] == "stream":
391394
args["socktype"] = socket.SOCK_STREAM
392395
else:
393-
raise Exception("Unknown socktype!")
396+
raise ConfigurationError("Unknown socktype!")
394397
try:
395398
handler = LOG_HANDLER[htyp](**args)
396399
except TypeError: # difference between 2.6 and 2.7

0 commit comments

Comments
 (0)