sso: Add captcha validation on 3 failed attempts

- clearing ip address correctly is not implemented yet
- currently clearing all ip addresses

Signed-off-by: Joseph Nuthalpati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalpati authored and James Valleroy committed 2017-10-17 22:07:57 -04:00
1 parent 31cd97e71e
commit f330d09ec9
5 files changed
+31 -12

No files matched your search

+25 -6
View File
@@ -30,6 +30,10 @@ from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import LoginView, LogoutView
from django.shortcuts import render_to_response
from axes.utils import reset
PRIVATE_KEY_FILE_NAME = 'privkey.pem'
SSO_COOKIE_NAME = 'auth_pubtkt'
KEYS_DIRECTORY = '/etc/apache2/auth-pubtkt-keys'
@@ -58,22 +62,37 @@ class SSOLoginView(LoginView):
def dispatch(self, request, *args, **kwargs):
response = super(SSOLoginView, self).dispatch(request, *args, **kwargs)
if request.user.is_authenticated:
return set_ticket_cookie(request.user, response)
else:
return response
class CaptchaLoginView(LoginView):
redirect_authenticated_user = True
template_name = 'login.html'
form_class = AuthenticationForm
def dispatch(self, request, *args, **kwargs):
response = super(CaptchaLoginView, self).dispatch(
request, *args, **kwargs)
if request.POST:
if request.user.is_authenticated:
ip = get_ip_address_from_request(request)
reset() # TODO reset(ip=ip)
return set_ticket_cookie(request.user, response)
else: # Redirect user to captcha page
redirect = '' if request.path.rstrip('/').endswith('captcha') else 'captcha'
return HttpResponseRedirect(redirect)
else:
return response
return response
class CaptchaLoginView(SSOLoginView):
form_class = AuthenticationForm
def get_ip_address_from_request(request):
# TODO Not sure if this is the right way to get the client ip
return request.META['HTTP_X_FORWARDED_FOR']
class SSOLogoutView(LogoutView):
"""View to log out of Plinth and remove the auth_pubtkt cookie"""
template_name = 'index.html'
def dispatch(self, request, *args, **kwargs):
+1 -4
View File
@@ -23,7 +23,7 @@ from django.urls import reverse_lazy
from stronghold.decorators import public
from plinth.utils import non_admin_view
from plinth.modules.sso.views import SSOLoginView, SSOLogoutView, CaptchaLoginView
from plinth.modules.sso.views import SSOLoginView, SSOLogoutView
from . import views
from axes.decorators import watch_login
@@ -49,9 +49,6 @@ urlpatterns = [
non_admin_view(SSOLogoutView.as_view()),
{'next_page': reverse_lazy('index')},
name='logout'),
url(r'^accounts/login/captcha/$',
public(CaptchaLoginView.as_view()),
name='captcha-login'),
url(r'^users/firstboot/$',
public(views.FirstBootView.as_view()),
name='firstboot'),