saml: implement a2_hook_good_next_url for SAML 2.0 SPs (#21769)

This commit is contained in:
Benjamin Dauvergne 2018-02-21 10:26:18 +01:00
parent 06c37bec0a
commit 09dab1b45d
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,11 @@
from django.apps import AppConfig
default_app_config = 'authentic2.saml.A2SAMLAppConfig'
class A2SAMLAppConfig(AppConfig):
name = 'authentic2.saml'
def a2_hook_good_next_url(self, next_url):
from .utils import saml_good_next_url
return saml_good_next_url(next_url)

View File

@ -0,0 +1,21 @@
from authentic2.decorators import GlobalCache
@GlobalCache(timeout=60)
def get_entity_ids():
from .models import LibertyProvider
return LibertyProvider.objects.values_list('entity_id', flat=True)
@GlobalCache(timeout=60)
def saml_good_next_url(next_url):
from authentic2.utils import same_origin
entity_ids = get_entity_ids()
for entity_id in entity_ids:
if same_origin(entity_id, next_url):
return True
return None