b843e3d18cf9eb46ed9abc629490c8fdf1445a4d
[auf_django_saml.git] / auf / django / saml / backends.py
1 # -*- coding: utf-8 -*-
2
3 from django.contrib.auth.models import User
4 from django.contrib.auth.backends import RemoteUserBackend, ModelBackend
5 from auf.django.saml import settings
6
7
8 class FakeSPBackend(ModelBackend):
9 """
10 On autentifie uniquement sur le username
11 """
12 def authenticate(self, username=None, password=None):
13 try:
14 return User.objects.get(username=username)
15 except User.DoesNotExist:
16 return None
17
18
19 class RealSPBackend(RemoteUserBackend):
20 """
21 Backend reposant sur le id.auf.org
22 """
23 create_unknown_user = True
24
25 def clean_username(self, username):
26 """
27 Le IdP retourne le courriel
28 """
29 return username.replace('@auf.org', '')
30
31 if settings.SAML_AUTH:
32 SPBackend = RealSPBackend
33 else:
34 SPBackend = FakeSPBackend
35
36