Page 471 - MDP2022-3
P. 471
HttpHeaders resHeaders = new HttpHeaders();
resHeaders.add("Content-Type", "application/json;charset=UTF-8");
return new ResponseEntity<>(userInfoList ,resHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/get",
method = {RequestMethod.GET, RequestMethod.POST}
)
public ResponseEntity<FindUserOnlyOneResponse> createUser(@RequestBody
FindUserOnlyOneRequest findUserOnlyOneRequest){
UserInfo userInfo = userInfoService.findUserInfoById(findUserOnlyOneRequest.getId());
FindUserOnlyOneResponse findUserOnlyOneResponse = new
FindUserOnlyOneResponse(userInfo);
HttpHeaders resHeaders = new HttpHeaders();
resHeaders.add("Content-Type", "application/json;charset=UTF-8");
return new ResponseEntity<>( findUserOnlyOneResponse,resHeaders, HttpStatus.OK);
}
@RequestMapping(value = "/login",
method = {RequestMethod.GET, RequestMethod.POST}
)
public ResponseEntity<TokenDto> login(@RequestBody Login login){
HttpHeaders resHeaders = new HttpHeaders();
resHeaders.add("Content-Type", "application/json;charset=UTF-8");
userInfoService.login(login);
UsernamePasswordAuthenticationToken authenticationToken =
new UsernamePasswordAuthenticationToken(login.getUserEmail(),
login.getPassword());
Authentication authentication =
authenticationManagerBuilder.getObject().authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
TokenDto jwt = jwtTokenProvider.createToken(authentication);
jwtService.previousRefreshTokenDelete(login.getUserEmail());
userInfoService.saveRefreshToken(login.getUserEmail(), jwt.getRefreshToken());
// 기존 리프레시 지우고, 리프레시 유효시간 체크해서 남으면 자동 액세스 토큰 재발급 / 지