Pārlūkot izejas kodu

设置session过期http状态

master
WendyYang pirms 1 gada
vecāks
revīzija
6ec0ced095
1 mainītis faili ar 3 papildinājumiem un 5 dzēšanām
  1. +3
    -5
      pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultExpiredSessionStrategy.java

+ 3
- 5
pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/handler/DefaultExpiredSessionStrategy.java Parādīt failu

@@ -6,11 +6,11 @@ import com.ningdatech.pmapi.user.security.auth.errorcode.AuthErrorCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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;

@@ -29,11 +29,9 @@ public class DefaultExpiredSessionStrategy implements SessionInformationExpiredS

@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent)
throws IOException, ServletException {
if (LOG.isInfoEnabled()) {
LOG.info("session is expired");
}
throws IOException {
HttpServletResponse response = sessionInformationExpiredEvent.getResponse();
response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(objectMapper.writeValueAsString(
ApiResponse.of(AuthErrorCodeEnum.SESSION_EXPIRED.getCode(), AuthErrorCodeEnum.SESSION_EXPIRED.getMsg(), null)));


Notiek ielāde…
Atcelt
Saglabāt