@@ -22,6 +22,7 @@ class PamAuthenticationResult(enum.Enum):
2222 FAILURE = 0 # Authentication failed
2323 SUCCESS = 1 # Authentication succeeded
2424 EXPIRED = - 1 # Password expired; needs reset
25+ LOCKED = 6 # User locked out due to incorrect attempts
2526
2627
2728class PamAuthenticationBackend :
@@ -72,14 +73,16 @@ def pam_auth(username, password):
7273 realm = settings .CSL_REALM
7374 pam_authenticator = pam .pam ()
7475 full_username = f"{ username } @{ realm } "
75- result = pam_authenticator .authenticate (full_username , password )
76+ result = pam_authenticator .authenticate (full_username , password , service = "ion-login" )
7677
7778 if result :
7879 result = PamAuthenticationResult .SUCCESS
7980 logger .debug ("PAM authorized %s@%s" , username , realm )
8081 else :
8182 logger .debug ("PAM failed to authorize %s" , username )
8283 result = PamAuthenticationResult .FAILURE
84+ if pam_authenticator .code == 6 :
85+ result = PamAuthenticationResult .LOCKED
8386 if "authentication token is no longer valid" in pam_authenticator .reason .lower ():
8487 result = PamAuthenticationResult .EXPIRED
8588 logger .debug ("Password for %s@%s expired, needs reset" , username , realm )
@@ -128,6 +131,10 @@ def authenticate(self, request, username=None, password=None):
128131 elif result == PamAuthenticationResult .EXPIRED :
129132 user , _ = get_user_model ().objects .get_or_create (username = "RESET_PASSWORD" , user_type = "service" , id = 999999 )
130133 return user
134+ elif result == PamAuthenticationResult .LOCKED :
135+ if request is not None :
136+ request .session ["user_locked_out" ] = 1
137+ return None
131138 else :
132139 pam_authenticate_failures .inc ()
133140 return None
0 commit comments