我希望在会话在spring security中过期时发送带有错误代码和错误消息的自定义对象。到目前为止,这是我的代码:
@Component
public class AuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
@Autowired
private UserJedisRepository userJedisRepository;
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
throws IOException, ServletException {
String token = request.getSession().getId();
userJedisRepository.delete(token);
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.getOutputStream().println("error Messsage: "+authEx.getMessage());
}
@Override
public void afterPropertiesSet() throws Exception {
setRealmName("Developer");
super.afterPropertiesSet();
}
}