1.1
[auf_django_saml.git] / auf / django / saml / middleware.py
... / ...
CommitLineData
1# -*- coding: utf-8 -*-
2
3import logging
4from django.contrib.auth.signals import user_logged_in
5from django.contrib.auth.middleware import RemoteUserMiddleware
6from auf.django.saml import settings as saml_settings
7
8
9class SPMiddleware(RemoteUserMiddleware):
10
11 def process_request(self, request):
12 """
13 Log MELLON an REMOTE_USER
14 """
15 logger = logging.getLogger('SAML')
16 for k, v in request.META.items():
17 if k.startswith('MELLON') or k is 'REMOTE_USER':
18 logger.info('%s : %s' % (k, v))
19
20 if not saml_settings.SAML_AUTH:
21 return
22 return super(SPMiddleware, self).process_request(request)
23
24
25def configure_user(sender, request, user, *args, **kwargs):
26 """
27 Au login, on synchronise les infos du serveur d'identités
28 avec le user local
29 """
30 meta = request.META
31 user.email = meta['MELLON_mail']
32 user.first_name = meta['MELLON_gn']
33 user.last_name = meta['MELLON_sn']
34 user.save()
35
36user_logged_in.connect(configure_user)