SPRING-SECURITY
JWT + OAuth2 구현 - (1)
cocodingding
2023. 12. 13. 18:17
참고한 블로그
Spring Security + JWT를 이용한 자체 Login & OAuth2 Login(구글, 네이버, 카카오) API 구현 (1) - 회원(User) 관
들어가기 전 처음 프로젝트 진행 시, 아무것도 모르던 상태에서 처음으로 만들어야겠다고 생각이 든 기능이 로그인 기능이었습니다. 처음부터 자체 Login과 OAuth2 Login(소셜 로그인)을 같이 구현해
ksh-coding.tistory.com
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.6'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// security 관련 의존성
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'mysql:mysql-connector-java:8.0.23'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-validation'//유효성 검사 validation
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final'//매핑 mapstruct 추가
implementation 'org.mapstruct:mapstruct:1.5.3.Final'//매핑 mapstruct 추가
implementation 'commons-validator:commons-validator:1.7' //유효성 검사
implementation 'org.springframework.security:spring-security-crypto:6.0.2'// 비밀번호 암호화
// jwt 관련 의존성
implementation 'com.auth0:java-jwt:4.2.1'
}
tasks.named('bootBuildImage') {
builder = 'paketobuildpacks/builder-jammy-base:latest'
}
tasks.named('test') {
useJUnitPlatform()
}
Spring initializr에 더 이상 2.x 버전들을 지원하지 않고 이에따라 java 11 or 8을 쓸 수 없기 때문에
강제로 Spring boot 3.1.6 버전과 java 17로 진행하게 되었다.
참고로 이 security 적용기는 원래 만들던 개인 블로그 프로젝트에 진행 한 것으로 이번 글과 관련 없는 것들이 좀 있는데
이번 security 적용을 위한 핵심 의존성은 이 두개다.
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'com.auth0:java-jwt:4.2.1'
application.yml
jwt:
secretKey:
access:
expiration:
header:
refresh:
expiration:
header:
각자의 yml 파일에 위치에 맞게 작성하면 된다.