-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
onyxia-api/src/main/java/fr/insee/onyxia/api/security/LogUserInfoFilter.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,32 @@ | ||
package fr.insee.onyxia.api.security; | ||
|
||
import fr.insee.onyxia.api.configuration.properties.RegionsConfiguration; | ||
import fr.insee.onyxia.api.services.UserProvider; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.MDC; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import java.io.IOException; | ||
|
||
@Component | ||
public class LogUserInfoFilter extends OncePerRequestFilter { | ||
|
||
@Autowired | ||
private UserProvider userProvider; | ||
|
||
@Autowired | ||
private RegionsConfiguration regionsConfiguration; | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, | ||
FilterChain filterChain) throws ServletException, IOException { | ||
MDC.put("username", userProvider.getUser(regionsConfiguration.getDefaultRegion()).getIdep()); | ||
filterChain.doFilter(request, response); | ||
MDC.clear(); | ||
} | ||
} |