misc: rename authentication "frontend" to "authenticator" (#14475)
This commit is contained in:
parent
14361e000b
commit
eac4437e5c
|
@ -15,5 +15,5 @@ class Plugin(object):
|
|||
def get_authentication_backends(self):
|
||||
return ['authentic2.auth2_auth.auth2_ssl.backends.SSLBackend']
|
||||
|
||||
def get_auth_frontends(self):
|
||||
return ['authentic2.auth2_auth.auth2_ssl.frontends.SSLFrontend']
|
||||
def get_authenticators(self):
|
||||
return ['authentic2.auth2_auth.auth2_ssl.authenticators.SSLAuthenticator']
|
||||
|
|
|
@ -5,7 +5,7 @@ from . import views, app_settings
|
|||
from authentic2.utils import redirect_to_login
|
||||
|
||||
|
||||
class SSLFrontend(object):
|
||||
class SSLAuthenticator(object):
|
||||
def enabled(self):
|
||||
return app_settings.ENABLE
|
||||
|
|
@ -4,7 +4,7 @@ from django.utils.translation import ugettext as _, ugettext_lazy
|
|||
from . import views, app_settings, utils, constants, forms
|
||||
|
||||
|
||||
class LoginPasswordBackend(object):
|
||||
class LoginPasswordAuthenticator(object):
|
||||
submit_name = 'login-password-submit'
|
||||
|
||||
def enabled(self):
|
|
@ -64,7 +64,7 @@ def register_plugins_urls(urlpatterns,
|
|||
|
||||
def register_plugins_installed_apps(installed_apps, group_name=DEFAULT_GROUP_NAME):
|
||||
'''Call get_apps() on all plugins of group_name and add the returned
|
||||
applications path to the installed_apps sequence.
|
||||
applications path to the installed_apps sequence.
|
||||
|
||||
Applications already present are ignored.
|
||||
'''
|
||||
|
@ -104,16 +104,16 @@ def register_plugins_authentication_backends(authentication_backends,
|
|||
authentication_backends.append(cls)
|
||||
return tuple(authentication_backends)
|
||||
|
||||
def register_plugins_auth_frontends(auth_frontends=(),
|
||||
def register_plugins_authenticators(authenticators=(),
|
||||
group_name=DEFAULT_GROUP_NAME):
|
||||
auth_frontends = list(auth_frontends)
|
||||
authenticators = list(authenticators)
|
||||
for plugin in get_plugins(group_name):
|
||||
if hasattr(plugin, 'get_auth_frontends'):
|
||||
cls = plugin.get_auth_frontends()
|
||||
if hasattr(plugin, 'get_authenticators'):
|
||||
cls = plugin.get_authenticators()
|
||||
for cls in cls:
|
||||
if cls not in auth_frontends:
|
||||
auth_frontends.append(cls)
|
||||
return tuple(auth_frontends)
|
||||
if cls not in authenticators:
|
||||
authenticators.append(cls)
|
||||
return tuple(authenticators)
|
||||
|
||||
def register_plugins_idp_backends(idp_backends,
|
||||
group_name=DEFAULT_GROUP_NAME):
|
||||
|
|
|
@ -94,8 +94,8 @@ class BaseRegistrationView(FormView):
|
|||
context = super(BaseRegistrationView, self).get_context_data(**kwargs)
|
||||
parameters = {'request': self.request,
|
||||
'context': context}
|
||||
blocks = [utils.get_backend_method(backend, 'registration', parameters)
|
||||
for backend in utils.get_backends('AUTH_FRONTENDS')]
|
||||
blocks = [utils.get_authenticator_method(authenticator, 'registration', parameters)
|
||||
for authenticator in utils.get_backends('AUTH_FRONTENDS')]
|
||||
context['frontends'] = collections.OrderedDict((block['id'], block)
|
||||
for block in blocks if block)
|
||||
return context
|
||||
|
|
|
@ -162,8 +162,8 @@ ACCOUNT_ACTIVATION_DAYS = 2
|
|||
# Authentication settings
|
||||
###########################
|
||||
AUTH_USER_MODEL = 'custom_user.User'
|
||||
AUTH_FRONTENDS = plugins.register_plugins_auth_frontends((
|
||||
'authentic2.auth_frontends.LoginPasswordBackend',))
|
||||
AUTH_FRONTENDS = plugins.register_plugins_authenticators((
|
||||
'authentic2.authenticators.LoginPasswordAuthenticator',))
|
||||
|
||||
###########################
|
||||
# RBAC settings
|
||||
|
|
|
@ -186,24 +186,24 @@ def get_backends(setting_name='IDP_BACKENDS'):
|
|||
return backends
|
||||
|
||||
|
||||
def get_backend_method(backend, method, parameters):
|
||||
if not hasattr(backend, method):
|
||||
def get_authenticator_method(authenticator, method, parameters):
|
||||
if not hasattr(authenticator, method):
|
||||
return None
|
||||
content = response = getattr(backend, method)(**parameters)
|
||||
content = response = getattr(authenticator, method)(**parameters)
|
||||
if not response:
|
||||
return None
|
||||
status_code = 200
|
||||
# Some backend methods return an HttpResponse, others return a string
|
||||
# Some authenticator methods return an HttpResponse, others return a string
|
||||
if isinstance(response, HttpResponse):
|
||||
content = response.content
|
||||
status_code = response.status_code
|
||||
return {
|
||||
'id': backend.id,
|
||||
'name': backend.name,
|
||||
'id': authenticator.id,
|
||||
'name': authenticator.name,
|
||||
'content': content,
|
||||
'response': response,
|
||||
'status_code': status_code,
|
||||
'backend': backend,
|
||||
'authenticator': authenticator,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -280,7 +280,7 @@ def login(request, template_name='authentic2/login.html',
|
|||
redirect_to = settings.LOGIN_REDIRECT_URL
|
||||
nonce = request.GET.get(constants.NONCE_FIELD_NAME)
|
||||
|
||||
frontends = utils.get_backends('AUTH_FRONTENDS')
|
||||
authenticators = utils.get_backends('AUTH_FRONTENDS')
|
||||
|
||||
blocks = []
|
||||
|
||||
|
@ -300,24 +300,24 @@ def login(request, template_name='authentic2/login.html',
|
|||
return utils.continue_to_next_url(request, params={'cancel': 1})
|
||||
|
||||
# Create blocks
|
||||
for frontend in frontends:
|
||||
for authenticator in authenticators:
|
||||
# Legacy API
|
||||
if not hasattr(frontend, 'login'):
|
||||
fid = frontend.id
|
||||
name = frontend.name
|
||||
form_class = frontend.form()
|
||||
if not hasattr(authenticator, 'login'):
|
||||
fid = authenticator.id
|
||||
name = authenticator.name
|
||||
form_class = authenticator.form()
|
||||
submit_name = 'submit-%s' % fid
|
||||
block = {
|
||||
'id': fid,
|
||||
'name': name,
|
||||
'frontend': frontend
|
||||
'authenticator': authenticator
|
||||
}
|
||||
if request.method == 'POST' and submit_name in request.POST:
|
||||
form = form_class(data=request.POST)
|
||||
if form.is_valid():
|
||||
if request.session.test_cookie_worked():
|
||||
request.session.delete_test_cookie()
|
||||
return frontend.post(request, form, nonce, redirect_to)
|
||||
return authenticator.post(request, form, nonce, redirect_to)
|
||||
block['form'] = form
|
||||
else:
|
||||
block['form'] = form_class()
|
||||
|
@ -325,15 +325,15 @@ def login(request, template_name='authentic2/login.html',
|
|||
else: # New frontends API
|
||||
parameters = {'request': request,
|
||||
'context': context}
|
||||
block = utils.get_backend_method(frontend, 'login', parameters)
|
||||
block = utils.get_authenticator_method(authenticator, 'login', parameters)
|
||||
# If a login frontend method returns an HttpResponse with a status code != 200
|
||||
# this response is returned.
|
||||
if block:
|
||||
if block['status_code'] != 200:
|
||||
return block['response']
|
||||
blocks.append(block)
|
||||
if hasattr(frontend, 'is_hidden'):
|
||||
blocks[-1]['is_hidden'] = frontend.is_hidden(request)
|
||||
if hasattr(authenticator, 'is_hidden'):
|
||||
blocks[-1]['is_hidden'] = authenticator.is_hidden(request)
|
||||
else:
|
||||
blocks[-1]['is_hidden'] = False
|
||||
|
||||
|
@ -343,15 +343,15 @@ def login(request, template_name='authentic2/login.html',
|
|||
fid = block['id']
|
||||
if not 'form' in block:
|
||||
continue
|
||||
frontend = block['frontend']
|
||||
authenticator = block['authenticator']
|
||||
context.update({
|
||||
'submit_name': 'submit-%s' % fid,
|
||||
redirect_field_name: redirect_to,
|
||||
'form': block['form']
|
||||
})
|
||||
if hasattr(frontend, 'get_context'):
|
||||
context.update(frontend.get_context())
|
||||
sub_template_name = frontend.template()
|
||||
context.update(authenticator.get_context())
|
||||
sub_template_name = authenticator.template()
|
||||
block['content'] = render_to_string(
|
||||
sub_template_name, context,
|
||||
request=request)
|
||||
|
@ -479,7 +479,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
|
|||
# Credentials management
|
||||
parameters = {'request': request,
|
||||
'context': context}
|
||||
profiles = [utils.get_backend_method(frontend, 'profile', parameters)
|
||||
profiles = [utils.get_authenticator_method(frontend, 'profile', parameters)
|
||||
for frontend in frontends]
|
||||
# Old frontends data structure for templates
|
||||
blocks = [block['content'] for block in profiles if block]
|
||||
|
|
|
@ -17,8 +17,8 @@ class Plugin(object):
|
|||
def get_authentication_backends(self):
|
||||
return ['authentic2_auth_oidc.backends.OIDCBackend']
|
||||
|
||||
def get_auth_frontends(self):
|
||||
return ['authentic2_auth_oidc.auth_frontends.OIDCFrontend']
|
||||
def get_authenticators(self):
|
||||
return ['authentic2_auth_oidc.authenticators.OIDCAuthenticator']
|
||||
|
||||
def redirect_logout_list(self, request, next=None):
|
||||
from .models import OIDCProvider
|
||||
|
@ -65,4 +65,3 @@ class Plugin(object):
|
|||
provider.issuer, e, content)
|
||||
return
|
||||
logger.info(u'revoked token from OIDC provider %s', provider.issuer)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.shortcuts import render
|
|||
from . import app_settings, utils
|
||||
|
||||
|
||||
class OIDCFrontend(object):
|
||||
class OIDCAuthenticator(object):
|
||||
def enabled(self):
|
||||
return app_settings.ENABLE and utils.has_providers()
|
||||
|
|
@ -9,8 +9,8 @@ class Plugin(object):
|
|||
def get_authentication_backends(self):
|
||||
return ['authentic2_auth_saml.backends.SAMLBackend']
|
||||
|
||||
def get_auth_frontends(self):
|
||||
return ['authentic2_auth_saml.auth_frontends.SAMLFrontend']
|
||||
def get_authenticators(self):
|
||||
return ['authentic2_auth_saml.authenticators.SAMLAuthenticator']
|
||||
|
||||
def redirect_logout_list(self, request, next_url=None):
|
||||
from mellon.views import logout
|
||||
|
|
|
@ -8,7 +8,7 @@ from authentic2.utils import redirect_to_login
|
|||
from . import app_settings
|
||||
|
||||
|
||||
class SAMLFrontend(object):
|
||||
class SAMLAuthenticator(object):
|
||||
id = 'saml'
|
||||
|
||||
def enabled(self):
|
Loading…
Reference in New Issue