Java源码示例:org.springframework.security.web.session.SessionInformationExpiredEvent

示例1
/**
 * 根据需要返回 Url 或者 Json
 * @author jitwxs
 * @since 2018/11/29 18:46
 */
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    Map<String, Object> map = new HashMap<>(16);
    map.put("code", 0);
    map.put("msg", "已经另一台机器登录,您被迫下线。" + event.getSessionInformation().getLastRequest());
    // Map -> Json
    String json = objectMapper.writeValueAsString(map);

    event.getResponse().setContentType("application/json;charset=UTF-8");
    event.getResponse().getWriter().write(json);

    // 如果是跳转html页面,url代表跳转的地址
    // redirectStrategy.sendRedirect(event.getRequest(), event.getResponse(), "url");
}
 
示例2
/**
 * 根据需要返回 Url 或者 Json
 * @author jitwxs
 * @since 2018/11/29 18:46
 */
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    Map<String, Object> map = new HashMap<>(16);
    map.put("code", 0);
    map.put("msg", "已经另一台机器登录,您被迫下线。" + event.getSessionInformation().getLastRequest());
    // Map -> Json
    String json = objectMapper.writeValueAsString(map);

    event.getResponse().setContentType("application/json;charset=UTF-8");
    event.getResponse().getWriter().write(json);

    // 如果是跳转html页面,url代表跳转的地址
    // redirectStrategy.sendRedirect(event.getRequest(), event.getResponse(), "url");
}
 
示例3
/**
 * 根据需要返回 Url 或者 Json
 * @author jitwxs
 * @since 2018/11/29 18:46
 */
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    Map<String, Object> map = new HashMap<>(16);
    map.put("code", 0);
    map.put("msg", "已经另一台机器登录,您被迫下线。" + event.getSessionInformation().getLastRequest());
    // Map -> Json
    String json = objectMapper.writeValueAsString(map);

    event.getResponse().setContentType("application/json;charset=UTF-8");
    event.getResponse().getWriter().write(json);

    // 如果是跳转html页面,url代表跳转的地址
    // redirectStrategy.sendRedirect(event.getRequest(), event.getResponse(), "url");
}
 
示例4
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    ResultMap resultMap = new ResultMap(getClass().getName() + ":onExpiredSessionDetected()",
            "您的 Session 已过期,请重新登录。" + event.getSessionInformation().getLastRequest());
    String json = objectMapper.writeValueAsString(resultMap);

    event.getResponse().setContentType("application/json;charset=UTF-8");
    event.getResponse().getWriter().write(json);
}
 
示例5
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    ResultMap resultMap = new ResultMap(getClass().getName() + ":onExpiredSessionDetected()",
            "您的 Session 已过期,请重新登录。" + event.getSessionInformation().getLastRequest());
    String json = objectMapper.writeValueAsString(resultMap);

    event.getResponse().setContentType("application/json;charset=UTF-8");
    event.getResponse().getWriter().write(json);
}
 
示例6
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event)
        throws IOException, ServletException {
    HttpServletResponse response = event.getResponse();
    response.setHeader("Content-type", "text/html;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().print("您的账号已在别处登录!要想继续访问,请刷新页面重新登录");
    response.flushBuffer();
}
 
示例7
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    HttpServletResponse response = event.getResponse();
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    response.setContentType("application/json;charset=utf-8");
    response.getWriter().write("您的账号已经在别的地方登录,当前登录已失效。如果密码遭到泄露,请立即修改密码!");
}
 
示例8
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    HttpServletResponse response = event.getResponse();
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    response.setContentType("application/json;charset=utf-8");
    response.getWriter().write("您的账号已经在别的地方登录,当前登录已失效。如果密码遭到泄露,请立即修改密码!");
}
 
示例9
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
    HttpServletResponse response = event.getResponse();
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    response.setContentType("application/json;charset=utf-8");
    response.getWriter().write("您的账号已经在别的地方登录,当前登录已失效。如果密码遭到泄露,请立即修改密码!");
}
 
示例10
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException {
    event.getResponse().setContentType(FebsConstant.JSON_UTF8);
    event.getResponse().getWriter().write(mapper.writeValueAsString(ResponseBo.unAuthorized("登录已失效")));
}
 
示例11
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
	HttpServletResponse response = event.getResponse();
	Response payload = CodiceEccezione.AUTENTICAZIONE.toFaultResponse("Sessione Scaduta");
	AbstractBasicAuthenticationEntryPoint.fillResponse(response, payload, this.timeZone);
}
 
示例12
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
	HttpServletResponse response = event.getResponse();
	Response payload = FaultCode.AUTORIZZAZIONE.toFaultResponse("Sessione Scaduta");
	AbstractBasicAuthenticationEntryPoint.fillResponse(response, payload, this.timeZone);
}