-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #871 from maykinmedia/develop
Release v1.12
- Loading branch information
Showing
268 changed files
with
10,446 additions
and
3,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.contrib.auth import get_user_model | ||
|
||
from digid_eherkenning.backends import eHerkenningBackend as _eHerkenningBackend | ||
from digid_eherkenning.exceptions import eHerkenningError | ||
from digid_eherkenning.utils import get_client_ip | ||
|
||
UserModel = get_user_model() | ||
|
||
|
||
class eHerkenningBackend(_eHerkenningBackend): | ||
""" | ||
Custom backend to identify users based on the KvK number instead of RSIN | ||
""" | ||
|
||
def get_or_create_user(self, request, saml_response, saml_attributes): | ||
kvk = self.get_kvk_number(saml_attributes) | ||
if kvk == "": | ||
raise eHerkenningError( | ||
"Login failed due to no KvK being returned by eHerkenning." | ||
) | ||
|
||
created = False | ||
try: | ||
user = UserModel.eherkenning_objects.get_by_kvk(kvk) | ||
except UserModel.DoesNotExist: | ||
user = UserModel.eherkenning_objects.eherkenning_create(kvk) | ||
created = True | ||
|
||
success_message = self.error_messages["login_success"] % { | ||
"user": str(user), | ||
"user_info": " (new account)" if created else "", | ||
"ip": get_client_ip(request), | ||
"service": self.service_name, | ||
} | ||
|
||
self.log_success(request, success_message) | ||
|
||
return user, created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from digid_eherkenning.managers import BaseeHerkenningManager as _BaseeHerkenningManager | ||
|
||
|
||
class BaseeHerkenningManager(_BaseeHerkenningManager): | ||
def get_by_kvk(self, kvk): | ||
raise NotImplementedError |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import logging | ||
import re | ||
|
||
from django.contrib.auth import get_user_model | ||
|
||
from digid_eherkenning.backends import BaseBackend | ||
from digid_eherkenning.utils import get_client_ip | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
UserModel = get_user_model() | ||
|
||
|
||
class eHerkenningBackend(BaseBackend): | ||
service_name = "eHerkenning" | ||
error_messages = dict( | ||
BaseBackend.error_messages, | ||
**{ | ||
"eherkenning_no_kvk": "Login failed due to no KvK being returned by eHerkenning.", | ||
"eherkenning_len_kvk": "Login failed due to no KvK having more then 8 digits.", | ||
"eherkenning_num_kvk": "Login failed due to no KvK not being numerical.", | ||
} | ||
) | ||
|
||
def get_or_create_user(self, request, kvk): | ||
created = False | ||
try: | ||
user = UserModel.eherkenning_objects.get_by_kvk(kvk) | ||
except UserModel.DoesNotExist: | ||
user = UserModel.eherkenning_objects.eherkenning_create(kvk) | ||
created = True | ||
|
||
success_message = self.error_messages["login_success"] % { | ||
"user": str(user), | ||
"user_info": " (new account)" if created else "", | ||
"ip": get_client_ip(request), | ||
"service": self.service_name, | ||
} | ||
|
||
self.log_success(request, success_message) | ||
|
||
return user, created | ||
|
||
def authenticate(self, request, kvk=None): | ||
if kvk is None: | ||
return | ||
|
||
if kvk == "": | ||
self.log_error(request, self.error_messages["eherkenning_no_kvk"]) | ||
return | ||
|
||
if not re.match(r"^[0-9]+$", kvk): | ||
self.log_error(request, self.error_messages["eherkenning_len_kvk"]) | ||
return | ||
|
||
if len(kvk) > 8: | ||
self.log_error(request, self.error_messages["eherkenning_num_kvk"]) | ||
return | ||
|
||
user, created = self.get_or_create_user(request, kvk) | ||
|
||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.conf import settings | ||
from django.shortcuts import resolve_url | ||
from django.urls import reverse | ||
from django.utils.encoding import force_str | ||
|
||
|
||
def get_app_title(): | ||
""" | ||
Title of application to display in IDP view | ||
""" | ||
return force_str( | ||
getattr(settings, "EHERKENNING_MOCK_APP_TITLE", "") or "eHerkenning Mock Login" | ||
) | ||
|
||
|
||
def get_success_url(): | ||
""" | ||
Default URL to redirect to after login | ||
""" | ||
url = ( | ||
getattr(settings, "EHERKENNING_MOCK_RETURN_URL", "") | ||
or getattr(settings, "LOGIN_REDIRECT_URL", "") | ||
or "/" | ||
) | ||
return resolve_url(url) | ||
|
||
|
||
def get_cancel_url(): | ||
""" | ||
Default URL if user presses 'vorige/back' in IDP view | ||
""" | ||
url = ( | ||
getattr(settings, "EHERKENNING_MOCK_CANCEL_URL", "") | ||
or getattr(settings, "LOGIN_URL", "") | ||
or "/" | ||
) | ||
return resolve_url(url) | ||
|
||
|
||
def get_idp_login_url(): | ||
""" | ||
URL of the IDP login page (possibly on other domain) | ||
""" | ||
url = getattr(settings, "EHERKENNING_MOCK_IDP_LOGIN_URL", "") or reverse( | ||
"eherkenning-mock:login" | ||
) | ||
return resolve_url(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.urls import path | ||
|
||
from eherkenning.mock.views.eherkenning import ( | ||
eHerkenningAssertionConsumerServiceMockView, | ||
eHerkenningLoginMockView, | ||
eHerkenningLogoutMockView, | ||
) | ||
|
||
""" | ||
this is a mock replacement for the regular eherkenning_urls.py | ||
""" | ||
|
||
app_name = "eherkenning" | ||
|
||
urlpatterns = ( | ||
path("login/", eHerkenningLoginMockView.as_view(), name="login"), | ||
path("acs/", eHerkenningAssertionConsumerServiceMockView.as_view(), name="acs"), | ||
path("logout/", eHerkenningLogoutMockView.as_view(), name="logout"), | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.urls import path | ||
|
||
from eherkenning.mock.idp.views.eherkenning import ( | ||
eHerkenningMockIDPLoginView, | ||
eHerkenningMockIDPPasswordLoginView, | ||
) | ||
|
||
app_name = "eherkenning-mock" | ||
|
||
urlpatterns = [ | ||
path("inloggen/", eHerkenningMockIDPLoginView.as_view(), name="login"), | ||
path( | ||
"inloggen_ww/", eHerkenningMockIDPPasswordLoginView.as_view(), name="password" | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django import forms | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from eherkenning.validators import KVKValidator | ||
|
||
|
||
class eHerkenningPasswordLoginForm(forms.Form): | ||
auth_name = forms.CharField( | ||
max_length=255, | ||
required=True, | ||
label=_("eHerkenning gebruikersnaam"), | ||
validators=[KVKValidator()], | ||
) | ||
auth_pass = forms.CharField( | ||
max_length=255, required=True, label=_("Wachtwoord"), widget=forms.PasswordInput | ||
) | ||
remember_login = forms.CharField( | ||
label=_("Onthoud mijn eHerkenning gebruikersnaam"), required=False | ||
) |
Empty file.
Oops, something went wrong.