| 12345678910111213141516171819202122232425 |
- package com.welampiot.security;
- import com.alibaba.fastjson.JSON;
- import com.welampiot.common.BaseResult;
- import com.welampiot.common.ResultEnum;
- import org.springframework.security.web.session.SessionInformationExpiredEvent;
- import org.springframework.security.web.session.SessionInformationExpiredStrategy;
- import org.springframework.stereotype.Component;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- /**
- * 会话信息过期策略
- */
- @Component
- public class CustomizeSessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {
- @Override
- public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
- HttpServletResponse httpServletResponse = sessionInformationExpiredEvent.getResponse();
- httpServletResponse.setContentType("text/json;charset=utf-8");
- httpServletResponse.getWriter().write(JSON.toJSONString(BaseResult.success(ResultEnum.USER_NOT_LOGIN)));
- }
- }
|