Search in sources :

Example 51 with User

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(org.haiku.haikudepotserver.dataobjects.User) ObjectId(org.apache.cayenne.ObjectId) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

User (org.haiku.haikudepotserver.dataobjects.User)51 ObjectContext (org.apache.cayenne.ObjectContext)47 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)16 Test (org.junit.jupiter.api.Test)16 AccessDeniedException (org.springframework.security.access.AccessDeniedException)14 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)7 ObjectId (org.apache.cayenne.ObjectId)5 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)5 org.haiku.haikudepotserver.dataobjects.auto._User (org.haiku.haikudepotserver.dataobjects.auto._User)5 PermissionUserPkg (org.haiku.haikudepotserver.dataobjects.PermissionUserPkg)4 AuthenticateUserRequest (org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest)3 AuthenticateUserResult (org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult)3 Captcha (org.haiku.haikudepotserver.captcha.model.Captcha)3 Preconditions (com.google.common.base.Preconditions)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 CSVWriter (com.opencsv.CSVWriter)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Instant (java.time.Instant)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2