0. RequestContextListener 설정
web.xml에서 RequestContextListener 리스너 클래스를 등록한다.
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
1. HttpServletRequest 꺼내기
UserDetailsService의 구현 클래스에서 RequestContextHolder에서 Request 객체를 꺼내어 사용하면 된다.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
EmployeeVO empVO = new EmployeeVO();
empVO.setEmpId(username);
empVO = empMapper.login(empVO);
AccessLogVO acsLogVO = new AccessLogVO();
acsLogVO.setLogId(username);
acsLogVO.setAcntType("EMPLOYEE");
acsLogMapper.insertLog(acsLogVO);
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
System.out.println("---------------------------------------------");
System.out.println("Hello there! : " + request.getRemoteAddr());
System.out.println("---------------------------------------------");
return empVO == null ? null : new EmpDetails(empVO);
}
'Java > Spring Framework' 카테고리의 다른 글
[Spring Framework] Quartz 스케줄러 설정하기 (0) | 2023.03.28 |
---|---|
[Spring Framework] 스프링 시큐리티에서 로그인 성공 후 로그인 전 요청했던 URL로 리다이렉트 하기 (0) | 2023.03.24 |
[Spring Framework] 스프링 시큐리티 다중 로그인 화면 (0) | 2023.02.23 |
[Spring Framework] 스프링 시큐리티에서 동시 접속 제한하기 (0) | 2023.02.17 |
[Spring Framework] 스프링 시큐리티 적용 후 서버에서 회원 정보 확인하기 (0) | 2023.02.15 |