|
|
@ -41,20 +41,30 @@ public class JwtAuthenticationController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private JwtService service; |
|
|
|
private JwtService service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 로그인 기능, |
|
|
|
|
|
|
|
* JwtRqModel에 입력받은 회원아이디, 입력받은 회원 비밀번호로 인증처리를 함. |
|
|
|
|
|
|
|
* @param authenticationRequest |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
@PostMapping(value = "/login") |
|
|
|
@PostMapping(value = "/login") |
|
|
|
@ApiOperation(value = "로그인") |
|
|
|
@ApiOperation(value = "로그인") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
|
public ResponseEntity<? extends BasicResponse> createAuthenticationToken(@RequestBody JwtRqModel authenticationRequest) throws Exception { |
|
|
|
public ResponseEntity<? extends BasicResponse> createAuthenticationToken(@RequestBody JwtRqModel authenticationRequest) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 로그인 프로세스
|
|
|
|
|
|
|
|
Map<String , Object> resultMap = service.loginProcess(authenticationRequest); |
|
|
|
|
|
|
|
|
|
|
|
Map<String , Object> resultMap = service.loginProcess(authenticationRequest); |
|
|
|
int loginError = (int) resultMap.get("loginError"); |
|
|
|
|
|
|
|
|
|
|
|
int loginError = (int) resultMap.get("loginError"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// loginError 은 1이 정상, - 값은 모두 로그인 실패임
|
|
|
|
if(loginError < 0) { |
|
|
|
if(loginError < 0) { |
|
|
|
|
|
|
|
|
|
|
|
String errorMessage = (String) resultMap.get("errorMessage"); |
|
|
|
String errorMessage = (String) resultMap.get("errorMessage"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 로그인 실패시 로그인 실패한 사유를 반환함
|
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
|
|
|
|
|
|
|
|
.body(new ErrorResponse(errorMessage, loginError + "")); // 계정 사용하지 못함
|
|
|
|
.body(new ErrorResponse(errorMessage, loginError + "")); // 계정 사용하지 못함
|
|
|
|
}else { |
|
|
|
}else { |
|
|
|
|
|
|
|
|
|
|
@ -65,49 +75,70 @@ public class JwtAuthenticationController { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 로그인 한 회원 정보, |
|
|
|
|
|
|
|
* 회원고유번호[cstmrSno]로 조회를 함. |
|
|
|
|
|
|
|
* @param cstmrSno |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
@GetMapping(value = "/profile/{cstmrSno}") |
|
|
|
@GetMapping(value = "/profile/{cstmrSno}") |
|
|
|
@ApiOperation(value = "로그인한 회원의 정보") |
|
|
|
@ApiOperation(value = "로그인한 회원의 정보") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
|
@ApiImplicitParam(name = "cstmrSno",value = "고객일련번호", dataTypeClass = Integer.class) |
|
|
|
@ApiImplicitParam(name = "cstmrSno",value = "고객일련번호", dataTypeClass = Integer.class) |
|
|
|
public ResponseEntity<? extends BasicResponse> proflie(@PathVariable Integer cstmrSno) throws Exception{ |
|
|
|
public ResponseEntity<? extends BasicResponse> proflie(@PathVariable Integer cstmrSno) throws Exception{ |
|
|
|
|
|
|
|
|
|
|
|
JwtProfileRsModel result = service.profile(cstmrSno); |
|
|
|
JwtProfileRsModel result = service.profile(cstmrSno); // 회원고유번호로 회원정보를 가져오는 기능.
|
|
|
|
if(result == null) { |
|
|
|
if(result == null) { |
|
|
|
|
|
|
|
// 반환받은 회원정보가 없을시 "의도적인" 예외코드를 반환해줌
|
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
.body(new ErrorResponse(RSErrorCode.DATA_NOTFOUNT)); |
|
|
|
.body(new ErrorResponse(RSErrorCode.DATA_NOTFOUNT)); |
|
|
|
} |
|
|
|
} |
|
|
|
return ResponseEntity.ok().body(new SuccessResponse<JwtProfileRsModel>(result)); |
|
|
|
return ResponseEntity.ok().body(new SuccessResponse<JwtProfileRsModel>(result)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 회원의 인가정보 유효기간 종료시, |
|
|
|
|
|
|
|
* 다시 인가정보[토큰]를 받는 기능 |
|
|
|
|
|
|
|
* @param body |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
@PostMapping(value = "/refresh") |
|
|
|
@PostMapping(value = "/refresh") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
|
// public ResponseEntity<? extends BasicResponse> refresh(@RequestParam("cstmrSno") int cstmrSno , @RequestParam("refreshToken") String refreshToken) throws Exception{
|
|
|
|
// public ResponseEntity<? extends BasicResponse> refresh(@RequestParam("cstmrSno") int cstmrSno , @RequestParam("refreshToken") String refreshToken) throws Exception{
|
|
|
|
public ResponseEntity<? extends BasicResponse> refresh(@RequestBody Map body) throws Exception{ |
|
|
|
public ResponseEntity<? extends BasicResponse> refresh(@RequestBody Map body) throws Exception{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//입력값 검증
|
|
|
|
// 회원고유번호[cstmrSno], 회원고유번호[cstmrSno]가 Integer타입인지, 인가정보를 다시받을 토큰값 [refreshToken] 입력값에 대한 검증처리
|
|
|
|
if(body.get("cstmrSno") == null || body.get("refreshToken") == null || !(body.get("cstmrSno") instanceof Integer)) { |
|
|
|
if(body.get("cstmrSno") == null || body.get("refreshToken") == null || !(body.get("cstmrSno") instanceof Integer)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 검증이 되지 않으면 "의도적인" 예외코드를 반환해줌
|
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
.body(new ErrorResponse(RSErrorCode.ER_PARAM)); |
|
|
|
.body(new ErrorResponse(RSErrorCode.ER_PARAM)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int cstmrSno = (int)body.get("cstmrSno"); |
|
|
|
int cstmrSno = (int)body.get("cstmrSno"); |
|
|
|
String refreshToken = (String)body.get("refreshToken"); |
|
|
|
String refreshToken = (String)body.get("refreshToken"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 재 인가토큰 발급
|
|
|
|
|
|
|
|
JwtRsModel result = service.findRefreshtoken(cstmrSno, refreshToken); |
|
|
|
JwtRsModel result = service.findRefreshtoken(cstmrSno, refreshToken); |
|
|
|
|
|
|
|
// JwtRsModel result = null;
|
|
|
|
// JwtRsModel result = null;
|
|
|
|
|
|
|
|
|
|
|
|
if(result ==null) { |
|
|
|
if(result ==null) { |
|
|
|
|
|
|
|
// 토큰발행 실패 시 "의도적인" 예외코드를 반환해줌
|
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
.body(new ErrorResponse(RSErrorCode.DATA_NOTFOUNT)); |
|
|
|
.body(new ErrorResponse(RSErrorCode.DATA_NOTFOUNT)); |
|
|
|
} |
|
|
|
} |
|
|
|
return ResponseEntity.ok().body(new SuccessResponse<JwtRsModel>(result)); |
|
|
|
return ResponseEntity.ok().body(new SuccessResponse<JwtRsModel>(result)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 로그아웃 기능. |
|
|
|
|
|
|
|
* @param cstmrSno |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
* @throws Exception |
|
|
|
|
|
|
|
*/ |
|
|
|
@GetMapping(value = "/logout/{cstmrSno}") |
|
|
|
@GetMapping(value = "/logout/{cstmrSno}") |
|
|
|
@ApiOperation(value = "로그아웃 한 회원의 정보") |
|
|
|
@ApiOperation(value = "로그아웃 한 회원의 정보") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
|
@Tag(name = "JWT 토큰 이용", description = "JWT 토큰 관련 API") |
|
|
@ -120,10 +151,11 @@ public class JwtAuthenticationController { |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// int cstmrSno = (int)body.get("cstmrSno");
|
|
|
|
// int cstmrSno = (int)body.get("cstmrSno");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 로그아웃 할 프로세스
|
|
|
|
PtyCstmrBas bas = service.logoutProcess(cstmrSno); |
|
|
|
PtyCstmrBas bas = service.logoutProcess(cstmrSno); |
|
|
|
|
|
|
|
|
|
|
|
if(bas == null) { |
|
|
|
if(bas == null) { |
|
|
|
|
|
|
|
// 로그아웃 프로세스 실패 시 "의도적인" 예외코드를 반환해줌
|
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
return ResponseEntity.status(HttpStatus.OK) |
|
|
|
.body(new ErrorResponse(RSErrorCode.DATA_NOTFOUNT)); |
|
|
|
.body(new ErrorResponse(RSErrorCode.DATA_NOTFOUNT)); |
|
|
|
} |
|
|
|
} |
|
|
|