본문 바로가기

Spring30

[Spring Security] SecurityContextHolder 내부구조와 PasswordEncoder 📌 SecurityContextHolder 내부구조 스프링 시큐리티는의 내부구조는 위 사진과 같이 서로 겹겹이 감싸고있다. SecurityContextHolder -> SercurityContext -> Authentication -> Principal -> GrantAuthority 코드로 확인할 수 있음. // SecurityContext에서 현재 사용자의 인증 및 보안 정보를 가져옵니다. SecurityContext securityContext = SecurityContextHolder.getContext(); // 현재 사용자의 인증 정보를 가져옵니다. Authentication authentication = securityContext.getAuthentication(); // 현재 사용자의 주.. 2023. 10. 28.
[Spring Security] JWT을 알아보자 Spring Boot JWT Tutorial 1. JWT 소개, 프로젝트 생성 2. Data 설정 추가 3. JWT 코드, Security 설정 추가 4. DTO, Repository, 로그인 5. 회원가입, 권한검증 📌 JWT 소개, 프로젝트 생성 JWT란 JWT는 RFC 7519 웹 표준으로 지정이 되어있고 JSON 객체를 사용해서 토큰 자체에 정보들을 저장하고 있는 Web ToKen이다. JWT는 Header, Payload, Signature 3개의 부분으로 구성되어져 있다. Header : Signature를 해싱하기 위한 알고리즘 정보가 담겨있다. Payload : 서버와 클라이언트가 주고받는, 시스템에서 실제로 사용될 정보에 대한 내용이 담겨있다. Signature : 토큰의 유효성을 검증하.. 2023. 7. 10.
[Spring Boot] HTTP Status Code 제어 및 Exception Handling HTTP Status Code 제어 및 Exception Handling 1. HTTP Status Code의 중요성 2. HTTP Status Code 제어 3. HTTP State Code 제어를 위한 Exception Handling 4. Spring의 AOP를 이용한 Exception Handling 📌 HTTP Status Code의 중요성 간단한 예제를 통해 알아보자. ID가 1~3인 회원이 존재한다. 존재하는 회원 조회 존재하지 않는 회원 조회(좋지 않은 API 설계) 존재하지 않는 회원을 조회하여 에러가 발생할 것을 예상했지만 상태코드는 200이 반환되었다. 그 이유는 HTTP 입장에서는 해당 URL 호출이 문법적으로 오류가 없고 정상적으로 서버에서 응답을 반환받았기 때문이다. 존재하지 않.. 2023. 6. 21.
[Spring Data JPA] 5. 스프링 데이터 JPA 분석 스프링 데이터 JPA 분석 1. 스프링 데이터 JPA 구현체 분석 2. 새로운 엔티티를 구별하는 방법 📌 스프링 데이터 JPA 구현체 분석 스프링 데이터 JPA가 제공하는 공통 인터페이스의 구현체 org.springframework.data.jpa.repository.support.SimpleJpaRepository SimpleJpaRepository @Repository @Transactional(readOnly = true) public class SimpleJpaRepository implements JpaRepositoryImplementation { //... @Transactional @Override public S save(S entity) { Assert.notNull(entity, "E.. 2023. 5. 22.