-
-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auth): log login failures (#699)
close #697
- Loading branch information
Showing
2 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/akhq/utils/LoginFailedEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.akhq.utils; | ||
|
||
import io.micronaut.context.event.ApplicationEventListener; | ||
import io.micronaut.security.authentication.AuthenticationFailed; | ||
import io.micronaut.security.authentication.UserDetails; | ||
import io.micronaut.security.event.LoginFailedEvent; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
@Slf4j | ||
public class LoginFailedEventListener implements ApplicationEventListener<LoginFailedEvent> { | ||
@Override | ||
public void onApplicationEvent(LoginFailedEvent event) { | ||
if (event.getSource() instanceof AuthenticationFailed) { | ||
AuthenticationFailed authenticationFailed = (AuthenticationFailed) event.getSource(); | ||
log.warn("Login failed reason {}, username {}, message {}", | ||
authenticationFailed.getReason(), | ||
authenticationFailed.getUserDetails().map(UserDetails::getUsername).orElse("unknown"), | ||
authenticationFailed.getMessage().orElse("none") | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean supports(LoginFailedEvent event) { | ||
return true; | ||
} | ||
} |