编写LoginHandlerInterceptor
@Configurationpublic class LoginHandlerInterceptor extends HandlerInterceptorAdapter {private static final Logger logger = LoggerFactory.getLogger(LoginHandlerInterceptor.class);@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return super.preHandle(request, response, handler);}@Overridepublic 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);}
}
@Autowiredprivate LoginHandlerInterceptor loginHandlerInterceptor;@Overridepublic void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {endpoints.tokenStore(getRedisTokenStore()) .userDetailsService(ssoUserDetailsService) // 如果这个不写着 会报Unsupported grant type: password .authenticationManager(authenticationManager) .addInterceptor(loginHandlerInterceptor) .exceptionTranslator(customWebResponseExceptionTranslator); }