-
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
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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 java.io.IOException; | ||
import org.slf4j.MDC; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
@Component | ||
public class LogUserInfoFilter extends OncePerRequestFilter { | ||
|
||
private UserProvider userProvider; | ||
|
||
private RegionsConfiguration regionsConfiguration; | ||
|
||
@Autowired | ||
public LogUserInfoFilter(UserProvider userProvider, RegionsConfiguration regionsConfiguration) { | ||
this.userProvider = userProvider; | ||
this.regionsConfiguration = regionsConfiguration; | ||
} | ||
|
||
@Override | ||
protected void doFilterInternal( | ||
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
try { | ||
MDC.put( | ||
"username", | ||
userProvider.getUser(regionsConfiguration.getDefaultRegion()).getIdep()); | ||
} catch (Exception ignored) { | ||
|
||
} | ||
filterChain.doFilter(request, response); | ||
MDC.clear(); | ||
} | ||
} |
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