Skip to content

Commit 5ab6b9e

Browse files
committed
add null check
1 parent 1bebb63 commit 5ab6b9e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

spring-security-login-and-registration/src/main/java/org/baeldung/security/AuthenticationFailureListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class AuthenticationFailureListener implements ApplicationListener<Authen
1414

1515
public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent e) {
1616
WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
17-
loginAttemptService.loginFailed(auth.getRemoteAddress());
17+
if (auth != null) {
18+
loginAttemptService.loginFailed(auth.getRemoteAddress());
19+
}
1820
}
1921
}

spring-security-login-and-registration/src/main/java/org/baeldung/security/AuthenticationSuccessEventListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
1414

1515
public void onApplicationEvent(AuthenticationSuccessEvent e) {
1616
WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
17-
loginAttemptService.loginSucceeded(auth.getRemoteAddress());
17+
if (auth != null) {
18+
loginAttemptService.loginSucceeded(auth.getRemoteAddress());
19+
}
1820
}
1921
}

0 commit comments

Comments
 (0)