Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 인증 및 인가 과정 리펙토링 #133

Merged
merged 13 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 22 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
buildscript {
ext {
queryDslVersion = "5.0.0"
}
}

plugins {
id 'java'
id 'org.springframework.boot' version '2.7.12'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
//querydsl 추가
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
}

jar {
Expand All @@ -18,10 +10,7 @@ jar {

group = 'com.umc'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
}
sourceCompatibility = '17'

configurations {
compileOnly {
Expand All @@ -44,6 +33,7 @@ dependencies {

//메일 전송 라이브러리
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.5.5'
implementation group: 'com.sun.mail', name: 'jakarta.mail', version: '2.0.1'

//타임리프 라이브러리®
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.7.12'
Expand All @@ -54,7 +44,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'

//JSON Parse 라이브러리
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.google.code.gson:gson'

// validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
Expand All @@ -65,33 +56,34 @@ dependencies {
//AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

//querydsl 추가
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}" // querydsl 라이브러리
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}" // Querydsl 관련 코드 생성 기능 제공

//JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-orgjson:0.11.5'
implementation 'org.json:json:20210307'

//querydsl 추가
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
}

tasks.named('test') {
useJUnitPlatform()
}


//querydsl 추가 시작 (위에 plugin 추가 부분과 맞물림)
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}

sourceSets { // IDE의 소스 폴더에 자동으로 넣어준다.
main.java.srcDir querydslDir
sourceSets {
main.java.srcDirs += [ querydslDir ]
}

configurations {
querydsl.extendsFrom compileClasspath // 컴파일이 될때 같이 수행
tasks.withType(JavaCompile) {
options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir)
}

compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl // Q파일을 생성해준다.
clean.doLast {
file(querydslDir).deleteDir()
}
29 changes: 29 additions & 0 deletions src/main/java/com/umc/refit/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.umc.refit;

import java.util.Random;

public class Util {

/**Random 문자열*/
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()";

public static String generateRandomString(int length) {
Random random = new Random();
StringBuilder stringBuilder = new StringBuilder(length);

for (int i = 0; i < length; i++) {
int randomIndex = random.nextInt(CHARACTERS.length());
stringBuilder.append(CHARACTERS.charAt(randomIndex));
}

return stringBuilder.toString();
}

/**시간*/
public static final int ONE_HOUR = 60 * 60 * 1000;
public static final int ONE_DAY = 24 * 60 * 60 * 1000;
public static final int ONE_WEEK = 7 * 24 * 60 * 60 * 1000;

/**PATH*/
public static final String KAKAO_API = "https://kapi.kakao.com/v2/user/me";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.*;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.*;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import lombok.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.*;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import lombok.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.*;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Getter
@Setter
public class ReportMemDto {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/umc/refit/domain/dto/member/LoginDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.umc.refit.domain.dto.member;

import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class LoginDto {
private String loginId;
private String password;
private String fcm;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@Getter @Setter
@AllArgsConstructor
public class ResLoginDto {
public class RefreshTokenDto {

private String refreshToken;
}
13 changes: 13 additions & 0 deletions src/main/java/com/umc/refit/domain/dto/member/TokenDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.umc.refit.domain.dto.member;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter @Setter
@AllArgsConstructor
public class TokenDto {

private String accessToken;
private String refreshToken;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.umc.refit.domain.dto.mypage;

import lombok.*;

import javax.validation.constraints.Size;
import jakarta.validation.constraints.*;

@Getter
@Setter
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/umc/refit/domain/entity/BaseTimeEntity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.umc.refit.domain.entity;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;

@Getter
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/refit/domain/entity/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Getter
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/refit/domain/entity/Clothe.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.umc.refit.domain.entity;

import com.umc.refit.domain.dto.clothe.*;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.*;
import java.time.LocalDate;

@Slf4j
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/umc/refit/domain/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import jakarta.persistence.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -43,10 +43,10 @@ public Member(String name) {
this.name = name;
}

public Member(String email, String password, String name, String fcm) {
public Member(String email, String name, String fcm) {
this.email = email;
this.loginId = email;
this.password = password;
this.password = email;
this.name = name;
this.birth = LocalDate.now().toString().replace('-', '/');
this.gender = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/refit/domain/entity/PostImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Getter
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/refit/domain/entity/Posts.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/refit/domain/entity/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.*;
import jakarta.persistence.*;

@Slf4j
@Getter
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/refit/domain/entity/ReportMem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Getter
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/refit/domain/entity/Scrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import jakarta.persistence.*;

@Entity
@Getter
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/umc/refit/exception/ExceptionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public enum ExceptionType {

//로그인 예외
LOGIN_FAILED(BAD_REQUEST, 10103, "존재하지 않는 계정입니다."),
LOGIN_FAILED_ALL(BAD_REQUEST, 10104, "알 수 없는 이유로 로그인 할 수 없습니다."),
LOGIN_FAILED_UNKNOWN(BAD_REQUEST, 10104, "알 수 없는 이유로 로그인 할 수 없습니다."),
KAKAO_MEMBER_EXIST(BAD_REQUEST, 10105, "카카오 로그인 계정이 존재합니다."),
GOOGLE_MEMBER_EXIST(BAD_REQUEST, 10505, "구글 로그인 계정이 존재합니다."),
NAVER_MEMBER_EXIST(BAD_REQUEST, 10605, "네이버 로그인 계정이 존재합니다."),
BASIC_MEMBER_EXIST(BAD_REQUEST, 10106, "일반 로그인 계정이 존재합니다."),


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice(basePackageClasses = ClotheController.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/umc/refit/web/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.umc.refit.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.web.client.RestTemplate;

@EnableJpaAuditing
@Configuration
public class AppConfig {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Loading
Loading