编写LoginHandlerInterceptor @Configuration public class LoginHandlerInterceptor extends HandlerInterceptorAdapter {
private static final Logger logger = LoggerFactory.getLogger(LoginHandlerInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return super.preHandle(request, response, handler);
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
logger.debug("modelAndView{}", modelAndView);
logger.debug("handler{}", handler);
logger.debug("response{}", response);
logger.debug("request{}", request);
// 获取ip
String ipAddr = RequestIpUtil.getIpAddress(request);
super.postHandle(request, response, handler, modelAndView);
}
复制代码
} @Autowired private LoginHandlerInterceptor loginHandlerInterceptor; @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints.tokenStore(getRedisTokenStore()) .userDetailsService(ssoUserDetailsService) // 如果这个不写着 会报Unsupported grant type: password .authenticationManager(authenticationManager) .addInterceptor(loginHandlerInterceptor) .exceptionTranslator(customWebResponseExceptionTranslator);