use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class LoggingFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try {
MDC.put(KEY_AUTHENTICATEDUSERNICKNAME, VALUE_ABSENT);
MDC.put(KEY_USERAGENT, VALUE_ABSENT);
MDC.put(KEY_USERAGENTCODE, VALUE_ABSENT);
Optional<ObjectId> authenticatedUserOidOptional = tryGetAuthenticatedUserObjectId();
if (authenticatedUserOidOptional.isPresent()) {
ObjectContext context = serverRuntime.newContext();
User user = User.getByObjectId(context, authenticatedUserOidOptional.get());
MDC.put(KEY_AUTHENTICATEDUSERNICKNAME, user.getNickname());
}
if (HttpServletRequest.class.isAssignableFrom(request.getClass())) {
HttpServletRequest hRequest = (HttpServletRequest) request;
String userAgent = hRequest.getHeader(HttpHeaders.USER_AGENT);
if (!Strings.isNullOrEmpty(userAgent)) {
MDC.put(KEY_USERAGENT, userAgent);
Optional<Agent> agentOptional = browserDetect(userAgent);
if (agentOptional.isPresent()) {
MDC.put(KEY_USERAGENTCODE, agentOptional.get().getCode());
}
}
}
chain.doFilter(request, response);
} finally {
MDC.clear();
}
}
Aggregations