Page 466 - MDP2022-3
P. 466

final  UserInfoRepository  userInfoRepository;
                     final  UserInfoService  userInfoService;
                     final  JwtTokenProvider  jwtTokenProvider;
                     final  AuthenticationManagerBuilder  authenticationManagerBuilder;


                     public  RefreshController(
                                     JwtService  jwtService,
                                     UserInfoRepository  userInfoRepository,
                                     UserInfoService  userInfoService,
                                     JwtTokenProvider  jwtTokenProvider,
                                     AuthenticationManagerBuilder  authenticationManagerBuilder
                     ){
                             this.jwtService  =  jwtService;
                             this.userInfoRepository  =  userInfoRepository;
                             this.userInfoService  =  userInfoService;
                             this.jwtTokenProvider  =  jwtTokenProvider;
                             this.authenticationManagerBuilder  =  authenticationManagerBuilder;
                     }


                     @RequestMapping(value  =  "/refresh/{userNickName}",
                                     method  =  {RequestMethod.GET,  RequestMethod.POST}
                     )
                     public   ResponseEntity<TokenDto>   validateRefreshToken(@PathVariable("userNickName")
             String  userNickName){


                             UserInfo  userInfo  =  userInfoService.findUserInfoByUserNickname(userNickName);


                             UserInfoRequest  userInfoRequest  =  new  UserInfoRequest();


                             jwtService.requestSave(userInfoRequest,  userInfo);
                             jwtService.roleSetUp(userInfoRequest,  userInfo);


                             UsernamePasswordAuthenticationToken  authenticationToken  =
                                             new   UsernamePasswordAuthenticationToken(userInfo.getUserEmail(),
             userInfo.getDecodedPassword());


                             Authentication                     authentication                            =
             authenticationManagerBuilder.getObject().authenticate(authenticationToken);
                             SecurityContextHolder.getContext().setAuthentication(authentication);


                             String  refreshToken  =  jwtService.findRefreshToken(userInfo.getUserEmail());


                             Boolean  status  =  jwtTokenProvider.validateRefreshToken(refreshToken);


                             HttpHeaders  resHeaders  =  new  HttpHeaders();
   461   462   463   464   465   466   467   468   469   470   471