login : session info, timeout
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package hello.login.web.session;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class SessionInfoController {
|
||||
|
||||
@GetMapping("/session-info")
|
||||
public String sessionInfo(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession(false);
|
||||
if (session == null) {
|
||||
return "세션이 없습니다.";
|
||||
}
|
||||
session.getAttributeNames().asIterator()
|
||||
.forEachRemaining(name -> log.info("session name={}, value={}", name, session.getAttribute(name)));
|
||||
|
||||
log.info("sessionId={}", session.getId());
|
||||
log.info("getMaxInactiveInterval={}", session.getMaxInactiveInterval());
|
||||
log.info("getCreationTime={}", new Date(session.getCreationTime()));
|
||||
log.info("getLastAccessedTime={}", new Date(session.getLastAccessedTime()));
|
||||
log.info("isNew={}", session.isNew());
|
||||
|
||||
return "세션 출력";
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#logging.level.org.apache.coyote.http11=debug
|
||||
spring.messages.basename=messages,errors
|
||||
|
||||
server.servlet.session.tracking-modes=cookie
|
||||
server.servlet.session.tracking-modes=cookie
|
||||
server.servlet.session.timeout=60
|
||||
Reference in New Issue
Block a user