prepopule users
[auf_django_saml.git] / auf / django / saml / middleware.py
CommitLineData
aa2ccaae
OL
1# -*- coding: utf-8 -*-
2
56de6221
OL
3import logging
4from django.contrib.auth.signals import user_logged_in
aa2ccaae 5from django.contrib.auth.middleware import RemoteUserMiddleware
56de6221
OL
6from auf.django.saml import settings as saml_settings
7
aa2ccaae
OL
8
9class SPMiddleware(RemoteUserMiddleware):
10
11 def process_request(self, request):
56de6221
OL
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:
aa2ccaae
OL
21 return
22 return super(SPMiddleware, self).process_request(request)
56de6221
OL
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 """
50992337
OL
30 if saml_settings.SAML_AUTH:
31 meta = request.META
32 user.email = meta['MELLON_mail']
33 user.first_name = meta['MELLON_gn']
34 user.last_name = meta['MELLON_sn']
35 user.save()
56de6221
OL
36
37user_logged_in.connect(configure_user)