From 8f2a43fee380cb0df4bbe0449848e55f2d5b9515 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 00:06:45 +0100 Subject: [PATCH] fix import paths --- authentic2_auth_saml2/__init__.py | 7 ++++--- authentic2_auth_saml2/frontend.py | 8 +++++--- authentic2_auth_saml2/urls.py | 18 ++++-------------- authentic2_auth_saml2/utils.py | 2 +- authentic2_auth_saml2/views.py | 8 ++++---- authentic2_auth_saml2/views_disco.py | 6 +++--- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/authentic2_auth_saml2/__init__.py b/authentic2_auth_saml2/__init__.py index 6b24fb6..26a80b6 100644 --- a/authentic2_auth_saml2/__init__.py +++ b/authentic2_auth_saml2/__init__.py @@ -2,15 +2,16 @@ __version__ = '1.0' class Plugin(object): - def __init__(self): + def init(self): from authentic2.decorators import TRANSIENT_USER_TYPES from . import transient TRANSIENT_USER_TYPES.append(transient.SAML2TransientUser) def get_before_urls(self): - from . import urls - return urls.urlpatterns + from django.conf.urls import patterns, url, include + return patterns('', + url('^authsaml/', include('authentic2_auth_saml2.urls'))) def get_apps(self): return [__name__, 'authentic2.saml'] diff --git a/authentic2_auth_saml2/frontend.py b/authentic2_auth_saml2/frontend.py index 2ae7009..d6576ba 100644 --- a/authentic2_auth_saml2/frontend.py +++ b/authentic2_auth_saml2/frontend.py @@ -3,6 +3,7 @@ import urllib from django.utils.translation import gettext_noop from django.http import HttpResponseRedirect from django.contrib.auth import REDIRECT_FIELD_NAME +from django.core.urlresolvers import reverse from authentic2.saml.models import LibertyProvider @@ -21,13 +22,14 @@ class AuthSAML2Frontend(object): def form(self): return forms.AuthSAML2Form - def post(self, request, form, nonce, next): + def post(self, request, form, nonce, next_url): entity_id = form.cleaned_data['entity_id'] query = urllib.urlencode({ 'entity_id': entity_id, - REDIRECT_FIELD_NAME: next + REDIRECT_FIELD_NAME: next_url, }) - return HttpResponseRedirect('/authsaml2/sso?%s' % query) + url = '{0}?{1}'.format(reverse('a2-auth-saml2-sso'), query) + return HttpResponseRedirect(url) def get_context(self): '''Specific context variable used by the specific template''' diff --git a/authentic2_auth_saml2/urls.py b/authentic2_auth_saml2/urls.py index 0a9c240..024f3d0 100644 --- a/authentic2_auth_saml2/urls.py +++ b/authentic2_auth_saml2/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import patterns, url -urlpatterns = patterns('authentic2.authsaml2.views', - url(r'^metadata$', 'metadata'), +urlpatterns = patterns('authentic2_auth_saml2.views', + url(r'^metadata$', 'metadata', name='a2-auth-saml2-metadata'), # Receive request from user interface url(r'^sso/$', 'sso', name='a2-auth-saml2-sso'), url(r'^account-linking/(?P.*)/$', 'account_linking', @@ -19,19 +19,9 @@ urlpatterns = patterns('authentic2.authsaml2.views', # Back of SLO treatment by the IdP Side url(r'^finish_slo$', 'finish_slo', name='a2-auth-saml2-finish-slo'), - # Receive request from user interface - url(r'^federationTermination$', 'federationTermination'), - # Receive response from Redirect SP initiated - url(r'^manageNameIdReturn$', 'manageNameIdReturn'), - # Receive request from SOAP IdP initiated - url(r'^manageNameIdSOAP$', 'manageNameIdSOAP'), - # Receive request from Redirect IdP initiated - url(r'^manageNameId$', 'manageNameId'), - # Receive request from Redirect IdP initiated - #Send idp discovery request ) -urlpatterns += patterns('authentic2.authsaml2.views_disco', +urlpatterns += patterns('authentic2_auth_saml2.views_disco', url(r'^redirect_to_disco/$', 'redirect_to_disco', name='a2-auth-saml2-redirect-to-disco'), #receive idp discovery response @@ -39,7 +29,7 @@ urlpatterns += patterns('authentic2.authsaml2.views_disco', name='a2-auth-saml2-disco-response'), ) -urlpatterns += patterns('authentic2.authsaml2.views_profile', +urlpatterns += patterns('authentic2_auth_saml2.views_profile', url(r'^delete_federation/(?P\d+)/$', 'delete_federation', name='a2-auth-saml2-delete-federation'), ) diff --git a/authentic2_auth_saml2/utils.py b/authentic2_auth_saml2/utils.py index ba0f5fc..bdb9e8f 100644 --- a/authentic2_auth_saml2/utils.py +++ b/authentic2_auth_saml2/utils.py @@ -133,7 +133,7 @@ def has_sessions(name_id, session_indexes=None): def get_session_keys(sessions): return sessions.values_list('django_session_key', flat=True) -def get_django_session_key_for_session_index(session_index) +def get_django_session_key_for_session_index(session_index): ls = LibertySession.objects.get(session_index=session_index) return ls.django_session_key diff --git a/authentic2_auth_saml2/views.py b/authentic2_auth_saml2/views.py index c1d1d9d..7cc542b 100644 --- a/authentic2_auth_saml2/views.py +++ b/authentic2_auth_saml2/views.py @@ -36,8 +36,8 @@ from authentic2.saml.models import (nameid2kwargs, LibertyProvider, from authentic2.saml.saml2utils import (authnresponse_checking, get_attributes_from_assertion) from authentic2.idp.saml.saml2_endpoints import return_logout_error -from authentic2.authsaml2.utils import error_page -from authentic2.authsaml2 import signals +from authentic2_auth_saml2.utils import error_page +from authentic2_auth_saml2 import signals from authentic2.utils import cache_and_validate, flush_django_session from . import utils @@ -656,7 +656,7 @@ def slo_return_response(request, logout): def get_provider_id_and_options(provider_id): if not provider_id: - provider_id = reverse(metadata) + provider_id = reverse('a2-auth-saml2-metadata') options = metadata_options if getattr(settings, 'AUTHSAML2_METADATA_OPTIONS', None): options.update(settings.AUTHSAML2_METADATA_OPTIONS) @@ -681,7 +681,7 @@ def http_response_forbidden_request(message): return HttpResponseForbidden(_(message)) def build_service_provider(request): - server = create_server(request, reverse(metadata)) + server = create_server(request, reverse('a2-auth-saml2-metadata')) assert server is not None, 'unable to build a LassoServer object' return server diff --git a/authentic2_auth_saml2/views_disco.py b/authentic2_auth_saml2/views_disco.py index 7ba7c53..6c2b793 100644 --- a/authentic2_auth_saml2/views_disco.py +++ b/authentic2_auth_saml2/views_disco.py @@ -7,7 +7,7 @@ from django.conf import settings from django.http import Http404, HttpResponseRedirect from django.utils.translation import ugettext as _ -from .saml2_endpoints import metadata +from .views import metadata from .utils import register_next_target, error_page, get_registered_url logger = logging.getLogger(__name__) @@ -30,8 +30,8 @@ def build_discovery_url(request, target): # Mix query strings d = urlparse.parse_qs(query) d.update({ - 'entityID': request.build_absolute_uri(reverse(metadata)), - 'return': request.build_absolute_uri(reverse(disco_response)), + 'entityID': request.build_absolute_uri(reverse('a2-auth-saml2-metadata')), + 'return': request.build_absolute_uri(reverse('a2-auth-saml2-disco-response')), 'returnIDParam': get_return_id_param(), }) query = urllib.urlencode(d)