89ee0aa50038c1174751d8dd5313af5a4f543ede
[auf_django_saml.git] / auf / django / saml / middleware.py
1 # -*- coding: utf-8 -*-
2
3 import logging
4 from django.contrib.auth.signals import user_logged_in
5 from django.contrib.auth.middleware import RemoteUserMiddleware
6 from auf.django.saml import settings as saml_settings
7
8
9 class 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
25 def 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
36 user_logged_in.connect(configure_user)