목록Spring (6)
히콩쓰 개발 일지

카카오 OAuth로 로그인, 로그아웃 등의 기능을 구현하면서 인증받은 User 객체를 Userdetails에 담아 SecurityConfig에서 권한을 확인한 뒤 API 접근을 허가하고자 아래와 같이 WebSecurityConfig 코드를 작성하였다. @Configuration @EnableWebSecurity @RequiredArgsConstructor public class WebSecurityConfig { private final UserDetailsServiceImpl userDetailsService; private final AuthenticationConfiguration authenticationConfiguration; private final RestTemplate restTempla..

Controller 테스트 코드를 작성하던 중 authentication에 userDetails를 넣어줬음에도 불구하고 403 forbidden 에러가 발생했다. 에러 코드를 살펴보니, 아래 사진과 같이 MockHttpServletRequest에 CSRF 토큰이 들어간 것을 확인할 수 있었다. 하지만 본 프로젝트에서는 아래와 같이 WebSecurityConfig 에서 csrf를 사용하지 않도록 설정했기 때문에 CSRF 토큰이 설정된 것이 더욱 이상하다고 생각했다. Controller 테스트를 위해 강의에서 나온대로 코드를 작성했고, 이 과정에서 WebSecurityConfig가 제외된 것을 확인할 수 있다. 결과적으로, WebSecurityConfig가 제외되면서 csrf를 disable한 것이 같이 제..

문제 분석 To-Do List를 개발하던 도중, "완료 된 할일 인가?" 를 표현하기 위해 아래와 같은 코드를 작성하였다. public class Card extends Timestamped{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "card_id") @Getter private Long cardId; @Getter private String cardTitle; @Getter private String cardContent; @Getter private boolean isCompletion; 이 때, private boolean isCompletion 이라는 필드에서 문제를 겪었다. 아래는 Service에서 전체 카드..
TO-DO LIST의 CRUD를 구현하던 중, Card를 선택해 조회하는 API 테스트를 진행했다. POSTMAN에서 http://localhost:8080/cards/{id} 로 요청을 보냈는데, 406 Not Acceptable Error가 발생했다. "406 Not Acceptable" 이란? 서버가 요청의 주도적인 콘텐츠 협상 헤더에 정의된 허용 가능한 값 목록과 일치하는 응답을 생성할 수 없으며, 서버가 기본 표현을 제공하지 않음을 나타낸다. 문제 발생 코드 @AllArgsConstructor public class CardViewResponseDto { private String cardTitle; private String cardContent; private String userName; ..

게시판 CRUD를 개발하던 중, 아래와 같은 요구사항을 구현하다 문제에 직면했다. 선택한 게시글 삭제 기능 선택한 게시글을 삭제할 수 있습니다. 서버에 게시글 삭제를 요청할 때 비밀번호를 함께 전달합니다. 선택한 게시글의 비밀번호와 요청할 때 함께 보낸 비밀번호가 일치할 경우에만 삭제가 가능합니다. password를 매개변수로 전달해주고 이를 비교하는 로직을 작성하면 된다고 생각해 아래와 같이 Controller를 구현했다. @DeleteMapping("/board/{id}") public void removeBoard(@PathVariable Long id, @RequestBody String password){ boardService.removeBoard(id, password); }Postman에서..
게시판 CRUD 기능을 구현할 때 맞닥뜨린 문제이다. ⛔ 전체 오류 메시지 Optional int parameter 'id' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type. int형 parameter id가 primitive type으로 선언되어 null을 표현할 수 없으니 wrapper class 를 사용해보는게 어떻겠냐는 것이다. 아래는 문제가 발생했을 당시 작성한 Board 클래스 이다. @Entity @Getter @Set..