Jwt
7 posts
SecurityJwtLogin - 6 [Login & Signup & logout]

SecurityJwtLogin - 6 [Login & Signup & logout] Structure 💥 전반적인 구조는 아래 그림과 같이 작성될 예정입니다. - Controller - Service - Mapper 구조 content

December 06, 2022
Spring-Security
Spring-Boot
Jwt
Login
TIL
SecurityJwtLogin - 5 [JWT Filter & ExceptionHandler]

SecurityJwtLogin - 5 [JWT Filter & ExceptionHandler] Spring Security Filter Spring-Security 는 Filter 기반으로 동작합니다. 큰 그림을 보면 아래 그림과 같습니다. 출처 : gngsn님 블로그 큰 흐름은 위와 같고, 이를 모두 이해하기엔 어려움이 있어 우선 당장 사용하는 기능들에 필요한 부분만 이용하겠습니다. UsernamePasswordAuthenticationFilter 🔥 기본적으로 Authentication(인증)을 담당하는 필터는 AbstractAuthenticationProcessingFilter이다. AbstractAuthenticationProcessingFilter는 추상 클래스로 SecurityFilterChain에 직접 들어갈 수 없습니다. UsernamePasswordAuthenticationFilter는 이를 상속받은 클래스이다. UsernamePasswordAuthenticat…

December 06, 2022
Spring-Security
Spring-Boot
Jwt
Login
TIL
SecurityJwtLogin - 4 [Token Provider]

SecurityJwtLogin - 4 [Token Provider] Token Provider 토큰을 생성, 토큰으로부터 Authentication 생성, 유효성 검사 등의 작업을 수행할 Token Provider를 작성합니다. 이 때, 인스턴스가 생성되는 시점에 필요한 작업이 있습니다. 일반적으로 생성자가 호출될 때 수행합니다. 이 경우에 어떤 문제가 발생하는지 알아보겠습니다. InitializingBean VS @PostConstruct 일반적인 생성자 호출 시점에 수행 🌈 SingleTon 으로 관리한다고 가정 new Foo() 를 수행하게 되면 Animal 이 등록되지 않았기 때문에 NULL 이 된다. 또한, Proxy 등의 이유로 Spring Framework에서 여러 번 호출될 수 있는 생성자이기 때문에 animal을 여러 번 출력하게 됩니다. 이를 생성자 주입과 @PostConstruct로 수정한 코드를 살펴보겠습니다. @PostConstruct 생성자 주입을 통해…

December 03, 2022
Spring-Security
Spring-Boot
Jwt
Login
TIL
SecurityJwtLogin - 3 [기본 Model 생성]

SecurityJwtLogin - 3 [기본 Model 생성] VO & DTO User : 사용자 Entity Token : Token Entity Authority : 권한 정보 JwtResponseDto : 응답 DTO User 권한의 경우 여러 권한을 가질 수 있으니 위와 같이 Collection으로 관리합니다. JwtResponse 최초 발급 시 access token, refresh token 모두 발급해주고, 유저 아이디와 권한 정보를 함께 보내줬습니다. 토큰 외의 정보는 어떤 정보를 보내줄 것인가에 따라서 설정하면 됩니다. access token 재발급 시 토큰만 재발급해줬습니다. 🌈 모든 코드는 junhyxxn GitHub에서 확인할 수 있습니다!! VO & DTO User JwtResponse

December 02, 2022
Spring-Security
Spring-Boot
Jwt
Login
TIL
SecurityJwtLogin - 2 [DB 설계]

SecurityJwtLogin - 2 [DB 설계] MySQL DB 설계 ERD 단순한 프로젝트의 경우 User Table에 Authority 를 포함시키는 편이 더 간단합니다. 하지만, 복잡한 프로젝트의 경우 한 user가 여러 autority를 가질 수 있습니다. 예를 든다면, 강사가 존재하고 그 직속으로 조교라는 개념이 존재한다면 강사는 조교의 권한과 강사의 권한을 모두 갖게 됩니다. ⭐ 따라서, 위와 같이 한 유저가 여러 권한을 가질 수 있도록 ERD를 구성했습니다. 일반적으로 사용자별 권한 관리 방식과 그룹별 권한 관리 방식이 존재한다고 합니다. MySQL DB 설계 ERD

December 02, 2022
Spring-Security
Spring-Boot
Jwt
Login
TIL
SecurityJwtLogin - 1 [프로젝트 설정]

SecurityJwtLogin - 1 [초기 프로젝트 설정] Dependencies and Version spring boot 의 경우 3.0.0 은 에러가 발생합니다. 따라서 2.7.6을 선택해줍니다. (되도록 SNAPSHOT은 피합니다.) 기본 설정 Dependency 를 추가할 때 설명이 적혀있지만 한 번 가볍게 살펴보겠습니다. Spring Web : Web 관련 Dependency Spring Boot DevTools : LiveReload 기능 제공 Lombok : Annotation 을 통해 Getter, Setter, Constructor 등을 사용가능 하도록 제공 Spring Security : 인증, 인가 등의 보안을 처리하기에 편리하도록 제공하는 Framework MyBatis Framework : Persistence Framework로 DB에 접근할 Connection Pool 등을 담당하고 SQL을 준비할 프레임워크 MySQL Driver : MySQL…

December 01, 2022
Spring-Security
Spring-Boot
Jwt
Login
TIL
SecurityJwtLogin - 0 [개요 - Spring Security Framework]

SecurityJwtLogin - 0 [개요 - Spring Security Framework] Spring Security를 적용한 Jwt 기반 로그인 프로젝트 - 0 프로젝트 시작 전 가볍게 스프링 시큐리티와 JWT 로그인 방식을 알아보고 시작하겠습니다. 🔒 Spring Security Framework Spring Security는 Spring 기반의 Application의 보안을 담당하는 Framework 이다. 인증(Authentication)과 인가(Authorization)에 대한 처리를 Filter 기반으로 처리를 해주며 많은 Filter가 제공되어 많은 보안 관련 옵션들을 개발자가 하나씩 작성하지 않고 쉽게 처리할 수 있는 장점이 있습니다. Authentication & Authorization 1️⃣ Authentication - 인증 접속하려는 사용자가 본인인지 확인하는 인증 절차 2️⃣ Authorization - 인가 / 권한 인증된 사용자가 요청한 자원에…

December 01, 2022
Spring-Security
Spring-Boot
Jwt
Login
TIL