0001-code-style-10196.patch
mellon/adapters.py | ||
---|---|---|
1 |
# django-mellon - SAML2 authentication for Django |
|
2 |
# Copyright (C) 2014-2019 Entr'ouvert |
|
3 |
# This program is free software: you can redistribute it and/or modify |
|
4 |
# it under the terms of the GNU Affero General Public License as |
|
5 |
# published by the Free Software Foundation, either version 3 of the |
|
6 |
# License, or (at your option) any later version. |
|
7 | ||
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 | ||
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
1 | 16 |
import logging |
2 | 17 |
import uuid |
3 | 18 |
from xml.etree import ElementTree as ET |
... | ... | |
62 | 77 |
self.logger.error(u'METADATA of %d-th idp has no EntityDescriptor root tag', i) |
63 | 78 |
continue |
64 | 79 | |
65 |
if not 'entityID' in doc.attrib:
|
|
80 |
if 'entityID' not in doc.attrib:
|
|
66 | 81 |
self.logger.error( |
67 | 82 |
u'METADATA of %d-th idp has no entityID attribute on its root tag', i) |
68 | 83 |
continue |
... | ... | |
91 | 106 |
except (AttributeError, KeyError, IndexError) as e: |
92 | 107 |
self.logger.error( |
93 | 108 |
u'invalid reference in username template %r: %s', username_template, e) |
94 |
except Exception as e:
|
|
109 |
except Exception: |
|
95 | 110 |
self.logger.exception(u'unknown error when formatting username') |
96 | 111 |
else: |
97 | 112 |
return username |
mellon/middleware.py | ||
---|---|---|
1 |
# django-mellon - SAML2 authentication for Django |
|
2 |
# Copyright (C) 2014-2019 Entr'ouvert |
|
3 |
# This program is free software: you can redistribute it and/or modify |
|
4 |
# it under the terms of the GNU Affero General Public License as |
|
5 |
# published by the Free Software Foundation, either version 3 of the |
|
6 |
# License, or (at your option) any later version. |
|
7 | ||
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 | ||
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
1 | 16 |
from django.utils.http import urlencode |
2 | 17 |
from django.http import HttpResponseRedirect |
3 | 18 |
from django.core.urlresolvers import reverse |
mellon/models.py | ||
---|---|---|
1 |
# django-mellon - SAML2 authentication for Django |
|
2 |
# Copyright (C) 2014-2019 Entr'ouvert |
|
3 |
# This program is free software: you can redistribute it and/or modify |
|
4 |
# it under the terms of the GNU Affero General Public License as |
|
5 |
# published by the Free Software Foundation, either version 3 of the |
|
6 |
# License, or (at your option) any later version. |
|
7 | ||
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 | ||
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
1 | 16 |
from django.db import models |
2 | 17 |
from django.utils.translation import ugettext_lazy as _ |
3 | 18 |
from django.conf import settings |
mellon/sessions_backends/cached_db.py | ||
---|---|---|
1 |
# django-mellon - SAML2 authentication for Django |
|
2 |
# Copyright (C) 2014-2019 Entr'ouvert |
|
3 |
# This program is free software: you can redistribute it and/or modify |
|
4 |
# it under the terms of the GNU Affero General Public License as |
|
5 |
# published by the Free Software Foundation, either version 3 of the |
|
6 |
# License, or (at your option) any later version. |
|
7 | ||
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 | ||
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
1 | 16 |
from django.contrib.sessions.backends.db import SessionStore |
2 | 17 | |
3 | 18 |
from . import db |
mellon/sessions_backends/db.py | ||
---|---|---|
1 |
# django-mellon - SAML2 authentication for Django |
|
2 |
# Copyright (C) 2014-2019 Entr'ouvert |
|
3 |
# This program is free software: you can redistribute it and/or modify |
|
4 |
# it under the terms of the GNU Affero General Public License as |
|
5 |
# published by the Free Software Foundation, either version 3 of the |
|
6 |
# License, or (at your option) any later version. |
|
7 | ||
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 | ||
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
1 | 16 |
from django.contrib.sessions.backends.db import SessionStore |
2 | 17 | |
3 | 18 |
from mellon import utils |
mellon/utils.py | ||
---|---|---|
1 |
# django-mellon - SAML2 authentication for Django |
|
2 |
# Copyright (C) 2014-2019 Entr'ouvert |
|
3 |
# This program is free software: you can redistribute it and/or modify |
|
4 |
# it under the terms of the GNU Affero General Public License as |
|
5 |
# published by the Free Software Foundation, either version 3 of the |
|
6 |
# License, or (at your option) any later version. |
|
7 | ||
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 | ||
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
1 | 16 |
import logging |
2 | 17 |
import datetime |
3 | 18 |
import importlib |
... | ... | |
29 | 44 |
public_keys.append(public_key) |
30 | 45 |
name_id_formats = app_settings.NAME_ID_FORMATS |
31 | 46 |
return render_to_string('mellon/metadata.xml', { |
32 |
'entity_id': request.build_absolute_uri(entity_id),
|
|
33 |
'login_url': request.build_absolute_uri(login_url),
|
|
34 |
'logout_url': request.build_absolute_uri(logout_url),
|
|
35 |
'public_keys': public_keys,
|
|
36 |
'name_id_formats': name_id_formats,
|
|
37 |
'default_assertion_consumer_binding': app_settings.DEFAULT_ASSERTION_CONSUMER_BINDING,
|
|
38 |
'organization': app_settings.ORGANIZATION,
|
|
39 |
'contact_persons': app_settings.CONTACT_PERSONS,
|
|
40 |
'discovery_endpoint_url': request.build_absolute_uri(reverse('mellon_login')),
|
|
41 |
})
|
|
47 |
'entity_id': request.build_absolute_uri(entity_id), |
|
48 |
'login_url': request.build_absolute_uri(login_url), |
|
49 |
'logout_url': request.build_absolute_uri(logout_url), |
|
50 |
'public_keys': public_keys, |
|
51 |
'name_id_formats': name_id_formats, |
|
52 |
'default_assertion_consumer_binding': app_settings.DEFAULT_ASSERTION_CONSUMER_BINDING, |
|
53 |
'organization': app_settings.ORGANIZATION, |
|
54 |
'contact_persons': app_settings.CONTACT_PERSONS, |
|
55 |
'discovery_endpoint_url': request.build_absolute_uri(reverse('mellon_login')), |
|
56 |
}) |
|
42 | 57 | |
43 | 58 | |
44 | 59 |
def create_server(request): |
... | ... | |
130 | 145 |
This function ignores the sub-second resolution''' |
131 | 146 |
try: |
132 | 147 |
dt = isodate.parse_datetime(date_string) |
133 |
except: |
|
148 |
except (ValueError, TypeError):
|
|
134 | 149 |
return default |
135 | 150 |
if is_aware(dt): |
136 | 151 |
if not settings.USE_TZ: |
... | ... | |
209 | 224 | |
210 | 225 | |
211 | 226 |
def is_nonnull(s): |
212 |
return not '\x00' in s
|
|
227 |
return '\x00' not in s
|
|
213 | 228 | |
214 | 229 | |
215 | 230 |
def same_origin(url1, url2): |
... | ... | |
244 | 259 |
message = lasso_decode(status.statusMessage) |
245 | 260 |
return status_codes, message |
246 | 261 | |
262 | ||
247 | 263 |
def login(request, user): |
248 | 264 |
for adapter in get_adapters(): |
249 | 265 |
if hasattr(adapter, 'auth_login'): |
... | ... | |
254 | 270 | |
255 | 271 | |
256 | 272 |
def get_xml_encoding(content): |
257 |
xml_encoding = 'utf-8' |
|
273 |
xml_encoding = ['utf-8'] |
|
274 | ||
258 | 275 |
def xmlDeclHandler(version, encoding, standalone): |
259 |
xml_encoding = encoding |
|
276 |
xml_encoding[0] = encoding
|
|
260 | 277 |
parser = expat.ParserCreate() |
261 | 278 |
parser.XmlDeclHandler = xmlDeclHandler |
262 | 279 |
parser.Parse(content, True) |
263 |
return xml_encoding |
|
280 |
return xml_encoding[0]
|
|
264 | 281 | |
265 | 282 | |
266 | 283 |
def get_local_path(request, url): |
mellon/views.py | ||
---|---|---|
1 |
# django-mellon - SAML2 authentication for Django |
|
2 |
# Copyright (C) 2014-2019 Entr'ouvert |
|
3 |
# This program is free software: you can redistribute it and/or modify |
|
4 |
# it under the terms of the GNU Affero General Public License as |
|
5 |
# published by the Free Software Foundation, either version 3 of the |
|
6 |
# License, or (at your option) any later version. |
|
7 | ||
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU Affero General Public License for more details. |
|
12 | ||
13 |
# You should have received a copy of the GNU Affero General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | ||
1 | 16 |
import logging |
2 | 17 |
import requests |
3 | 18 |
import lasso |
4 |
- |