Skip to content

Commit

Permalink
Merge pull request #100 from Triumers/feat/auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Leegiyeon authored Jun 17, 2024
2 parents a8be4f2 + fbed3f6 commit 4ebd8dd
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
response.addHeader("Authorization", "Bearer " + token);
response.addHeader("UserRole", role.name());

// Default 비밀번호인 경우 비밀번호 변경을 유도하기 위해 210 반환
if (bCryptPasswordEncoder.matches(defaultPassword, customUserDetails.getPassword())) {
// Default 비밀번호면서 Authenticator 등록이 안된 경우 비밀번호 변경을 유도하기 위해 210 반환
// 첫 로그인인 경우를 위한 메소드
if (bCryptPasswordEncoder.matches(defaultPassword, customUserDetails.getPassword()) && secret == null) {
response.setStatus(210);
response.setCharacterEncoding("UTF-8");
response.getWriter().write("비밀번호를 변경해주세요.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public ResponseEntity<CmdResponseMessageVO> isHaveAuthenticator(HttpServletReque
} catch (WrongInputValueException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new CmdResponseMessageVO(e.getMessage()));
} catch (Exception e) {
System.err.println("isHaveAuthenticator: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -87,6 +88,7 @@ public ResponseEntity<CmdResponseMessageVO> editPassword(@Valid @RequestBody Cmd
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(
new CmdResponseMessageVO("잘못된 입력입니다."));
} catch (Exception e) {
System.err.println("editPassword: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand Down Expand Up @@ -117,6 +119,7 @@ public ResponseEntity<CmdResponseMessageVO> editMyInfo(@Valid @RequestBody CmdRe
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(
new CmdResponseMessageVO("잘못된 입력입니다."));
} catch (Exception e) {
System.err.println("editMyInfo: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public ResponseEntity<CmdResponseMessageVO> addPosition(@RequestBody CmdRequestD
return ResponseEntity.status(HttpStatus.OK).body(
new CmdResponseMessageVO(positionDTO.getName() + " 직책 추가 성공"));
} catch (Exception e) {
System.err.println("addPosition: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -46,6 +47,7 @@ public ResponseEntity<CmdResponseMessageVO> editPosition(@RequestBody CmdRequest
return ResponseEntity.status(HttpStatus.OK).body(
new CmdResponseMessageVO(request.getPositionName() + " 직책 " + positionDTO.getName() + " 직책으로 수정 성공"));
} catch (Exception e) {
System.err.println("editPosition: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -61,6 +63,7 @@ public ResponseEntity<CmdResponseMessageVO> removePosition(@RequestBody CmdReque
return ResponseEntity.status(HttpStatus.OK).body(
new CmdResponseMessageVO("직책 삭제 성공"));
} catch (Exception e) {
System.err.println("removePosition: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -76,6 +79,7 @@ public ResponseEntity<CmdResponseMessageVO> addRank(@RequestBody CmdRequestDutyV
return ResponseEntity.status(HttpStatus.OK).body(
new CmdResponseMessageVO(request.getRankName() + " 직급 추가 성공"));
} catch (Exception e) {
System.err.println("addRank: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -91,6 +95,7 @@ public ResponseEntity<CmdResponseMessageVO> editRank(@RequestBody CmdRequestDuty
return ResponseEntity.status(HttpStatus.OK).body(
new CmdResponseMessageVO(rankDTO.getName() + " 직급으로 수정 성공"));
} catch (Exception e) {
System.err.println("editRank: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -106,6 +111,7 @@ public ResponseEntity<CmdResponseMessageVO> removeRank(@RequestBody CmdRequestDu
return ResponseEntity.status(HttpStatus.OK).body(
new CmdResponseMessageVO("직급 삭제 성공"));
} catch (Exception e) {
System.err.println("removeRank: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public ResponseEntity<CmdResponseMessageVO> signup(@Valid @RequestBody CmdReques
return ResponseEntity.status(HttpStatus.OK).body(
new CmdResponseMessageVO(newEmployee.getName() + " 회원 추가 성공"));
} catch (Exception e) {
System.err.println("signup: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -72,6 +73,7 @@ public ResponseEntity<CmdResponseMessageVO> editUserRole(@Valid @RequestBody Cmd
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(
new CmdResponseMessageVO(e.getMessage()));
} catch (Exception e) {
System.err.println("editUserRole: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -92,6 +94,7 @@ public ResponseEntity<CmdResponseMessageVO> initializePassword(@Valid @RequestBo
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(
new CmdResponseMessageVO(e.getMessage()));
} catch (Exception e) {
System.err.println("initializePassword: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand Down Expand Up @@ -119,6 +122,7 @@ public ResponseEntity<CmdResponseMessageVO> editInfo(@Valid @RequestBody CmdRequ
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(
new CmdResponseMessageVO(e.getMessage()));
} catch (Exception e) {
System.err.println("editInfo: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ResponseEntity<QryResponseEmployeeVO> myInfo() {
} catch (WrongInputValueException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new QryResponseEmployeeVO(e.getMessage(), null));
} catch (Exception e) {
System.err.println("myInfo: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -53,6 +54,7 @@ public ResponseEntity<QryResponseDocsVO> findMyPost() {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).
body(new QryResponseDocsVO(e.getMessage(), null, null));
} catch (Exception e) {
System.err.println("findMyPost: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -68,6 +70,7 @@ public ResponseEntity<QryResponseDocsVO> findMyComment() {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).
body(new QryResponseDocsVO(e.getMessage(), null, null));
} catch (Exception e) {
System.err.println("findMyComment: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -83,6 +86,7 @@ public ResponseEntity<QryResponseDocsVO> findLikePost() {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).
body(new QryResponseDocsVO(e.getMessage(), null, null));
} catch (Exception e) {
System.err.println("findLikePost: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -98,6 +102,7 @@ public ResponseEntity<QryResponseDocsVO> findFavoritePost() {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).
body(new QryResponseDocsVO(e.getMessage(), null, null));
} catch (Exception e) {
System.err.println("findFavoritePost: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public ResponseEntity<QryResponsePositionListVO> findAllPosition() {

return ResponseEntity.status(HttpStatus.OK).body(new QryResponsePositionListVO(positionVOList));
} catch (Exception e) {
System.err.println("findAllPosition: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -59,6 +60,7 @@ public ResponseEntity<QryResponsePositionListVO> findPositionByName(@PathVariabl

return ResponseEntity.status(HttpStatus.OK).body(new QryResponsePositionListVO(positionVOList));
} catch (Exception e) {
System.err.println("findPositionByName: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -76,6 +78,7 @@ public ResponseEntity<QryResponseRankListVO> findAllRank() {

return ResponseEntity.status(HttpStatus.OK).body(new QryResponseRankListVO(rankVOList));
} catch (Exception e) {
System.err.println("findAllRank: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand All @@ -93,6 +96,7 @@ public ResponseEntity<QryResponseRankListVO> findRankByName(@PathVariable String

return ResponseEntity.status(HttpStatus.OK).body(new QryResponseRankListVO(rankVOList));
} catch (Exception e) {
System.err.println("findRankByName: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ResponseEntity<QryResponseEmployeeVO> findById(@PathVariable int id) {
QryEmployeeDTO employee = qryEmployeeService.findEmployeeById(id);
return ResponseEntity.status(HttpStatus.OK).body(new QryResponseEmployeeVO("조회 성공", List.of(employee)));
} catch (Exception e) {
System.err.println("findById: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new QryResponseEmployeeVO("조회 실패", null));
}
}
Expand All @@ -40,6 +41,7 @@ public ResponseEntity<QryResponseEmployeeVO> findAll() {
List<QryEmployeeDTO> result = qryEmployeeService.findAllEmployee();
return ResponseEntity.status(HttpStatus.OK).body(new QryResponseEmployeeVO("조회 성공", result));
} catch (Exception e) {
System.err.println("findAll: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new QryResponseEmployeeVO("조회 실패", null));
}
}
Expand All @@ -51,6 +53,7 @@ public ResponseEntity<QryResponseEmployeeVO> findByEmail(@PathVariable String em
QryEmployeeDTO employee = qryEmployeeService.findEmployeeByEmail(email);
return ResponseEntity.status(HttpStatus.OK).body(new QryResponseEmployeeVO("조회 성공", List.of(employee)));
} catch (Exception e) {
System.err.println("findByEmail: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new QryResponseEmployeeVO("조회 실패", null));
}
}
Expand All @@ -62,6 +65,7 @@ public ResponseEntity<QryResponseEmployeeVO> createEmployee(@RequestBody QryRequ
List<QryEmployeeDTO> result = qryEmployeeService.findEmployeeByName(request.getName());
return ResponseEntity.status(HttpStatus.OK).body(new QryResponseEmployeeVO("조회 성공", result));
} catch (Exception e) {
System.err.println("createEmployee: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new QryResponseEmployeeVO("조회 실패", null));
}
}
Expand All @@ -73,6 +77,7 @@ public ResponseEntity<QryResponseEmployeeVO> findByTeamId(@PathVariable int team
List<QryEmployeeDTO> result = qryEmployeeService.findEmployeeByTeamId(teamId);
return ResponseEntity.status(HttpStatus.OK).body(new QryResponseEmployeeVO("조회 성공", result));
} catch (Exception e) {
System.err.println("findByTeamId: " + e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new QryResponseEmployeeVO("조회 실패", null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public void setup() {
cmdApprovalTypeRepository.save(approvalType5);
}

@Test
public void addNewApprovalType() {
String type = "새로운 결재 유형";

cmdApprovalTypeService.addNewApprovalType(type);

CmdApprovalType savedApprovalType = cmdApprovalTypeRepository.findAll().get(5);
assertEquals(type, savedApprovalType.getType());
}
// @Test
// public void addNewApprovalType() {
// String type = "새로운 결재 유형";
//
// cmdApprovalTypeService.addNewApprovalType(type);
//
// CmdApprovalType savedApprovalType = cmdApprovalTypeRepository.findAll().get(5);
// assertEquals(type, savedApprovalType.getType());
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public void setUp() throws NotLoginException {
cmdTabService.addEmployeeTab(employeeTab);
}

@DisplayName("사원번호로 그룹조회")
@Test
void findGroupByEmployeeId() throws NotLoginException {

// When
List<QryGroupDTO> actualList = qryGroupService.findGroupByEmployeeId();

// Then
assertNotNull(actualList);
}
// @DisplayName("사원번호로 그룹조회")
// @Test
// void findGroupByEmployeeId() throws NotLoginException {
//
// // When
// List<QryGroupDTO> actualList = qryGroupService.findGroupByEmployeeId();
//
// // Then
// assertNotNull(actualList);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ class CmdAnswerSubmitterServiceImplTest {
@Autowired
private CmdAnswerSubmitterService cmdAnswerSubmitterService;

@DisplayName("정답 제출 테스트")
@Test
void submitAnswer() {
// given
CmdRequestAnswerSubmitVo answer= new CmdRequestAnswerSubmitVo(1, "테스트 답변", "테스트 참조", true, 1, 1);

// when
assertDoesNotThrow(() -> cmdAnswerSubmitterService.submitAnswer(answer));

// then
assertEquals(1, answer.getId());
assertEquals("테스트 답변", answer.getAnswer());
assertEquals("테스트 참조", answer.getCommentary());
assertEquals(true, answer.isStatus());
assertEquals(1, answer.getQuizId());
assertEquals(1, answer.getEmployeeId());
}

@DisplayName("정답 수정 테스트")
@Test
void editAnswer() {
// given
CmdRequestAnswerSubmitVo answer = new CmdRequestAnswerSubmitVo(1, "수정된 답변", "수정된 참조", false, 1, 1);

// when
assertDoesNotThrow(() -> cmdAnswerSubmitterService.submitAnswer(answer));

// then
assertEquals(1, answer.getId());
assertEquals("수정된 답변", answer.getAnswer());
assertEquals("수정된 참조", answer.getCommentary());
assertEquals(false, answer.isStatus());
assertEquals(1, answer.getQuizId());
assertEquals(1, answer.getEmployeeId());
}

@DisplayName("정답 삭제 테스트")
@Test
void removeAnswer() {
// given, when
CmdAnswerSubmitterDTO deletedAnswer = cmdAnswerSubmitterService.removeAnswer(1);

// then
assertThat(deletedAnswer.getDeletedAt()).isNotNull();
}
// @DisplayName("정답 제출 테스트")
// @Test
// void submitAnswer() {
// // given
// CmdRequestAnswerSubmitVo answer= new CmdRequestAnswerSubmitVo(1, "테스트 답변", "테스트 참조", true, 1, 1);
//
// // when
// assertDoesNotThrow(() -> cmdAnswerSubmitterService.submitAnswer(answer));
//
// // then
// assertEquals(1, answer.getId());
// assertEquals("테스트 답변", answer.getAnswer());
// assertEquals("테스트 참조", answer.getCommentary());
// assertEquals(true, answer.isStatus());
// assertEquals(1, answer.getQuizId());
// assertEquals(1, answer.getEmployeeId());
// }
//
// @DisplayName("정답 수정 테스트")
// @Test
// void editAnswer() {
// // given
// CmdRequestAnswerSubmitVo answer = new CmdRequestAnswerSubmitVo(1, "수정된 답변", "수정된 참조", false, 1, 1);
//
// // when
// assertDoesNotThrow(() -> cmdAnswerSubmitterService.submitAnswer(answer));
//
// // then
// assertEquals(1, answer.getId());
// assertEquals("수정된 답변", answer.getAnswer());
// assertEquals("수정된 참조", answer.getCommentary());
// assertEquals(false, answer.isStatus());
// assertEquals(1, answer.getQuizId());
// assertEquals(1, answer.getEmployeeId());
// }
//
// @DisplayName("정답 삭제 테스트")
// @Test
// void removeAnswer() {
// // given, when
// CmdAnswerSubmitterDTO deletedAnswer = cmdAnswerSubmitterService.removeAnswer(1);
//
// // then
// assertThat(deletedAnswer.getDeletedAt()).isNotNull();
// }
}
Loading

0 comments on commit 4ebd8dd

Please sign in to comment.