This commit is contained in:
parent
aa9bdc9cbe
commit
a17efc6f1b
|
@ -135,7 +135,7 @@ class DefaultAdapter:
|
|||
logger.error('invalid METADATA_URL %r: %s', url, e)
|
||||
return
|
||||
if not hostname:
|
||||
logger.error('no hostname in METADATA_URL %r: %s', url)
|
||||
logger.error('no hostname in METADATA_URL %r', url)
|
||||
return
|
||||
|
||||
try:
|
||||
|
@ -359,8 +359,8 @@ class DefaultAdapter:
|
|||
name_id=name_id, issuer=models_utils.get_issuer(entity_id)
|
||||
)
|
||||
# nid_* attributes are new, we must update them if they are not initialized, eventually
|
||||
for key in to_update:
|
||||
if getattr(saml_identifier, key) != to_update[key]:
|
||||
for key, value in to_update.items():
|
||||
if getattr(saml_identifier, key) != value:
|
||||
models.UserSAMLIdentifier.objects.filter(pk=saml_identifier.pk).update(**to_update)
|
||||
break
|
||||
user = saml_identifier.user
|
||||
|
@ -506,8 +506,8 @@ class DefaultAdapter:
|
|||
},
|
||||
)
|
||||
# nid_* attributes are new, we must update them eventually
|
||||
for key in to_update:
|
||||
if getattr(saml_id, key) != to_update[key]:
|
||||
for key, value in to_update.items():
|
||||
if getattr(saml_id, key) != value:
|
||||
models.UserSAMLIdentifier.objects.filter(pk=saml_id.pk).update(**to_update)
|
||||
break
|
||||
if created:
|
||||
|
@ -531,7 +531,7 @@ class DefaultAdapter:
|
|||
value = tpl.format(realm=realm, attributes=saml_attributes, idp=idp)
|
||||
except ValueError:
|
||||
logger.warning('mellon: invalid attribute mapping template %r', tpl)
|
||||
except (AttributeError, KeyError, IndexError, ValueError) as e:
|
||||
except (AttributeError, KeyError, IndexError) as e:
|
||||
logger.warning('mellon: invalid reference in attribute mapping template %r: %s', tpl, e)
|
||||
else:
|
||||
model_field = user._meta.get_field(field)
|
||||
|
@ -591,7 +591,7 @@ class DefaultAdapter:
|
|||
groups = []
|
||||
for value in set(values):
|
||||
if create_group:
|
||||
group, created = Group.objects.get_or_create(name=value)
|
||||
group, _ = Group.objects.get_or_create(name=value)
|
||||
else:
|
||||
try:
|
||||
group = Group.objects.get(name=value)
|
||||
|
|
|
@ -26,5 +26,5 @@ def get_issuer(entity_id):
|
|||
issuer.entity_id = entity_id
|
||||
issuer.save()
|
||||
if not slug or not issuer:
|
||||
issuer, created = models.Issuer.objects.update_or_create(entity_id=entity_id, defaults={'slug': slug})
|
||||
issuer, _ = models.Issuer.objects.update_or_create(entity_id=entity_id, defaults={'slug': slug})
|
||||
return issuer
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from django.contrib.sessions.backends.cached_db import SessionStore as BaseSessionStore
|
||||
|
||||
from . import db
|
||||
|
||||
|
||||
class SessionStore(db.SessionStore, SessionStore):
|
||||
class SessionStore(db.SessionStore, BaseSessionStore):
|
||||
pass
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from django.contrib.sessions.backends.db import SessionStore as BaseSessionStore
|
||||
|
||||
from mellon import utils
|
||||
|
||||
|
||||
class SessionStore(SessionStore):
|
||||
class SessionStore(BaseSessionStore):
|
||||
def get_session_not_on_or_after(self):
|
||||
session_not_on_or_after = self.get('mellon_session', {}).get('session_not_on_or_after')
|
||||
if session_not_on_or_after:
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import django
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
|
|
@ -27,7 +27,6 @@ from django.conf import settings
|
|||
from django.contrib import auth
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import force_str
|
||||
from django.utils.timezone import get_default_timezone, is_aware, make_aware, make_naive, now
|
||||
|
||||
from . import app_settings
|
||||
|
@ -47,7 +46,8 @@ def create_metadata(request):
|
|||
for public_key in app_settings.PUBLIC_KEYS:
|
||||
if public_key.startswith('/'):
|
||||
# clean PEM file
|
||||
content = open(public_key).read()
|
||||
with open(public_key) as fd:
|
||||
content = fd.read()
|
||||
public_key = ''.join(content.splitlines()[1:-1])
|
||||
public_keys.append(public_key)
|
||||
name_id_formats = app_settings.NAME_ID_FORMATS
|
||||
|
@ -191,7 +191,7 @@ def import_object(path):
|
|||
|
||||
|
||||
@to_list
|
||||
def get_adapters(idp={}, **kwargs):
|
||||
def get_adapters(idp=None, **kwargs):
|
||||
idp = idp or {}
|
||||
adapters = tuple(idp.get('ADAPTER', ())) + tuple(app_settings.ADAPTER)
|
||||
for adapter in adapters:
|
||||
|
|
|
@ -195,8 +195,7 @@ class LoginView(ProfileMixin, LogMixin, View):
|
|||
if not entity_id:
|
||||
for idp in utils.get_idps():
|
||||
return idp
|
||||
else:
|
||||
return {}
|
||||
return {}
|
||||
else:
|
||||
return utils.get_idp(entity_id)
|
||||
|
||||
|
@ -260,7 +259,7 @@ class LoginView(ProfileMixin, LogMixin, View):
|
|||
content = self.get_attribute_value(at, attribute_value)
|
||||
if content is not None:
|
||||
values.append(content)
|
||||
entity_id = attributes['issuer'] = login.remoteProviderId
|
||||
attributes['issuer'] = login.remoteProviderId
|
||||
in_response_to = login.response.inResponseTo
|
||||
if in_response_to:
|
||||
attributes['nonce'] = request.session.get('mellon-nonce-%s' % in_response_to)
|
||||
|
@ -427,7 +426,7 @@ class LoginView(ProfileMixin, LogMixin, View):
|
|||
self.log.warning('unable to reach %r: %s', login.msgUrl, e)
|
||||
return self.failure(
|
||||
request,
|
||||
reason=_('IdP is temporarily down, please try again ' 'later.'),
|
||||
reason=_('IdP is temporarily down, please try again later.'),
|
||||
status_codes=status_codes,
|
||||
)
|
||||
if result.status_code != 200:
|
||||
|
@ -712,7 +711,7 @@ class LogoutView(ProfileMixin, LogMixin, View):
|
|||
try:
|
||||
logout.validateRequest()
|
||||
except lasso.Error as e:
|
||||
self.log.warning('error validating logout request: %r' % e)
|
||||
self.log.warning('error validating logout request: %s', e)
|
||||
else:
|
||||
if session_indexes:
|
||||
self.log.info('logout requested for sessionIndexes %s', session_indexes)
|
||||
|
|
Loading…
Reference in New Issue