Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit b2d48ce

Browse files
authored
Merge pull request #5 from starboarder2001/master
add ability to use different login URL for SSL client auth
2 parents f1ba601 + c566ff3 commit b2d48ce

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ There are two things you need to do in ``settings.py``
6969
``AUTOCREATE_VALID_SSL_USERS = True``. Auto-created users will be set to
7070
inactive by default, consider using the `User.is_active`_ field in your
7171
`LOGIN_REDIRECT_URL`_ view to notifying the user of their status.
72+
3. If you want to use the standard login url, set `SSLCLIENT_LOGIN_URL = None` or leave it undefined.
73+
For cases where you want a seperate login URL for SSL auth, set `SSLCLIENT_LOGIN_URL = "/YOUR_URL/"`.
74+
`SSLCLIENT_LOGIN_URL` is designed for use cases where some users login via the regular Django login
75+
without using SSLCLIENT auth, but you have a seperate login URL for users that login with SSLCLIENT auth.
7276

7377
For details, see ``testapp/ssltest/settings.py``
7478

django_ssl_auth/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def process_request(self, request):
101101
return
102102
logger.debug("REST API call, not logging user in")
103103
request.user = user
104-
elif request.path_info == settings.LOGIN_URL:
104+
elif request.path_info == settings.LOGIN_URL or \
105+
(hasattr(settings, 'SSLCLIENT_LOGIN_URL') and request.path_info == settings.SSLCLIENT_LOGIN_URL):
105106
user = authenticate(request=request)
106107
if user is None or not check_user_auth(user):
107108
return

testapp/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@
3636
SILENCED_SYSTEM_CHECKS = (
3737
'1_10.W001',
3838
)
39+
40+
SSLCLIENT_LOGIN_URL = None

testapp/tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,20 @@ def test_login_new_user(self):
2121
self.assertEqual(user.username, '42')
2222
self.assertEqual(user.first_name, 'John')
2323
self.assertEqual(user.last_name, 'Smith')
24+
25+
def test_login_new_user_sslurl(self):
26+
"""Ensure users are automatically created."""
27+
# Simulate an SSL connection (of a new user)
28+
with self.settings(SSLCLIENT_LOGIN_URL="/pivlogin"):
29+
self.client.get(
30+
settings.SSLCLIENT_LOGIN_URL,
31+
HTTP_X_SSL_AUTHENTICATED='SUCCESS',
32+
HTTP_X_SSL_USER_DN='C=FI/serialNumber=42/GN=John/SN=Smith/CN=John Smith',
33+
HTTP_X_FORWARDED_PROTOCOL='https'
34+
)
35+
36+
# Ensure the new user was created
37+
user = User.objects.last()
38+
self.assertEqual(user.username, '42')
39+
self.assertEqual(user.first_name, 'John')
40+
self.assertEqual(user.last_name, 'Smith')

0 commit comments

Comments
 (0)