Skip to content

Commit 3136756

Browse files
committed
Remove obsolete authenticate() implementation
The old `nav.web.auth.authenticate()` function has been replaced by proper Django authentication backends and can therefore be removed.
1 parent 6e90998 commit 3136756

File tree

1 file changed

+1
-64
lines changed

1 file changed

+1
-64
lines changed

python/nav/web/auth/__init__.py

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,16 @@
1919

2020
import logging
2121
from typing import Optional
22-
2322
from urllib import parse
2423

2524
from django.http import HttpRequest
2625
from django.urls import reverse
2726

2827
from nav.auditlog.models import LogEntry
29-
from nav.models.profiles import Account
30-
from nav.web.auth import ldap, remote_user
31-
from nav.web.auth.ldap_auth_backend import _handle_ldap_admin_status
32-
28+
from nav.web.auth import remote_user
3329
from nav.web.auth.sudo import desudo
3430
from nav.web.auth.utils import clear_session, get_account
3531

36-
3732
_logger = logging.getLogger(__name__)
3833

3934

@@ -47,64 +42,6 @@
4742
LOGOUT_URL = '/index/logout/'
4843

4944

50-
def authenticate(username: str, password: str) -> Optional[Account]:
51-
"""Authenticate username and password against database.
52-
Returns account object if user was authenticated, else None.
53-
"""
54-
# FIXME Log stuff?
55-
auth = False
56-
account = None
57-
58-
# Try to find the account in the database. If it's not found we can try
59-
# LDAP.
60-
try:
61-
account = Account.objects.get(login__iexact=username)
62-
except Account.DoesNotExist:
63-
if ldap.available:
64-
user = ldap.authenticate(username, password)
65-
# If we authenticated, store the user in database.
66-
if user:
67-
account = Account(
68-
login=user.username, name=user.get_real_name(), ext_sync='ldap'
69-
)
70-
account.set_password(password)
71-
account.save()
72-
_handle_ldap_admin_status(user, account)
73-
# We're authenticated now
74-
auth = True
75-
76-
if account and account.locked:
77-
_logger.info("Locked user %s tried to log in", account.login)
78-
79-
if (
80-
account
81-
and account.ext_sync == 'ldap'
82-
and ldap.available
83-
and not auth
84-
and not account.locked
85-
):
86-
try:
87-
auth = ldap.authenticate(username, password)
88-
except ldap.NoAnswerError:
89-
# Fallback to stored password if ldap is unavailable
90-
auth = False
91-
else:
92-
if auth:
93-
account.set_password(password)
94-
account.save()
95-
_handle_ldap_admin_status(auth, account)
96-
else:
97-
return
98-
99-
if account and not auth:
100-
auth = account.check_password(password)
101-
102-
if auth and account:
103-
return account
104-
else:
105-
return None
106-
107-
10845
def get_login_url(request: HttpRequest) -> str:
10946
"""Calculate which login_url to use"""
11047
path = parse.quote(request.get_full_path())

0 commit comments

Comments
 (0)