com.chutneytesting.security.AuditHandler Maven / Gradle / Ivy
/*
* SPDX-FileCopyrightText: 2017-2024 Enedis
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package com.chutneytesting.security;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
@Component
public class AuditHandler implements HandlerInterceptor {
Logger logger = LoggerFactory.getLogger(AuditHandler.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (!"GET".equals(request.getMethod())) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
logger.info("[{}] [{}] [{}]", authentication.getName(), request.getMethod(), request.getRequestURI());
}
}
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy