- DI
- mysql
- 스프링부트
- 프로그래머스
- Docker
- 스프링
- spring
- ORM
- Django
- springboot
- SSL
- string
- java
- spring mvc
- jpa
- hibernate
- select
- @transactional
- join
- 1차원 배열
- spring boot
- nginx
- spring security 6
- sql
- 데이터베이스
- 문자열
- static
- 자바
- PYTHON
- AWS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
목록Java & Kotlin (86)
개발하는 자몽
해당 메서드는 매개변수로 받은 클래스가 특정 클래스를 구현 또는 상속했는지 boolean 값으로 결과를 반환한다. public class ItemValidator implements Validator { @Override public boolean supports(Class clazz) { return Item.class.isAssignableFrom(clazz); } ... } 위 코드를 예시로 보면 clazz가 Item 클래스를 구현 또는 상속했는지 확인한다. ==으로 확인하는 것보다 해당 메서드를 사용하여 검증하는 방식이 좋다.
오류 질문을 받았는데, 내가 지난번에 겪었던 에러와 유사한 것 같아서 정리해두려고 한다. 상황 API에 요청을 하고 해당 정보를 DB에 담는 것까지는 에러 없이 진행이 된다. 하지만 저장한 정보를 조회하면 아래와 같은 에러가 콘솔창에 나타난다. Postman에서는 500 에러라고 알려준다. (오류 전문이 아닌 중요한 부분만 가져왔다) 2023-02-13T09:52:21.966+09:00 ERROR 71150 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request process..

상황 서버를 켜고 질문 등록을 해보는데 500 에러가 발생했다. 혹시나 해서 답변 등록도 해봤는데 똑같이 500 에러가 발생했다. 이 에러는 서버의 문제라서 바로 콘솔창에서 에러를 확인했다. 연관 관계 ERD에 다른 필드는 적지 않고 PK와 FK만 작성했다. 발생한 에러와 원인 고찰 JdbcSQLIntegrityConstraintViolationException: Referential integrity constraint violation 오류 내용을 보면 Referential integrity constraint violation(참조 무결성 제약 조건 위반)이 발생함을 알 수 있다. 참조 무결성 제약 조건을 위반했다고 나오니 의심 가는 부분은 @ManyToOne을 적용한 FK 뿐이었다. 오류가 난 h..
스프링 시큐리티 인증을 받은 로그인한 사용자의 정보를 타임리프에서 사용하고 싶을 때 사용한다. 공식 문서 Thymeleaf + Spring Security integration basics - ThymeleafHave you switched to Thymeleaf but your login and error pages are still using JSP? In this article we will see how to configure your Spring application to use Thymeleaf for login and error pages. All the code seen here comes from a working application. Youwww.thymeleaf.org build...
권한에 따른 페이지처리를 하고 싶다면 Principal 객체를 사용하는 메서드 위에 @PreAuthorize("isAuthenticated()") 어노테이션을 사용하면 된다. Principal 객체를 사용하는 메소드에서 사용하지 않으면 500 에러가 발생한다. 이 오류는 Principal 객체가 널(null)값이라서 발생한 오류이다(콘솔을 확인하면 NPE가 반겨줄거다). Principal 객체는 로그인을 해야만 생성되는 객체이기 때문이다. ▶ isAuthenticated() : 로그인 → true | 로그아웃 → false 나의 경우 "로그인을 해야 게시글 또는 댓글을 달 수 있게 하고, 로그아웃 상태라면 로그인 페이지로 이동"하게 하고싶었다. 해당 따라서 해당 어노테이션을 적용하여 메서드가 실행되기 전..
GrantedAuthority 스프링 공식문서는 GrantedAuthority를 아래와 같이 설명하고 있다. Represents an authority granted to an Authentication object (이 글의 Authentication은 인터페이스이다. AuthenticationManager.authenticate 메소드에서 요청을 처리한 후 authenticated principal 또는 인증 요청에 대한 토큰을 나타낸다. (나는 '나타낸다'로 하면 헷갈려서 '토큰의 정보를 갖고있다'로 해석한다)) GrantedAuthority는 인터페이스로 Authentication에 부여한 권한을 나타낸다. Authentication에는 User(사용자)정보가 있어야 한다. 그리고 User 객체의..
UserDetailsService UserSecurityService는 스프링 시큐리티 설정에 등록할 클래스이다. 이 클래스는 스프링 시큐리티 로그인 처리의 핵심 부분이다. @RequiredArgsConstructor @Service public class UserSecurityService implements UserDetailsService { private final UserRepository userRepository; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Optional userOptional = userRepository.findByUsername(use..
BCryptPasswordEncoder는 BCrypt 해싱함수(BCrypt Hashing Function)를 사용해서 비밀번호를 암호화(encode)한다. 아래 코드는 값을 받아서 사용자를 생성한다. 이때 비밀번호는 BCryptPasswordEncoder를 사용하여 암호화하고 DB에 저장한다. @RequiredArgsConstructor @Service public class UserService { private final UserRepository userRepository; public SiteUser create(String username, String email, String password) { BCryptPasswordEncoder encoder = new BCryptPasswordEnco..

@EnableWebSecurity? @EnableWebSecurity는 URL이 스프링 시큐리티의 제어를 받도록 만드는 어노테이션이다. @EnableWebSecurity 어노테이션을 사용하면 내부적으로 SpringSecurityFilterChain이 동작하여 URL 필터가 적용된다. 스프링 시큐리티의 세부 설정은 SecurityFilterChain 빈을 생성하여 설정할 수 있다. 공식문서에서는 아래와 같이 설명하고 있다. Add this annotation to an @Configuration class to have the Spring Security configuration defined in any WebSecurityConfigurer or more likely by exposing a Secur..
예를 들어 질문 게시판을 구현한다고 하자. 그렇다면 질문 엔티티와 답변 엔티티가 필요하다. 이때 고려해야 할 점은 매핑 관계이다. 하나의 질문에는 여러 개의 답변이 달릴 수 있고, 하나의 답변은 여러 개의 질문에 달릴 수 있다. 답변 엔티티 입장에서 질문 엔티티와의 매핑 관계 → 1 : N 질문 엔티티 입장에서 답변 엔티티와의 매핑 관계 → N : 1 이를 위한 어노테이션으로 @ManyToOne과 @OneToMany를 사용할 수 있다. 해당 어노테이션을 사용하면 실제 데이터베이스에서는 ForeignKey(FK) 관계가 생성된다. (@ManyToOne은 부모 자식 관계를 갖는 구조에서 사용한다. 여기서 부모는 질문, 자식은 답변이라고 할 수 있다.) 질문 엔티티 - Question.java @Getter ..