-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
강사님 질문이있습니다 ㅠㅠ
23.02.24 21:26 작성 조회수 349
0
public class MyCustomDsl extends AbstractHttpConfigurer<MyCustomDsl, HttpSecurity> {
@Override
public void configure(HttpSecurity http) throws Exception {
System.out.println("체크포인트!@@!@!@!@");
AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
http
.addFilter(new LoginFilter(authenticationManager))
.addFilterAfter(jwtFilter, UsernamePasswordAuthenticationFilter.class);
}
}
를 구현하고,
로그인이 완료 되었을 때,
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
log.info("successfulAuthentication 함수 실행: 로그인 성공");
PrincipalDetails principalDetails = (PrincipalDetails) authResult.getPrincipal();
/*
로그인 완료,
1. 토큰 생성
2. 쿠키 장착
*/
response.setHeader("gd", "gdgd");
// response.sendRedirect("/api/loginTest");
// super.successfulAuthentication(request, response, chain, authResult);
}
이 메서드 까지 구현했습니다.
제 원래 로직은
액세스 토큰, 리프레쉬 토큰을 생성하고
리프레쉬 토큰을 DB에 담고
액세스 토큰, 레프레쉬 토큰 두 개를 쿠키에 저장하는 로직입니다.
ResponseCookie build = ResponseCookie
.from("accessToken", "gd")
.path("/")
.httpOnly(true)
// 시간
.maxAge(JwtUtil.REFRESH_TOKEN_EXPIRE_TIME)
.sameSite("Lax")
.build();
ResponseEntity.ok().header("Set-Cookie", build.toString())
.body("ok");
대충 쿠키를 생성해서 그 쿠키를 헤더에 담는 방식을 사용 중인데,
이렇게 로그인 완료 메서드에서 구현할 방법이 없고 헤더에 저장할 방법이 없어서 너무 막막합니다..
Controller에서 그냥 구현하면 ResponseEntity를 이용해서 헤더에 고정적으로 담을 수 있는데
로그인 성공 메서드에서 어떻게 해야 이렇게 똑같이 구현을 할 수 있을까요..ㅠㅠㅜ?
답변을 작성해보세요.
0
답변 1