-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect logs outside of console (#78)
* Redirect logs outside of console * Log user log in and authorities.
- Loading branch information
1 parent
3e1bfd7
commit 04c18a4
Showing
3 changed files
with
30 additions
and
6 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
26 changes: 26 additions & 0 deletions
26
src/main/java/hbp/mip/configurations/AuthenticationEventListener.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,26 @@ | ||
package hbp.mip.configurations; | ||
|
||
import hbp.mip.utils.Logger; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class AuthenticationEventListener { | ||
|
||
@EventListener | ||
public void handleAuthenticationSuccess(AuthenticationSuccessEvent event) { | ||
Authentication authentication = event.getAuthentication(); | ||
String username = authentication.getName(); | ||
Logger logger = new Logger(username, "LOGGING IN"); | ||
logger.info("User " + username + " has logged in successfully"); | ||
|
||
// If you need to log additional details: | ||
authentication.getAuthorities().forEach(authority -> | ||
logger.info("User " + username + " has authority " + authority.getAuthority()) | ||
); | ||
} | ||
} |
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