CustomizeSessionInformationExpiredStrategy.java 1.0 KB

12345678910111213141516171819202122232425
  1. package com.welampiot.security;
  2. import com.alibaba.fastjson.JSON;
  3. import com.welampiot.common.BaseResult;
  4. import com.welampiot.common.ResultEnum;
  5. import org.springframework.security.web.session.SessionInformationExpiredEvent;
  6. import org.springframework.security.web.session.SessionInformationExpiredStrategy;
  7. import org.springframework.stereotype.Component;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.http.HttpServletResponse;
  10. import java.io.IOException;
  11. /**
  12. * 会话信息过期策略
  13. */
  14. @Component
  15. public class CustomizeSessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {
  16. @Override
  17. public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
  18. HttpServletResponse httpServletResponse = sessionInformationExpiredEvent.getResponse();
  19. httpServletResponse.setContentType("text/json;charset=utf-8");
  20. httpServletResponse.getWriter().write(JSON.toJSONString(BaseResult.success(ResultEnum.USER_NOT_LOGIN)));
  21. }
  22. }