From daaf2d4e25ed8436d21bc76d31d03f4ef4079cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:07:56 +0900 Subject: [PATCH 01/14] [FEAT] Kakao Login Init Setting --- backend/.gitignore | 2 + backend/build.gradle | 1 + backend/docker-compose.yml | 15 ++++++++ .../com/twtw/backend/BackendApplication.java | 2 +- .../config/security/SecurityConfig.java | 13 +++++++ .../backend/config/security/jwt/JwtToken.java | 17 +++++++++ .../module/member/entity/AuthType.java | 6 +++ .../backend/module/member/entity/Member.java | 28 ++++++++++++++ .../module/member/entity/OAuth2Info.java | 38 +++++++++++++++++++ .../src/main/resources/application.properties | 1 - backend/src/main/resources/application.yml | 17 +++++++++ 11 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 backend/docker-compose.yml create mode 100644 backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java create mode 100644 backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/entity/Member.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java delete mode 100644 backend/src/main/resources/application.properties create mode 100644 backend/src/main/resources/application.yml diff --git a/backend/.gitignore b/backend/.gitignore index c2065bc2..a02a3af4 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -4,6 +4,8 @@ build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ +.env +backend/src/main/resources/application-oauth.yml ### STS ### .apt_generated diff --git a/backend/build.gradle b/backend/build.gradle index bb7a2421..0eb3152d 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -30,6 +30,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-amqp' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-webflux' diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml new file mode 100644 index 00000000..6e569023 --- /dev/null +++ b/backend/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3" + +services: + db: + image: mariadb:10 + ports: + - 3306:3306 + env_file: .env + environment: + TZ: Asia/Seoul + networks: + - backend + restart: always +networks: + backend: diff --git a/backend/src/main/java/com/twtw/backend/BackendApplication.java b/backend/src/main/java/com/twtw/backend/BackendApplication.java index 471009fa..d8a09665 100644 --- a/backend/src/main/java/com/twtw/backend/BackendApplication.java +++ b/backend/src/main/java/com/twtw/backend/BackendApplication.java @@ -5,8 +5,8 @@ @SpringBootApplication public class BackendApplication { - public static void main(String[] args) { + SpringApplication.run(BackendApplication.class, args); } diff --git a/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java b/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java new file mode 100644 index 00000000..5763b088 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java @@ -0,0 +1,13 @@ +package com.twtw.backend.config.security; + +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +@Configuration +@EnableWebSecurity +@RequiredArgsConstructor +public class SecurityConfig { + + +} diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java new file mode 100644 index 00000000..9ee0437b --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java @@ -0,0 +1,17 @@ +package com.twtw.backend.config.security.jwt; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class JwtToken { + private String accessToken; + private String refreshToken; + + @Builder + public JwtToken(String accessToken,String refreshToken) + { + this.accessToken = accessToken; + this.refreshToken = refreshToken; + } +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java b/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java new file mode 100644 index 00000000..9009e60d --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java @@ -0,0 +1,6 @@ +package com.twtw.backend.module.member.entity; + +public enum AuthType { + APPLE, + KAKAO +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java new file mode 100644 index 00000000..23f3c1ff --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java @@ -0,0 +1,28 @@ +package com.twtw.backend.module.member.entity; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Member { + @Id + @GeneratedValue(generator = "uuid2") + @Column(name = "id",columnDefinition = "BINARY(16)") + private UUID id; + + private String nickname; + + private String profileImage; + + private String phoneNumber; + + @Embedded + private OAuth2Info oAuth2Info; + +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java b/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java new file mode 100644 index 00000000..de324126 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java @@ -0,0 +1,38 @@ +package com.twtw.backend.module.member.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Objects; + +@Getter +@Embeddable +@AllArgsConstructor +@NoArgsConstructor +public class OAuth2Info { + + @Lob + @Column(nullable = false) + private String clientId; + + @Enumerated(value = EnumType.STRING) + private AuthType authType; + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + OAuth2Info tmp = (OAuth2Info) o; + + return Objects.equals(clientId,tmp.clientId) && authType == tmp.authType; + } + + @Override + public int hashCode() { + return Objects.hash(clientId,authType); + } +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/backend/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml new file mode 100644 index 00000000..3b37585e --- /dev/null +++ b/backend/src/main/resources/application.yml @@ -0,0 +1,17 @@ +server: + port: 8080 +spring: + profiles: + include: oauth + datasource: + driver-class-name: org.mariadb.jdbc.Driver + url: jdbc:mariadb://localhost:3306/TWTW + username: root + password: root! + jpa: + database: mysql + generate-ddl: true + show-sql: true + hibernate: + ddl-auto: create + From 020bf437f70980e3b9ba881ada6f1962212385a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Thu, 3 Aug 2023 23:37:03 +0900 Subject: [PATCH 02/14] [FEAT/ADD] Spring Security Setting + JWT Token Setting --- backend/build.gradle | 5 +- .../config/security/SecurityConfig.java | 43 ++++++- .../config/security/entity/RefreshToken.java | 24 ++++ .../security/jwt/JwtAccessDeniedHandler.java | 18 +++ .../jwt/JwtAuthenticationEntryPoint.java | 19 ++++ .../config/security/jwt/JwtFilter.java | 46 ++++++++ .../backend/config/security/jwt/JwtToken.java | 17 --- .../config/security/jwt/TokenProvider.java | 105 ++++++++++++++++++ .../repository/RefreshTokenRepository.java | 7 ++ .../member/controller/AuthController.java | 17 +++ .../member/controller/MemberController.java | 16 +++ .../backend/module/member/dto/TokenDto.java | 14 +++ .../module/member/entity/AuthType.java | 3 + .../backend/module/member/entity/Member.java | 10 ++ .../module/member/entity/OAuth2Info.java | 3 +- .../backend/module/member/entity/Role.java | 9 ++ .../member/repository/MemberRepository.java | 10 ++ .../module/member/service/AuthService.java | 22 ++++ .../module/member/service/MemberService.java | 14 +++ 19 files changed, 382 insertions(+), 20 deletions(-) create mode 100644 backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java create mode 100644 backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAccessDeniedHandler.java create mode 100644 backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAuthenticationEntryPoint.java create mode 100644 backend/src/main/java/com/twtw/backend/config/security/jwt/JwtFilter.java delete mode 100644 backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java create mode 100644 backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java create mode 100644 backend/src/main/java/com/twtw/backend/config/security/repository/RefreshTokenRepository.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/dto/TokenDto.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/entity/Role.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java diff --git a/backend/build.gradle b/backend/build.gradle index 0eb3152d..93a99598 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -30,10 +30,13 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-amqp' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive' - implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-webflux' + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' + implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' + compileOnly 'org.projectlombok:lombok' runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' annotationProcessor 'org.projectlombok:lombok' diff --git a/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java b/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java index 5763b088..d0c5574e 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java @@ -1,13 +1,54 @@ package com.twtw.backend.config.security; +import com.twtw.backend.config.security.jwt.JwtAccessDeniedHandler; +import com.twtw.backend.config.security.jwt.JwtAuthenticationEntryPoint; +import com.twtw.backend.config.security.jwt.JwtFilter; +import com.twtw.backend.config.security.jwt.TokenProvider; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.Customizer; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.SessionManagementConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; + +import java.util.function.ToDoubleBiFunction; + @Configuration @EnableWebSecurity @RequiredArgsConstructor -public class SecurityConfig { +public class SecurityConfig{ + private final JwtFilter jwtFilter; + private final JwtAccessDeniedHandler jwtAccessDeniedHandler; + private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint; + @Bean + public SecurityFilterChain configure(HttpSecurity http) throws Exception{ + return http.cors(cors -> cors.disable()).csrf(csrf -> csrf.disable()) + .httpBasic(h -> h.disable()) + .formLogin(f -> f.disable()) + .authorizeHttpRequests( + x->x.requestMatchers("/auth/**","members") + .permitAll() + .anyRequest() + .authenticated() + ) + .sessionManagement(x -> x.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class) + .exceptionHandling( + x -> { + x.authenticationEntryPoint(jwtAuthenticationEntryPoint); + x.accessDeniedHandler(jwtAccessDeniedHandler); + } + ).build(); + } } diff --git a/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java b/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java new file mode 100644 index 00000000..b9fa2bd7 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java @@ -0,0 +1,24 @@ +package com.twtw.backend.config.security.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RefreshToken { + @Id + private String tokenKey; + + private String tokenValue; + + public RefreshToken(String tokenKey,String tokenValue) + { + this.tokenKey = tokenKey; + this.tokenValue = tokenValue; + } +} diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAccessDeniedHandler.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAccessDeniedHandler.java new file mode 100644 index 00000000..e3ee61af --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAccessDeniedHandler.java @@ -0,0 +1,18 @@ +package com.twtw.backend.config.security.jwt; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.web.access.AccessDeniedHandler; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Component +public class JwtAccessDeniedHandler implements AccessDeniedHandler { + @Override + public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + } +} diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAuthenticationEntryPoint.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAuthenticationEntryPoint.java new file mode 100644 index 00000000..b346f2a5 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtAuthenticationEntryPoint.java @@ -0,0 +1,19 @@ +package com.twtw.backend.config.security.jwt; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Component +public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { + + @Override + public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } +} diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtFilter.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtFilter.java new file mode 100644 index 00000000..3a3c1fba --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtFilter.java @@ -0,0 +1,46 @@ +package com.twtw.backend.config.security.jwt; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; + +@Component +@RequiredArgsConstructor +public class JwtFilter extends OncePerRequestFilter { + + private final TokenProvider tokenProvider; + private final String AUTHORIZATION_HEADER = "Authorization"; + private final String BEARER_PREFIX = "Bearer "; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + String jwt = resolveToken(request); + + if(StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) + { + Authentication authentication = tokenProvider.getAuthentication(jwt); + SecurityContextHolder.getContext().setAuthentication(authentication); + } + filterChain.doFilter(request,response); + } + + private String resolveToken(HttpServletRequest request) { + String bearerToken = request.getHeader(AUTHORIZATION_HEADER); + + if(StringUtils.hasText(bearerToken) && bearerToken.startsWith(BEARER_PREFIX)) + { + return bearerToken.substring(7); + } + + return null; + } +} diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java deleted file mode 100644 index 9ee0437b..00000000 --- a/backend/src/main/java/com/twtw/backend/config/security/jwt/JwtToken.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.twtw.backend.config.security.jwt; - -import lombok.Builder; -import lombok.Getter; - -@Getter -public class JwtToken { - private String accessToken; - private String refreshToken; - - @Builder - public JwtToken(String accessToken,String refreshToken) - { - this.accessToken = accessToken; - this.refreshToken = refreshToken; - } -} diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java new file mode 100644 index 00000000..b6e95ee7 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java @@ -0,0 +1,105 @@ +package com.twtw.backend.config.security.jwt; +import com.twtw.backend.module.member.dto.TokenDto; +import io.jsonwebtoken.*; +import io.jsonwebtoken.io.Decoders; +import io.jsonwebtoken.security.Keys; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; + +import java.security.Key; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.stream.Collectors; + +@Component +public class TokenProvider implements InitializingBean { + private Key key; + private final String secretKey; + private static final String AUTHORITIES_KEY = "auth"; + private static final Long ACCESS_TOKEN_EXPIRE_LENGTH = 60L * 60 * 24 * 1000; // 1 Day + private static final Long REFRESH_TOKEN_EXPIRE_LENGTH = 60L * 60 * 24 * 14 * 1000; // 14 Days + + public TokenProvider( + @Value("${jwt.secret}") String secretKey + ){ + this.secretKey = secretKey; + } + + @Override + public void afterPropertiesSet() throws Exception { + byte[] keyBytes = Decoders.BASE64.decode(secretKey); + this.key = Keys.hmacShaKeyFor(keyBytes); + } + + public TokenDto createToken(Authentication authentication) { + String authorities = authentication.getAuthorities().stream() + .map(GrantedAuthority::getAuthority) + .collect(Collectors.joining(",")); + + Long now = (new Date()).getTime(); + Date validAccessDate = new Date(now + ACCESS_TOKEN_EXPIRE_LENGTH); + Date validRefreshDate = new Date(now + REFRESH_TOKEN_EXPIRE_LENGTH); + + String accessToken = Jwts.builder() + .setSubject(authentication.getName()) + .claim(AUTHORITIES_KEY,authorities) + .signWith(key, SignatureAlgorithm.HS512) + .setExpiration(validAccessDate) + .compact(); + + String refreshToken = Jwts.builder() + .setExpiration(validRefreshDate) + .signWith(key,SignatureAlgorithm.HS512) + .compact(); + + return new TokenDto(accessToken,refreshToken,validAccessDate.getTime()); + } + + public Authentication getAuthentication(String accessToken) { + Claims claims = parseClaims(accessToken); + + if(claims.get(AUTHORITIES_KEY) == null) + { + throw new RuntimeException("권한 정보가 없는 토큰입니다."); + } + + Collection authorities = + Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(",")) + .map(SimpleGrantedAuthority::new) + .collect(Collectors.toList()); + + UserDetails principal = new User(claims.getSubject(),"",authorities); + + return new UsernamePasswordAuthenticationToken(principal,accessToken,authorities); + + } + + public boolean validateToken(String accessToken) { + try{ + Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(accessToken); + return true; + }catch (ExpiredJwtException | UnsupportedJwtException | IllegalStateException e) { + return false; + } + } + + private Claims parseClaims(String accessToken) { + try{ + Claims claims = Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(accessToken).getBody(); + return claims; + }catch (ExpiredJwtException e) + { + return e.getClaims(); + } + } + +} diff --git a/backend/src/main/java/com/twtw/backend/config/security/repository/RefreshTokenRepository.java b/backend/src/main/java/com/twtw/backend/config/security/repository/RefreshTokenRepository.java new file mode 100644 index 00000000..2a2e1263 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/repository/RefreshTokenRepository.java @@ -0,0 +1,7 @@ +package com.twtw.backend.config.security.repository; + +import com.twtw.backend.config.security.entity.RefreshToken; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RefreshTokenRepository extends JpaRepository { +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java new file mode 100644 index 00000000..5d743d8b --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java @@ -0,0 +1,17 @@ +package com.twtw.backend.module.member.controller; + +import com.twtw.backend.module.member.service.AuthService; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/auth") +public class AuthController { + private final AuthService authService; + + public AuthController(AuthService authService) { + this.authService = authService; + } + + +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java new file mode 100644 index 00000000..aec87a44 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java @@ -0,0 +1,16 @@ +package com.twtw.backend.module.member.controller; + +import com.twtw.backend.module.member.service.MemberService; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/member") +public class MemberController { + private final MemberService memberService; + + public MemberController(MemberService memberService) + { + this.memberService = memberService; + } +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/TokenDto.java b/backend/src/main/java/com/twtw/backend/module/member/dto/TokenDto.java new file mode 100644 index 00000000..f119576e --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/TokenDto.java @@ -0,0 +1,14 @@ +package com.twtw.backend.module.member.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class TokenDto { + private String accessToken; + private String refreshToken; + private final Long accessTokenExpiresIn; +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java b/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java index 9009e60d..e53f6c8f 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java @@ -1,5 +1,8 @@ package com.twtw.backend.module.member.entity; +import lombok.Getter; + +@Getter public enum AuthType { APPLE, KAKAO diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java index 23f3c1ff..1648da9a 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java @@ -25,4 +25,14 @@ public class Member { @Embedded private OAuth2Info oAuth2Info; + + public Member(String nickname,String profileImage,String phoneNumber) { + this.nickname = nickname; + this.profileImage = profileImage; + this.phoneNumber = phoneNumber; + } + + public void updateOAuth(OAuth2Info oAuth2Info){ + this.oAuth2Info = oAuth2Info; + } } diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java b/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java index de324126..2779aea3 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java @@ -1,6 +1,7 @@ package com.twtw.backend.module.member.entity; import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,7 +11,7 @@ @Getter @Embeddable @AllArgsConstructor -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class OAuth2Info { @Lob diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java b/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java new file mode 100644 index 00000000..da3cfde4 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java @@ -0,0 +1,9 @@ +package com.twtw.backend.module.member.entity; + +import lombok.Getter; + +@Getter +public enum Role { + ADMIN, + USER +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java b/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java new file mode 100644 index 00000000..777844c4 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java @@ -0,0 +1,10 @@ +package com.twtw.backend.module.member.repository; + + +import com.twtw.backend.module.member.entity.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface MemberRepository extends JpaRepository { +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java new file mode 100644 index 00000000..83cbe7e0 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java @@ -0,0 +1,22 @@ +package com.twtw.backend.module.member.service; + +import com.twtw.backend.config.security.jwt.TokenProvider; +import com.twtw.backend.config.security.repository.RefreshTokenRepository; +import com.twtw.backend.module.member.repository.MemberRepository; +import org.springframework.stereotype.Service; + +@Service +public class AuthService { + private final MemberRepository memberRepository; + private final RefreshTokenRepository refreshTokenRepository; + private final TokenProvider tokenProvider; + + + public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider) { + this.memberRepository = memberRepository; + this.refreshTokenRepository = refreshTokenRepository; + this.tokenProvider = tokenProvider; + } + + +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java new file mode 100644 index 00000000..40548cfb --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java @@ -0,0 +1,14 @@ +package com.twtw.backend.module.member.service; + +import com.twtw.backend.module.member.repository.MemberRepository; +import org.springframework.stereotype.Service; + +@Service +public class MemberService { + private final MemberRepository memberRepository; + + public MemberService(MemberRepository memberRepository) + { + this.memberRepository = memberRepository; + } +} From f95e991cc6d2dd74adb6330c97b02d7ac2a087b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 7 Aug 2023 04:05:11 +0900 Subject: [PATCH 03/14] =?UTF-8?q?[FEAT/ADD]=20Auth=20Controller=20+=20Swag?= =?UTF-8?q?ger(=EC=9E=84=EC=8B=9C)=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 2 +- .../config/security/SecurityConfig.java | 19 ++-- .../config/security/entity/RefreshToken.java | 2 + .../config/security/jwt/TokenProvider.java | 22 +++-- .../service/CustomMemberDetailService.java | 41 +++++++++ .../module/member/SwaggerConfiguration.java | 31 +++++++ .../member/controller/AuthController.java | 31 ++++++- .../member/controller/MemberController.java | 8 +- .../member/dto/request/MemberRequest.java | 24 +++++ .../member/dto/request/TokenRequest.java | 13 +++ .../backend/module/member/entity/Member.java | 9 +- .../backend/module/member/entity/Role.java | 4 +- .../member/repository/MemberRepository.java | 2 + .../module/member/service/AuthService.java | 87 ++++++++++++++++++- .../module/member/service/MemberService.java | 9 +- 15 files changed, 275 insertions(+), 29 deletions(-) create mode 100644 backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/SwaggerConfiguration.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberRequest.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/dto/request/TokenRequest.java diff --git a/backend/build.gradle b/backend/build.gradle index 93a99598..924bd97f 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -36,7 +36,7 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-api:0.11.5' implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' - + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' compileOnly 'org.projectlombok:lombok' runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' annotationProcessor 'org.projectlombok:lombok' diff --git a/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java b/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java index d0c5574e..22949c67 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/twtw/backend/config/security/SecurityConfig.java @@ -3,24 +3,17 @@ import com.twtw.backend.config.security.jwt.JwtAccessDeniedHandler; import com.twtw.backend.config.security.jwt.JwtAuthenticationEntryPoint; import com.twtw.backend.config.security.jwt.JwtFilter; -import com.twtw.backend.config.security.jwt.TokenProvider; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configurers.SessionManagementConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.NoOpPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.CorsConfigurationSource; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; - -import java.util.function.ToDoubleBiFunction; - @Configuration @EnableWebSecurity @@ -36,7 +29,11 @@ public SecurityFilterChain configure(HttpSecurity http) throws Exception{ .httpBasic(h -> h.disable()) .formLogin(f -> f.disable()) .authorizeHttpRequests( - x->x.requestMatchers("/auth/**","members") + x->x.requestMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html","auth/**") + .permitAll() + ) + .authorizeHttpRequests( + x->x.requestMatchers("/test/**") .permitAll() .anyRequest() .authenticated() diff --git a/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java b/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java index b9fa2bd7..d646a29f 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java +++ b/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java @@ -6,6 +6,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.UUID; + @Entity @Getter diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java index b6e95ee7..d5b57997 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Component; import java.security.Key; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Date; @@ -22,6 +23,7 @@ @Component public class TokenProvider implements InitializingBean { + private Key key; private final String secretKey; private static final String AUTHORITIES_KEY = "auth"; @@ -72,20 +74,24 @@ public Authentication getAuthentication(String accessToken) { throw new RuntimeException("권한 정보가 없는 토큰입니다."); } - Collection authorities = - Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(",")) - .map(SimpleGrantedAuthority::new) - .collect(Collectors.toList()); + Collection authorities = new ArrayList<>(); + String role = claims.get(AUTHORITIES_KEY).toString(); + + if(role.equals("ROLE_ADMIN")) { + authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN")); + } - UserDetails principal = new User(claims.getSubject(),"",authorities); + else if(role.equals("ROLE_USER")){ + authorities.add(new SimpleGrantedAuthority("ROLE_USER")); + } - return new UsernamePasswordAuthenticationToken(principal,accessToken,authorities); + return new UsernamePasswordAuthenticationToken(claims.getSubject(),"",authorities); } - public boolean validateToken(String accessToken) { + public boolean validateToken(String token) { try{ - Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(accessToken); + Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token); return true; }catch (ExpiredJwtException | UnsupportedJwtException | IllegalStateException e) { return false; diff --git a/backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java b/backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java new file mode 100644 index 00000000..65cf5935 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java @@ -0,0 +1,41 @@ +package com.twtw.backend.config.security.service; + +import com.twtw.backend.module.member.entity.Member; +import com.twtw.backend.module.member.repository.MemberRepository; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import java.util.*; + +@Service +public class CustomMemberDetailService implements UserDetailsService { + + private final MemberRepository memberRepository; + + CustomMemberDetailService(MemberRepository memberRepository) { + this.memberRepository = memberRepository; + } + + @Override + public UserDetails loadUserByUsername(String username){ + Optional member = memberRepository.findById(UUID.fromString(username)); + + if(member.isEmpty()) { + throw new UsernameNotFoundException("User Not Found"); + } + + Member curMember = member.get(); + + GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(curMember.getRole().toString()); + Collection list = new ArrayList<>(); + list.add(grantedAuthority); + + return new User(curMember.getId().toString(),"",list); + } + +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/SwaggerConfiguration.java b/backend/src/main/java/com/twtw/backend/module/member/SwaggerConfiguration.java new file mode 100644 index 00000000..438da01e --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/SwaggerConfiguration.java @@ -0,0 +1,31 @@ +package com.twtw.backend.module.member; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import java.util.List; + +@Configuration +public class SwaggerConfiguration { + @Bean + public OpenAPI getOpenAPI() { + return new OpenAPI() + .info( + new Info().title("TWTW") + .description("Hong Dam Jin") + .version("v0.0.1") + ) + .components( + new Components().addSecuritySchemes( + "bearerAuth", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT") + .in(SecurityScheme.In.HEADER).name("Authorization") + ) + ).security( + List.of(new SecurityRequirement().addList("bearerAuth")) + ); + } +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java index 5d743d8b..5123b348 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java @@ -1,8 +1,14 @@ package com.twtw.backend.module.member.controller; +import com.twtw.backend.module.member.dto.TokenDto; +import com.twtw.backend.module.member.dto.request.MemberRequest; +import com.twtw.backend.module.member.dto.request.TokenRequest; import com.twtw.backend.module.member.service.AuthService; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.UUID; @RestController @RequestMapping("/auth") @@ -13,5 +19,26 @@ public AuthController(AuthService authService) { this.authService = authService; } + @PostMapping("/refresh") + public ResponseEntity authorize(@RequestBody TokenRequest tokenRequest) { + return ResponseEntity.ok(authService.refreshToken(tokenRequest.getAccessToken(),tokenRequest.getRefreshToken())); + } + + @PostMapping("/save") + public ResponseEntity saveMember(@RequestBody MemberRequest memberRequest) { + authService.saveMember(memberRequest); + return ResponseEntity.status(HttpStatus.OK).body(null); + } + + @GetMapping("/check/{id}") + public ResponseEntity checkMember(@PathVariable(name = "id") String uuid){ + try{ + TokenDto tokenDto = authService.checkMember(UUID.fromString(uuid)); + return ResponseEntity.ok(tokenDto); + }catch (Exception e) + { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); + } + } } diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java index aec87a44..16445ae2 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java @@ -1,6 +1,7 @@ package com.twtw.backend.module.member.controller; import com.twtw.backend.module.member.service.MemberService; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -8,9 +9,14 @@ @RequestMapping("/member") public class MemberController { private final MemberService memberService; - public MemberController(MemberService memberService) { this.memberService = memberService; } + + @GetMapping("/memer1") + public String getMember() + { + return "hello"; + } } diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberRequest.java b/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberRequest.java new file mode 100644 index 00000000..7bea90a9 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberRequest.java @@ -0,0 +1,24 @@ +package com.twtw.backend.module.member.dto.request; + +import com.twtw.backend.module.member.entity.Role; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class MemberRequest { + private String userEmail; + + private String nickname; + + private String profileImage; + + private String phoneNumber; + + @Enumerated(EnumType.STRING) + private Role role; +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/TokenRequest.java b/backend/src/main/java/com/twtw/backend/module/member/dto/request/TokenRequest.java new file mode 100644 index 00000000..2c7b163a --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/request/TokenRequest.java @@ -0,0 +1,13 @@ +package com.twtw.backend.module.member.dto.request; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class TokenRequest { + String accessToken; + String refreshToken; +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java index 1648da9a..8fc344a9 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java @@ -16,20 +16,27 @@ public class Member { @Column(name = "id",columnDefinition = "BINARY(16)") private UUID id; + private String userEmail; + private String nickname; private String profileImage; private String phoneNumber; + @Enumerated(EnumType.STRING) + private Role role; + @Embedded private OAuth2Info oAuth2Info; - public Member(String nickname,String profileImage,String phoneNumber) { + public Member(String userEmail,String nickname,String profileImage,String phoneNumber,Role role) { + this.userEmail = userEmail; this.nickname = nickname; this.profileImage = profileImage; this.phoneNumber = phoneNumber; + this.role = role; } public void updateOAuth(OAuth2Info oAuth2Info){ diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java b/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java index da3cfde4..b154754e 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java @@ -4,6 +4,6 @@ @Getter public enum Role { - ADMIN, - USER + ROLE_ADMIN, + ROLE_USER } diff --git a/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java b/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java index 777844c4..aa57df5f 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java +++ b/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java @@ -4,7 +4,9 @@ import com.twtw.backend.module.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; import java.util.UUID; public interface MemberRepository extends JpaRepository { + Optional findById(UUID uuid); } diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java index 83cbe7e0..e602eadb 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java @@ -1,21 +1,106 @@ package com.twtw.backend.module.member.service; +import com.twtw.backend.config.security.entity.RefreshToken; import com.twtw.backend.config.security.jwt.TokenProvider; import com.twtw.backend.config.security.repository.RefreshTokenRepository; +import com.twtw.backend.module.member.dto.TokenDto; +import com.twtw.backend.module.member.dto.request.MemberRequest; +import com.twtw.backend.module.member.entity.AuthType; +import com.twtw.backend.module.member.entity.Member; +import com.twtw.backend.module.member.entity.OAuth2Info; import com.twtw.backend.module.member.repository.MemberRepository; + +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + @Service public class AuthService { private final MemberRepository memberRepository; private final RefreshTokenRepository refreshTokenRepository; private final TokenProvider tokenProvider; + private final AuthenticationManagerBuilder authenticationManagerBuilder; - public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider) { + + public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider,AuthenticationManagerBuilder authenticationManagerBuilder) { this.memberRepository = memberRepository; this.refreshTokenRepository = refreshTokenRepository; this.tokenProvider = tokenProvider; + this.authenticationManagerBuilder = authenticationManagerBuilder; + } + + private Member toEntity(MemberRequest request) + { + Member member = new Member(request.getUserEmail(), request.getNickname(), request.getProfileImage(), request.getPhoneNumber(), request.getRole()); + return member; + } + + public void saveMember(MemberRequest request){ + Member member = toEntity(request); + member.updateOAuth(new OAuth2Info("1111", AuthType.KAKAO)); + memberRepository.save(member); + } + + /*임시 메소드*/ + public TokenDto checkMember(UUID uuid) { + Optional member = memberRepository.findById(uuid); + + if(!member.isPresent()) + return null; + + Member curMember = member.get(); + List role = new ArrayList<>(); + role.add(new SimpleGrantedAuthority(curMember.getRole().toString())); + UsernamePasswordAuthenticationToken credit = new UsernamePasswordAuthenticationToken(uuid.toString(),"",role); + + TokenDto token = tokenProvider.createToken(credit); + + refreshTokenRepository.save(new RefreshToken(curMember.getId().toString(),token.getRefreshToken())); + + return token; + } + + /* + * Token 재발급 + * 1. refreshToken validate 확인 + * 2. refreshToken DB 정보 확인 + * 3. 토큰 만들어서 반환 + * */ + + public TokenDto refreshToken(String accessToken, String refreshToken){ + if(!tokenProvider.validateToken(refreshToken)) { + throw new RuntimeException("Refresh Token이 유효하지 않습니다."); + } + + Authentication authentication = tokenProvider.getAuthentication(accessToken); + + String userName = authentication.getName(); + + if(!getRefreshTokenValue(userName).equals(refreshToken)) { + throw new RuntimeException("Refresh Token 정보가 일치하지 않습니다."); + } + + return saveRefreshToken(authentication,userName); + } + + public String getRefreshTokenValue(String tokenKey) { + return refreshTokenRepository.getReferenceById(tokenKey).getTokenValue(); + } + + public TokenDto saveRefreshToken(Authentication authentication,String userName){ + TokenDto token = tokenProvider.createToken(authentication); + refreshTokenRepository.save(new RefreshToken(userName,token.getRefreshToken())); + + return token; } diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java index 40548cfb..25e00b15 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java @@ -1,14 +1,19 @@ package com.twtw.backend.module.member.service; +import com.twtw.backend.config.security.jwt.TokenProvider; +import com.twtw.backend.module.member.dto.TokenDto; +import com.twtw.backend.module.member.dto.request.MemberRequest; +import com.twtw.backend.module.member.entity.Member; import com.twtw.backend.module.member.repository.MemberRepository; import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.GetMapping; @Service public class MemberService { private final MemberRepository memberRepository; - public MemberService(MemberRepository memberRepository) - { + public MemberService(MemberRepository memberRepository) { this.memberRepository = memberRepository; } + } From bc9c3bb34c0aec9e9fa6988ec3d437fb0ffb90d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 7 Aug 2023 14:59:29 +0900 Subject: [PATCH 04/14] =?UTF-8?q?[FIX]=20Token=20PasswordEncoder=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CustomMemberDetailService.java | 41 ------------------- .../module/member/service/AuthService.java | 6 +-- 2 files changed, 1 insertion(+), 46 deletions(-) delete mode 100644 backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java diff --git a/backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java b/backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java deleted file mode 100644 index 65cf5935..00000000 --- a/backend/src/main/java/com/twtw/backend/config/security/service/CustomMemberDetailService.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.twtw.backend.config.security.service; - -import com.twtw.backend.module.member.entity.Member; -import com.twtw.backend.module.member.repository.MemberRepository; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; - -import java.util.*; - -@Service -public class CustomMemberDetailService implements UserDetailsService { - - private final MemberRepository memberRepository; - - CustomMemberDetailService(MemberRepository memberRepository) { - this.memberRepository = memberRepository; - } - - @Override - public UserDetails loadUserByUsername(String username){ - Optional member = memberRepository.findById(UUID.fromString(username)); - - if(member.isEmpty()) { - throw new UsernameNotFoundException("User Not Found"); - } - - Member curMember = member.get(); - - GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(curMember.getRole().toString()); - Collection list = new ArrayList<>(); - list.add(grantedAuthority); - - return new User(curMember.getId().toString(),"",list); - } - -} diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java index e602eadb..9134765e 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java @@ -28,14 +28,10 @@ public class AuthService { private final RefreshTokenRepository refreshTokenRepository; private final TokenProvider tokenProvider; - private final AuthenticationManagerBuilder authenticationManagerBuilder; - - - public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider,AuthenticationManagerBuilder authenticationManagerBuilder) { + public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider) { this.memberRepository = memberRepository; this.refreshTokenRepository = refreshTokenRepository; this.tokenProvider = tokenProvider; - this.authenticationManagerBuilder = authenticationManagerBuilder; } private Member toEntity(MemberRequest request) From 8ee5846100e5af654892365152c2fd149037758f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:03:09 +0900 Subject: [PATCH 05/14] =?UTF-8?q?[FIX]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=B0=B8=EC=A1=B0=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/module/member/controller/MemberController.java | 5 ----- .../com/twtw/backend/module/member/service/AuthService.java | 1 - .../twtw/backend/module/member/service/MemberService.java | 1 - 3 files changed, 7 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java index 16445ae2..9f075046 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java @@ -14,9 +14,4 @@ public MemberController(MemberService memberService) this.memberService = memberService; } - @GetMapping("/memer1") - public String getMember() - { - return "hello"; - } } diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java index 9134765e..1fee2a9e 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java @@ -11,7 +11,6 @@ import com.twtw.backend.module.member.repository.MemberRepository; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java index 25e00b15..4c1f1de2 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java @@ -11,7 +11,6 @@ @Service public class MemberService { private final MemberRepository memberRepository; - public MemberService(MemberRepository memberRepository) { this.memberRepository = memberRepository; } From b04ad29f9f2c5b835159de2abcc15c6ae733ea77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:10:31 +0900 Subject: [PATCH 06/14] =?UTF-8?q?[FIX]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=B0=B8=EC=A1=B0=20=EC=82=AD=EC=A0=9C=20+=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/twtw/backend/config/security/entity/RefreshToken.java | 3 --- .../twtw/backend/module/member/controller/AuthController.java | 4 ++++ .../backend/module/member/controller/MemberController.java | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java b/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java index d646a29f..1b44ac3c 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java +++ b/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java @@ -6,9 +6,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.UUID; - - @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java index 5123b348..b952ebaf 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java @@ -41,4 +41,8 @@ public ResponseEntity checkMember(@PathVariable(name = "id") String uu return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); } } + + // TODO("OAuth2Info 를 이용하여 토큰 발급 메소드"); + // TODO("SOFT DELETE 구현"); + } diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java index 9f075046..76b30194 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java @@ -1,7 +1,6 @@ package com.twtw.backend.module.member.controller; import com.twtw.backend.module.member.service.MemberService; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; From 13f7ba1bf9658e81f7e7593aa537e89aa466f88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 7 Aug 2023 16:30:23 +0900 Subject: [PATCH 07/14] =?UTF-8?q?[ADD]=20AuthController=20+=20AuthService?= =?UTF-8?q?=20:=20saveMember=20,=20afterSocialLogin=20,=20refreshToken=20?= =?UTF-8?q?=EC=9E=AC=EB=B0=9C=EA=B8=89=20=EA=B8=B0=EB=B3=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C=20(?= =?UTF-8?q?=EC=B9=B4=EC=B9=B4=EC=98=A4=20=EC=97=B0=EB=8F=99=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80=20=ED=95=84=EC=9A=94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/security/jwt/TokenProvider.java | 6 +- .../member/controller/AuthController.java | 31 ++++----- .../member/controller/MemberController.java | 1 + ...berRequest.java => MemberSaveRequest.java} | 7 +- .../member/dto/request/OAuthRequest.java | 18 +++++ .../member/dto/{ => response}/TokenDto.java | 2 +- .../backend/module/member/entity/Member.java | 5 +- .../member/repository/MemberRepository.java | 5 ++ .../module/member/service/AuthService.java | 67 ++++++++++++------- .../module/member/service/MemberService.java | 5 -- 10 files changed, 92 insertions(+), 55 deletions(-) rename backend/src/main/java/com/twtw/backend/module/member/dto/request/{MemberRequest.java => MemberSaveRequest.java} (78%) create mode 100644 backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java rename backend/src/main/java/com/twtw/backend/module/member/dto/{ => response}/TokenDto.java (82%) diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java index d5b57997..08c092e9 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java @@ -1,5 +1,5 @@ package com.twtw.backend.config.security.jwt; -import com.twtw.backend.module.member.dto.TokenDto; +import com.twtw.backend.module.member.dto.response.TokenDto; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.security.Keys; @@ -10,13 +10,10 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Component; import java.security.Key; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.stream.Collectors; @@ -42,6 +39,7 @@ public void afterPropertiesSet() throws Exception { this.key = Keys.hmacShaKeyFor(keyBytes); } + public TokenDto createToken(Authentication authentication) { String authorities = authentication.getAuthorities().stream() .map(GrantedAuthority::getAuthority) diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java index b952ebaf..e22cfb21 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java @@ -1,7 +1,9 @@ package com.twtw.backend.module.member.controller; -import com.twtw.backend.module.member.dto.TokenDto; -import com.twtw.backend.module.member.dto.request.MemberRequest; +import com.twtw.backend.config.security.repository.RefreshTokenRepository; +import com.twtw.backend.module.member.dto.request.OAuthRequest; +import com.twtw.backend.module.member.dto.response.TokenDto; +import com.twtw.backend.module.member.dto.request.MemberSaveRequest; import com.twtw.backend.module.member.dto.request.TokenRequest; import com.twtw.backend.module.member.service.AuthService; import org.springframework.http.HttpStatus; @@ -25,24 +27,23 @@ public ResponseEntity authorize(@RequestBody TokenRequest tokenRequest } @PostMapping("/save") - public ResponseEntity saveMember(@RequestBody MemberRequest memberRequest) { - authService.saveMember(memberRequest); + public ResponseEntity saveMember(@RequestBody MemberSaveRequest memberSaveRequest) { + authService.saveMember(memberSaveRequest); return ResponseEntity.status(HttpStatus.OK).body(null); } - @GetMapping("/check/{id}") - public ResponseEntity checkMember(@PathVariable(name = "id") String uuid){ - try{ - TokenDto tokenDto = authService.checkMember(UUID.fromString(uuid)); - return ResponseEntity.ok(tokenDto); - }catch (Exception e) - { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); + @PostMapping("/login") + public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest request){ + TokenDto tokenDto = authService.getTokenByOAuth(request); + + if(tokenDto == null){ + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(tokenDto); } - } - // TODO("OAuth2Info 를 이용하여 토큰 발급 메소드"); - // TODO("SOFT DELETE 구현"); + else{ + return ResponseEntity.status(HttpStatus.OK).body(tokenDto); + } + } } diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java index 76b30194..467b6494 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java @@ -13,4 +13,5 @@ public MemberController(MemberService memberService) this.memberService = memberService; } + } diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberRequest.java b/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberSaveRequest.java similarity index 78% rename from backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberRequest.java rename to backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberSaveRequest.java index 7bea90a9..c405aece 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberRequest.java +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberSaveRequest.java @@ -1,5 +1,6 @@ package com.twtw.backend.module.member.dto.request; +import com.twtw.backend.module.member.entity.OAuth2Info; import com.twtw.backend.module.member.entity.Role; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -10,9 +11,7 @@ @Getter @Setter @RequiredArgsConstructor -public class MemberRequest { - private String userEmail; - +public class MemberSaveRequest { private String nickname; private String profileImage; @@ -21,4 +20,6 @@ public class MemberRequest { @Enumerated(EnumType.STRING) private Role role; + + private OAuthRequest oAuthRequest; } diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java b/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java new file mode 100644 index 00000000..f7c37eb3 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java @@ -0,0 +1,18 @@ +package com.twtw.backend.module.member.dto.request; + +import com.twtw.backend.module.member.entity.AuthType; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class OAuthRequest { + private String clientId; + + @Enumerated(EnumType.STRING) + private AuthType authType; +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/TokenDto.java b/backend/src/main/java/com/twtw/backend/module/member/dto/response/TokenDto.java similarity index 82% rename from backend/src/main/java/com/twtw/backend/module/member/dto/TokenDto.java rename to backend/src/main/java/com/twtw/backend/module/member/dto/response/TokenDto.java index f119576e..55c8d698 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/TokenDto.java +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/response/TokenDto.java @@ -1,4 +1,4 @@ -package com.twtw.backend.module.member.dto; +package com.twtw.backend.module.member.dto.response; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java index 8fc344a9..ed8fa062 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java +++ b/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java @@ -16,8 +16,6 @@ public class Member { @Column(name = "id",columnDefinition = "BINARY(16)") private UUID id; - private String userEmail; - private String nickname; private String profileImage; @@ -31,8 +29,7 @@ public class Member { private OAuth2Info oAuth2Info; - public Member(String userEmail,String nickname,String profileImage,String phoneNumber,Role role) { - this.userEmail = userEmail; + public Member(String nickname,String profileImage,String phoneNumber,Role role) { this.nickname = nickname; this.profileImage = profileImage; this.phoneNumber = phoneNumber; diff --git a/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java b/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java index aa57df5f..75ca47c3 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java +++ b/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java @@ -1,12 +1,17 @@ package com.twtw.backend.module.member.repository; +import com.twtw.backend.module.member.entity.AuthType; import com.twtw.backend.module.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.Optional; import java.util.UUID; public interface MemberRepository extends JpaRepository { Optional findById(UUID uuid); + + @Query("SELECT m FROM Member m WHERE m.oAuth2Info.clientId = :OAuthId AND m.oAuth2Info.authType = :authType") + Optional findByOAuthIdAndAuthType(String OAuthId, AuthType authType); } diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java index 1fee2a9e..ae902b0e 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java @@ -3,9 +3,9 @@ import com.twtw.backend.config.security.entity.RefreshToken; import com.twtw.backend.config.security.jwt.TokenProvider; import com.twtw.backend.config.security.repository.RefreshTokenRepository; -import com.twtw.backend.module.member.dto.TokenDto; -import com.twtw.backend.module.member.dto.request.MemberRequest; -import com.twtw.backend.module.member.entity.AuthType; +import com.twtw.backend.module.member.dto.request.OAuthRequest; +import com.twtw.backend.module.member.dto.response.TokenDto; +import com.twtw.backend.module.member.dto.request.MemberSaveRequest; import com.twtw.backend.module.member.entity.Member; import com.twtw.backend.module.member.entity.OAuth2Info; import com.twtw.backend.module.member.repository.MemberRepository; @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.UUID; @Service public class AuthService { @@ -33,37 +32,59 @@ public AuthService(MemberRepository memberRepository,RefreshTokenRepository refr this.tokenProvider = tokenProvider; } - private Member toEntity(MemberRequest request) + private Member toMemberEntity(MemberSaveRequest request) { - Member member = new Member(request.getUserEmail(), request.getNickname(), request.getProfileImage(), request.getPhoneNumber(), request.getRole()); + Member member = new Member(request.getNickname(), request.getProfileImage(), request.getPhoneNumber(), request.getRole()); return member; } - public void saveMember(MemberRequest request){ - Member member = toEntity(request); - member.updateOAuth(new OAuth2Info("1111", AuthType.KAKAO)); - memberRepository.save(member); + private OAuth2Info toOAuthInfo(OAuthRequest request) + { + OAuth2Info info = new OAuth2Info(request.getClientId(),request.getAuthType()); + + return info; } - /*임시 메소드*/ - public TokenDto checkMember(UUID uuid) { - Optional member = memberRepository.findById(uuid); + /* + * 1. after social SignUp + * 2. 기본 정보 기입 + * 3. OAuth Info 저장 -> kakao , apple enum 구분 + * 4. 저장 + * 5. 토큰(jwt) 발급 + * */ + public void saveMember(MemberSaveRequest request){ + Member member = toMemberEntity(request); + member.updateOAuth(toOAuthInfo(request.getOAuthRequest())); + memberRepository.save(member); + } + /* + * 1.로그인(Social) 후의 토큰 발급 + * 2.JWT 토큰 발급 -> OAuth 정보 (clientId , AuthType)으로 진행 + * + * */ + public TokenDto getTokenByOAuth(OAuthRequest request) { + Optional member = memberRepository.findByOAuthIdAndAuthType(request.getClientId(),request.getAuthType()); + + if(member.isPresent()) { + Member curMember = member.get(); + UsernamePasswordAuthenticationToken credit = makeCredit(curMember); + TokenDto tokenDto = saveRefreshToken(credit,curMember.getId().toString()); + return tokenDto; + } - if(!member.isPresent()) - return null; + return null; + } - Member curMember = member.get(); + private UsernamePasswordAuthenticationToken makeCredit(Member member) + { List role = new ArrayList<>(); - role.add(new SimpleGrantedAuthority(curMember.getRole().toString())); - UsernamePasswordAuthenticationToken credit = new UsernamePasswordAuthenticationToken(uuid.toString(),"",role); + role.add(new SimpleGrantedAuthority(member.getRole().toString())); + UsernamePasswordAuthenticationToken credit = new UsernamePasswordAuthenticationToken(member.getId().toString(),"",role); - TokenDto token = tokenProvider.createToken(credit); - - refreshTokenRepository.save(new RefreshToken(curMember.getId().toString(),token.getRefreshToken())); - - return token; + return credit; } + /* * Token 재발급 * 1. refreshToken validate 확인 diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java index 4c1f1de2..5c26d349 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java @@ -1,12 +1,7 @@ package com.twtw.backend.module.member.service; -import com.twtw.backend.config.security.jwt.TokenProvider; -import com.twtw.backend.module.member.dto.TokenDto; -import com.twtw.backend.module.member.dto.request.MemberRequest; -import com.twtw.backend.module.member.entity.Member; import com.twtw.backend.module.member.repository.MemberRepository; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.GetMapping; @Service public class MemberService { From 73edc69522395f37cc5b500de01c83813e33d8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:45:43 +0900 Subject: [PATCH 08/14] =?UTF-8?q?[ADD]=20Kakao=20API=20=EC=97=B0=EB=8F=99?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C=20+=20Kakao=20ClientId=20=EC=A0=95?= =?UTF-8?q?=EC=83=81=20=EC=9E=91=EB=8F=99=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/member/client/KakaoWebClient.java | 36 +++++++++++++++++++ .../member/controller/AuthController.java | 2 +- .../member/dto/client/KakaoResponse.java | 12 +++++++ .../member/dto/request/OAuthRequest.java | 2 +- .../module/member/service/AuthService.java | 25 ++++++++++--- 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 backend/src/main/java/com/twtw/backend/module/member/client/KakaoWebClient.java create mode 100644 backend/src/main/java/com/twtw/backend/module/member/dto/client/KakaoResponse.java diff --git a/backend/src/main/java/com/twtw/backend/module/member/client/KakaoWebClient.java b/backend/src/main/java/com/twtw/backend/module/member/client/KakaoWebClient.java new file mode 100644 index 00000000..b2e0b546 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/client/KakaoWebClient.java @@ -0,0 +1,36 @@ +package com.twtw.backend.module.member.client; + +import com.twtw.backend.module.member.dto.client.KakaoResponse; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; + + +import java.nio.charset.StandardCharsets; + +@Component +public class KakaoWebClient { + private final WebClient webclient; + + public KakaoWebClient() { + this.webclient = generateWebClient(); + } + + public KakaoResponse requestKakao(final String token){ + return webclient + .get() + .headers(headers -> headers.setBearerAuth(token)) + .accept(MediaType.APPLICATION_JSON) + .acceptCharset(StandardCharsets.UTF_8) + .retrieve() + .bodyToMono(KakaoResponse.class) + .blockOptional() + .orElseThrow(RuntimeException::new); + } + + private WebClient generateWebClient(){ + return WebClient.builder() + .baseUrl("https://kapi.kakao.com/v2/user/me") + .build(); + } +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java index e22cfb21..574c89e6 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java @@ -5,6 +5,7 @@ import com.twtw.backend.module.member.dto.response.TokenDto; import com.twtw.backend.module.member.dto.request.MemberSaveRequest; import com.twtw.backend.module.member.dto.request.TokenRequest; +import com.twtw.backend.module.member.entity.AuthType; import com.twtw.backend.module.member.service.AuthService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -45,5 +46,4 @@ public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest reque return ResponseEntity.status(HttpStatus.OK).body(tokenDto); } } - } diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/client/KakaoResponse.java b/backend/src/main/java/com/twtw/backend/module/member/dto/client/KakaoResponse.java new file mode 100644 index 00000000..bd7083af --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/client/KakaoResponse.java @@ -0,0 +1,12 @@ +package com.twtw.backend.module.member.dto.client; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class KakaoResponse { + public long id; +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java b/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java index f7c37eb3..cee74a1a 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java +++ b/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java @@ -11,7 +11,7 @@ @Setter @RequiredArgsConstructor public class OAuthRequest { - private String clientId; + private String token; @Enumerated(EnumType.STRING) private AuthType authType; diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java index ae902b0e..1950927a 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java @@ -3,9 +3,11 @@ import com.twtw.backend.config.security.entity.RefreshToken; import com.twtw.backend.config.security.jwt.TokenProvider; import com.twtw.backend.config.security.repository.RefreshTokenRepository; +import com.twtw.backend.module.member.client.KakaoWebClient; import com.twtw.backend.module.member.dto.request.OAuthRequest; import com.twtw.backend.module.member.dto.response.TokenDto; import com.twtw.backend.module.member.dto.request.MemberSaveRequest; +import com.twtw.backend.module.member.entity.AuthType; import com.twtw.backend.module.member.entity.Member; import com.twtw.backend.module.member.entity.OAuth2Info; import com.twtw.backend.module.member.repository.MemberRepository; @@ -25,11 +27,13 @@ public class AuthService { private final MemberRepository memberRepository; private final RefreshTokenRepository refreshTokenRepository; private final TokenProvider tokenProvider; + private final KakaoWebClient kakaoWebClient; - public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider) { + public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider,KakaoWebClient kakaoWebClient) { this.memberRepository = memberRepository; this.refreshTokenRepository = refreshTokenRepository; this.tokenProvider = tokenProvider; + this.kakaoWebClient = kakaoWebClient; } private Member toMemberEntity(MemberSaveRequest request) @@ -38,9 +42,9 @@ private Member toMemberEntity(MemberSaveRequest request) return member; } - private OAuth2Info toOAuthInfo(OAuthRequest request) + private OAuth2Info toOAuthInfo(String clientId,AuthType type) { - OAuth2Info info = new OAuth2Info(request.getClientId(),request.getAuthType()); + OAuth2Info info = new OAuth2Info(clientId,type); return info; } @@ -54,7 +58,10 @@ private OAuth2Info toOAuthInfo(OAuthRequest request) * */ public void saveMember(MemberSaveRequest request){ Member member = toMemberEntity(request); - member.updateOAuth(toOAuthInfo(request.getOAuthRequest())); + + String clientId = getClientId(request.getOAuthRequest()); + + member.updateOAuth(toOAuthInfo(clientId,request.getOAuthRequest().getAuthType())); memberRepository.save(member); } /* @@ -63,7 +70,9 @@ public void saveMember(MemberSaveRequest request){ * * */ public TokenDto getTokenByOAuth(OAuthRequest request) { - Optional member = memberRepository.findByOAuthIdAndAuthType(request.getClientId(),request.getAuthType()); + String clientId = getClientId(request); + + Optional member = memberRepository.findByOAuthIdAndAuthType(clientId,request.getAuthType()); if(member.isPresent()) { Member curMember = member.get(); @@ -119,5 +128,11 @@ public TokenDto saveRefreshToken(Authentication authentication,String userName){ return token; } + private String getClientId(OAuthRequest request){ + if(request.getAuthType().equals(AuthType.KAKAO)){ + return Long.toString(kakaoWebClient.requestKakao(request.getToken()).getId()); + } + return request.getToken(); + } } From 7d9bc2fea85d939370b7af9d3b7f1445bf3710a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Mon, 7 Aug 2023 21:58:29 +0900 Subject: [PATCH 09/14] =?UTF-8?q?[ADD/FIX]=20Kakao=20API=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99=20=EC=99=84=EB=A3=8C=20+=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A0=80=EC=9E=A5=20=EC=8B=9C=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=20=EB=B0=9C=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/module/member/controller/AuthController.java | 6 +++--- .../twtw/backend/module/member/service/AuthService.java | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java index 574c89e6..bcb176e0 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java @@ -28,10 +28,10 @@ public ResponseEntity authorize(@RequestBody TokenRequest tokenRequest } @PostMapping("/save") - public ResponseEntity saveMember(@RequestBody MemberSaveRequest memberSaveRequest) { - authService.saveMember(memberSaveRequest); + public ResponseEntity saveMember(@RequestBody MemberSaveRequest memberSaveRequest) { + TokenDto tokenDto = authService.saveMember(memberSaveRequest); - return ResponseEntity.status(HttpStatus.OK).body(null); + return ResponseEntity.status(HttpStatus.OK).body(tokenDto); } @PostMapping("/login") diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java index 1950927a..91d991d9 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java @@ -56,13 +56,18 @@ private OAuth2Info toOAuthInfo(String clientId,AuthType type) * 4. 저장 * 5. 토큰(jwt) 발급 * */ - public void saveMember(MemberSaveRequest request){ + public TokenDto saveMember(MemberSaveRequest request){ Member member = toMemberEntity(request); String clientId = getClientId(request.getOAuthRequest()); member.updateOAuth(toOAuthInfo(clientId,request.getOAuthRequest().getAuthType())); - memberRepository.save(member); + member = memberRepository.save(member); + + UsernamePasswordAuthenticationToken credit = makeCredit(member); + TokenDto tokenDto = saveRefreshToken(credit,member.getId().toString()); + + return tokenDto; } /* * 1.로그인(Social) 후의 토큰 발급 From 3f90e6e17a8f8a7b55db1799760f7e12932eb506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Tue, 8 Aug 2023 02:01:44 +0900 Subject: [PATCH 10/14] =?UTF-8?q?[FIX]=20Setter=20=EC=82=AD=EC=A0=9C=20,?= =?UTF-8?q?=20AllArgs=20=EB=B3=80=EA=B2=BD=20,=20RefreshToken=20+=20repo?= =?UTF-8?q?=20->=20Member=ED=8C=A8=ED=82=A4=EC=A7=80=EB=A1=9C=20=EC=9C=84?= =?UTF-8?q?=EC=B9=98=20=EB=B3=80=EA=B2=BD=20,=20module=20->=20domain=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20,=20makeCredit=20security=20=EC=B1=85?= =?UTF-8?q?=EC=9E=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/security/jwt/TokenProvider.java | 13 +++++- .../member/SwaggerConfiguration.java | 2 +- .../member/client/KakaoWebClient.java | 4 +- .../member/controller/AuthController.java | 18 ++++---- .../member/controller/MemberController.java | 4 +- .../member/dto/client/KakaoResponse.java | 6 +-- .../member/dto/request/MemberSaveRequest.java | 11 ++--- .../member/dto/request/OAuthRequest.java | 10 ++--- .../member/dto/request/TokenRequest.java | 6 +-- .../member/dto/response/TokenDto.java | 3 +- .../domain/member/entity/AuthType.java | 6 +++ .../member/entity/Member.java | 2 +- .../member/entity/OAuth2Info.java | 2 +- .../member}/entity/RefreshToken.java | 2 +- .../backend/domain/member/entity/Role.java | 6 +++ .../member/repository/MemberRepository.java | 6 +-- .../repository/RefreshTokenRepository.java | 4 +- .../member/service/AuthService.java | 41 +++++++------------ .../member/service/MemberService.java | 4 +- .../module/member/entity/AuthType.java | 9 ---- .../backend/module/member/entity/Role.java | 9 ---- backend/src/main/resources/application.yml | 2 - 22 files changed, 75 insertions(+), 95 deletions(-) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/SwaggerConfiguration.java (96%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/client/KakaoWebClient.java (89%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/controller/AuthController.java (71%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/controller/MemberController.java (76%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/dto/client/KakaoResponse.java (57%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/dto/request/MemberSaveRequest.java (56%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/dto/request/OAuthRequest.java (53%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/dto/request/TokenRequest.java (61%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/dto/response/TokenDto.java (80%) create mode 100644 backend/src/main/java/com/twtw/backend/domain/member/entity/AuthType.java rename backend/src/main/java/com/twtw/backend/{module => domain}/member/entity/Member.java (95%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/entity/OAuth2Info.java (94%) rename backend/src/main/java/com/twtw/backend/{config/security => domain/member}/entity/RefreshToken.java (90%) create mode 100644 backend/src/main/java/com/twtw/backend/domain/member/entity/Role.java rename backend/src/main/java/com/twtw/backend/{module => domain}/member/repository/MemberRepository.java (75%) rename backend/src/main/java/com/twtw/backend/{config/security => domain/member}/repository/RefreshTokenRepository.java (56%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/service/AuthService.java (72%) rename backend/src/main/java/com/twtw/backend/{module => domain}/member/service/MemberService.java (70%) delete mode 100644 backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java delete mode 100644 backend/src/main/java/com/twtw/backend/module/member/entity/Role.java diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java index 08c092e9..74822a66 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java @@ -1,5 +1,6 @@ package com.twtw.backend.config.security.jwt; -import com.twtw.backend.module.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.entity.Member; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; import io.jsonwebtoken.security.Keys; @@ -16,6 +17,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.List; import java.util.stream.Collectors; @Component @@ -106,4 +108,13 @@ private Claims parseClaims(String accessToken) { } } + public UsernamePasswordAuthenticationToken makeCredit(Member member) + { + List role = new ArrayList<>(); + role.add(new SimpleGrantedAuthority(member.getRole().toString())); + UsernamePasswordAuthenticationToken credit = new UsernamePasswordAuthenticationToken(member.getId().toString(),"",role); + + return credit; + } + } diff --git a/backend/src/main/java/com/twtw/backend/module/member/SwaggerConfiguration.java b/backend/src/main/java/com/twtw/backend/domain/member/SwaggerConfiguration.java similarity index 96% rename from backend/src/main/java/com/twtw/backend/module/member/SwaggerConfiguration.java rename to backend/src/main/java/com/twtw/backend/domain/member/SwaggerConfiguration.java index 438da01e..51baaf7c 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/SwaggerConfiguration.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/SwaggerConfiguration.java @@ -1,4 +1,4 @@ -package com.twtw.backend.module.member; +package com.twtw.backend.domain.member; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; diff --git a/backend/src/main/java/com/twtw/backend/module/member/client/KakaoWebClient.java b/backend/src/main/java/com/twtw/backend/domain/member/client/KakaoWebClient.java similarity index 89% rename from backend/src/main/java/com/twtw/backend/module/member/client/KakaoWebClient.java rename to backend/src/main/java/com/twtw/backend/domain/member/client/KakaoWebClient.java index b2e0b546..39af205c 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/client/KakaoWebClient.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/client/KakaoWebClient.java @@ -1,6 +1,6 @@ -package com.twtw.backend.module.member.client; +package com.twtw.backend.domain.member.client; -import com.twtw.backend.module.member.dto.client.KakaoResponse; +import com.twtw.backend.domain.member.dto.client.KakaoResponse; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java similarity index 71% rename from backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java rename to backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java index bcb176e0..7e5f8798 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java @@ -1,18 +1,14 @@ -package com.twtw.backend.module.member.controller; - -import com.twtw.backend.config.security.repository.RefreshTokenRepository; -import com.twtw.backend.module.member.dto.request.OAuthRequest; -import com.twtw.backend.module.member.dto.response.TokenDto; -import com.twtw.backend.module.member.dto.request.MemberSaveRequest; -import com.twtw.backend.module.member.dto.request.TokenRequest; -import com.twtw.backend.module.member.entity.AuthType; -import com.twtw.backend.module.member.service.AuthService; +package com.twtw.backend.domain.member.controller; + +import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; +import com.twtw.backend.domain.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.service.AuthService; +import com.twtw.backend.domain.member.dto.request.OAuthRequest; +import com.twtw.backend.domain.member.dto.request.TokenRequest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.UUID; - @RestController @RequestMapping("/auth") public class AuthController { diff --git a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java b/backend/src/main/java/com/twtw/backend/domain/member/controller/MemberController.java similarity index 76% rename from backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java rename to backend/src/main/java/com/twtw/backend/domain/member/controller/MemberController.java index 467b6494..f02684b1 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/controller/MemberController.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/controller/MemberController.java @@ -1,6 +1,6 @@ -package com.twtw.backend.module.member.controller; +package com.twtw.backend.domain.member.controller; -import com.twtw.backend.module.member.service.MemberService; +import com.twtw.backend.domain.member.service.MemberService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/client/KakaoResponse.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/client/KakaoResponse.java similarity index 57% rename from backend/src/main/java/com/twtw/backend/module/member/dto/client/KakaoResponse.java rename to backend/src/main/java/com/twtw/backend/domain/member/dto/client/KakaoResponse.java index bd7083af..8625662c 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/client/KakaoResponse.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/client/KakaoResponse.java @@ -1,12 +1,12 @@ -package com.twtw.backend.module.member.dto.client; +package com.twtw.backend.domain.member.dto.client; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; @Getter -@Setter -@RequiredArgsConstructor +@AllArgsConstructor public class KakaoResponse { public long id; } diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberSaveRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java similarity index 56% rename from backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberSaveRequest.java rename to backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java index c405aece..3fe315a2 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/request/MemberSaveRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java @@ -1,16 +1,13 @@ -package com.twtw.backend.module.member.dto.request; +package com.twtw.backend.domain.member.dto.request; -import com.twtw.backend.module.member.entity.OAuth2Info; -import com.twtw.backend.module.member.entity.Role; +import com.twtw.backend.domain.member.entity.Role; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; @Getter -@Setter -@RequiredArgsConstructor +@AllArgsConstructor public class MemberSaveRequest { private String nickname; diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java similarity index 53% rename from backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java rename to backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java index cee74a1a..b6278630 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/request/OAuthRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java @@ -1,15 +1,13 @@ -package com.twtw.backend.module.member.dto.request; +package com.twtw.backend.domain.member.dto.request; -import com.twtw.backend.module.member.entity.AuthType; +import com.twtw.backend.domain.member.entity.AuthType; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; @Getter -@Setter -@RequiredArgsConstructor +@AllArgsConstructor public class OAuthRequest { private String token; diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/request/TokenRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/TokenRequest.java similarity index 61% rename from backend/src/main/java/com/twtw/backend/module/member/dto/request/TokenRequest.java rename to backend/src/main/java/com/twtw/backend/domain/member/dto/request/TokenRequest.java index 2c7b163a..4a0be64b 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/request/TokenRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/TokenRequest.java @@ -1,12 +1,12 @@ -package com.twtw.backend.module.member.dto.request; +package com.twtw.backend.domain.member.dto.request; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; @Getter -@Setter -@RequiredArgsConstructor +@AllArgsConstructor public class TokenRequest { String accessToken; String refreshToken; diff --git a/backend/src/main/java/com/twtw/backend/module/member/dto/response/TokenDto.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java similarity index 80% rename from backend/src/main/java/com/twtw/backend/module/member/dto/response/TokenDto.java rename to backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java index 55c8d698..59daa45d 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/dto/response/TokenDto.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java @@ -1,11 +1,10 @@ -package com.twtw.backend.module.member.dto.response; +package com.twtw.backend.domain.member.dto.response; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @Getter -@Setter @AllArgsConstructor public class TokenDto { private String accessToken; diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthType.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthType.java new file mode 100644 index 00000000..ec50c355 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/AuthType.java @@ -0,0 +1,6 @@ +package com.twtw.backend.domain.member.entity; + +public enum AuthType { + APPLE, + KAKAO +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java similarity index 95% rename from backend/src/main/java/com/twtw/backend/module/member/entity/Member.java rename to backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java index ed8fa062..a5b6e04e 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/Member.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/Member.java @@ -1,4 +1,4 @@ -package com.twtw.backend.module.member.entity; +package com.twtw.backend.domain.member.entity; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/OAuth2Info.java similarity index 94% rename from backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java rename to backend/src/main/java/com/twtw/backend/domain/member/entity/OAuth2Info.java index 2779aea3..df94e06a 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/OAuth2Info.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/OAuth2Info.java @@ -1,4 +1,4 @@ -package com.twtw.backend.module.member.entity; +package com.twtw.backend.domain.member.entity; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/RefreshToken.java similarity index 90% rename from backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java rename to backend/src/main/java/com/twtw/backend/domain/member/entity/RefreshToken.java index 1b44ac3c..9f02387b 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/entity/RefreshToken.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/RefreshToken.java @@ -1,4 +1,4 @@ -package com.twtw.backend.config.security.entity; +package com.twtw.backend.domain.member.entity; import jakarta.persistence.Entity; import jakarta.persistence.Id; diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/Role.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/Role.java new file mode 100644 index 00000000..1a1f3e2e --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/Role.java @@ -0,0 +1,6 @@ +package com.twtw.backend.domain.member.entity; + +public enum Role { + ROLE_ADMIN, + ROLE_USER +} diff --git a/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java similarity index 75% rename from backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java rename to backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java index 75ca47c3..d969bb90 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/repository/MemberRepository.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java @@ -1,8 +1,8 @@ -package com.twtw.backend.module.member.repository; +package com.twtw.backend.domain.member.repository; -import com.twtw.backend.module.member.entity.AuthType; -import com.twtw.backend.module.member.entity.Member; +import com.twtw.backend.domain.member.entity.AuthType; +import com.twtw.backend.domain.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; diff --git a/backend/src/main/java/com/twtw/backend/config/security/repository/RefreshTokenRepository.java b/backend/src/main/java/com/twtw/backend/domain/member/repository/RefreshTokenRepository.java similarity index 56% rename from backend/src/main/java/com/twtw/backend/config/security/repository/RefreshTokenRepository.java rename to backend/src/main/java/com/twtw/backend/domain/member/repository/RefreshTokenRepository.java index 2a2e1263..451e539c 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/repository/RefreshTokenRepository.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/repository/RefreshTokenRepository.java @@ -1,6 +1,6 @@ -package com.twtw.backend.config.security.repository; +package com.twtw.backend.domain.member.repository; -import com.twtw.backend.config.security.entity.RefreshToken; +import com.twtw.backend.domain.member.entity.RefreshToken; import org.springframework.data.jpa.repository.JpaRepository; public interface RefreshTokenRepository extends JpaRepository { diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java similarity index 72% rename from backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java rename to backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java index 91d991d9..1c347a3a 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java @@ -1,25 +1,21 @@ -package com.twtw.backend.module.member.service; +package com.twtw.backend.domain.member.service; -import com.twtw.backend.config.security.entity.RefreshToken; +import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; +import com.twtw.backend.domain.member.dto.response.TokenDto; +import com.twtw.backend.domain.member.entity.AuthType; +import com.twtw.backend.domain.member.entity.Member; +import com.twtw.backend.domain.member.entity.RefreshToken; import com.twtw.backend.config.security.jwt.TokenProvider; -import com.twtw.backend.config.security.repository.RefreshTokenRepository; -import com.twtw.backend.module.member.client.KakaoWebClient; -import com.twtw.backend.module.member.dto.request.OAuthRequest; -import com.twtw.backend.module.member.dto.response.TokenDto; -import com.twtw.backend.module.member.dto.request.MemberSaveRequest; -import com.twtw.backend.module.member.entity.AuthType; -import com.twtw.backend.module.member.entity.Member; -import com.twtw.backend.module.member.entity.OAuth2Info; -import com.twtw.backend.module.member.repository.MemberRepository; +import com.twtw.backend.domain.member.repository.RefreshTokenRepository; +import com.twtw.backend.domain.member.client.KakaoWebClient; +import com.twtw.backend.domain.member.dto.request.OAuthRequest; +import com.twtw.backend.domain.member.entity.OAuth2Info; +import com.twtw.backend.domain.member.repository.MemberRepository; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; import java.util.Optional; @Service @@ -42,7 +38,7 @@ private Member toMemberEntity(MemberSaveRequest request) return member; } - private OAuth2Info toOAuthInfo(String clientId,AuthType type) + private OAuth2Info toOAuthInfo(String clientId, AuthType type) { OAuth2Info info = new OAuth2Info(clientId,type); @@ -64,7 +60,7 @@ public TokenDto saveMember(MemberSaveRequest request){ member.updateOAuth(toOAuthInfo(clientId,request.getOAuthRequest().getAuthType())); member = memberRepository.save(member); - UsernamePasswordAuthenticationToken credit = makeCredit(member); + UsernamePasswordAuthenticationToken credit = tokenProvider.makeCredit(member); TokenDto tokenDto = saveRefreshToken(credit,member.getId().toString()); return tokenDto; @@ -81,7 +77,7 @@ public TokenDto getTokenByOAuth(OAuthRequest request) { if(member.isPresent()) { Member curMember = member.get(); - UsernamePasswordAuthenticationToken credit = makeCredit(curMember); + UsernamePasswordAuthenticationToken credit = tokenProvider.makeCredit(curMember); TokenDto tokenDto = saveRefreshToken(credit,curMember.getId().toString()); return tokenDto; } @@ -89,15 +85,6 @@ public TokenDto getTokenByOAuth(OAuthRequest request) { return null; } - private UsernamePasswordAuthenticationToken makeCredit(Member member) - { - List role = new ArrayList<>(); - role.add(new SimpleGrantedAuthority(member.getRole().toString())); - UsernamePasswordAuthenticationToken credit = new UsernamePasswordAuthenticationToken(member.getId().toString(),"",role); - - return credit; - } - /* * Token 재발급 diff --git a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java b/backend/src/main/java/com/twtw/backend/domain/member/service/MemberService.java similarity index 70% rename from backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java rename to backend/src/main/java/com/twtw/backend/domain/member/service/MemberService.java index 5c26d349..c2554b1e 100644 --- a/backend/src/main/java/com/twtw/backend/module/member/service/MemberService.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/service/MemberService.java @@ -1,6 +1,6 @@ -package com.twtw.backend.module.member.service; +package com.twtw.backend.domain.member.service; -import com.twtw.backend.module.member.repository.MemberRepository; +import com.twtw.backend.domain.member.repository.MemberRepository; import org.springframework.stereotype.Service; @Service diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java b/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java deleted file mode 100644 index e53f6c8f..00000000 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/AuthType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.twtw.backend.module.member.entity; - -import lombok.Getter; - -@Getter -public enum AuthType { - APPLE, - KAKAO -} diff --git a/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java b/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java deleted file mode 100644 index b154754e..00000000 --- a/backend/src/main/java/com/twtw/backend/module/member/entity/Role.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.twtw.backend.module.member.entity; - -import lombok.Getter; - -@Getter -public enum Role { - ROLE_ADMIN, - ROLE_USER -} diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 3b37585e..428b1c0e 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,5 +1,3 @@ -server: - port: 8080 spring: profiles: include: oauth From 12c009fcabe1362e3ac306b88456ad671ef84281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:28:41 +0900 Subject: [PATCH 11/14] =?UTF-8?q?[ADD/FIX]=20Member=20Mapper=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20+=20=EB=B3=80=EC=88=98=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95(=EB=8C=80=EB=AC=B8=EC=9E=90=EC=98=80=EB=84=A4=20....)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/AuthController.java | 4 +-- .../member/dto/client/KakaoResponse.java | 6 ++-- .../member/dto/request/MemberSaveRequest.java | 4 ++- .../{OAuthRequest.java => OauthRequest.java} | 6 ++-- .../member/dto/request/TokenRequest.java | 10 +++--- .../domain/member/dto/response/TokenDto.java | 4 +-- .../domain/member/mapper/MemberMapper.java | 24 +++++++++++++ .../domain/member/service/AuthService.java | 36 ++++++++----------- 8 files changed, 53 insertions(+), 41 deletions(-) rename backend/src/main/java/com/twtw/backend/domain/member/dto/request/{OAuthRequest.java => OauthRequest.java} (76%) create mode 100644 backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java diff --git a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java index 7e5f8798..6df12b13 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java @@ -3,7 +3,7 @@ import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.response.TokenDto; import com.twtw.backend.domain.member.service.AuthService; -import com.twtw.backend.domain.member.dto.request.OAuthRequest; +import com.twtw.backend.domain.member.dto.request.OauthRequest; import com.twtw.backend.domain.member.dto.request.TokenRequest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,7 +31,7 @@ public ResponseEntity saveMember(@RequestBody MemberSaveRequest member } @PostMapping("/login") - public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest request){ + public ResponseEntity afterSocialLogin(@RequestBody OauthRequest request){ TokenDto tokenDto = authService.getTokenByOAuth(request); if(tokenDto == null){ diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/client/KakaoResponse.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/client/KakaoResponse.java index 8625662c..8a2fc40d 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/client/KakaoResponse.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/client/KakaoResponse.java @@ -1,11 +1,9 @@ package com.twtw.backend.domain.member.dto.client; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; +import lombok.*; @Getter +@NoArgsConstructor @AllArgsConstructor public class KakaoResponse { public long id; diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java index 3fe315a2..33937afd 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java @@ -5,8 +5,10 @@ import jakarta.persistence.Enumerated; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor @AllArgsConstructor public class MemberSaveRequest { private String nickname; @@ -18,5 +20,5 @@ public class MemberSaveRequest { @Enumerated(EnumType.STRING) private Role role; - private OAuthRequest oAuthRequest; + private OauthRequest oauthRequest; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OauthRequest.java similarity index 76% rename from backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java rename to backend/src/main/java/com/twtw/backend/domain/member/dto/request/OauthRequest.java index b6278630..4a780a82 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OauthRequest.java @@ -3,12 +3,12 @@ import com.twtw.backend.domain.member.entity.AuthType; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.*; @Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor -public class OAuthRequest { +public class OauthRequest { private String token; @Enumerated(EnumType.STRING) diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/TokenRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/TokenRequest.java index 4a0be64b..1b714497 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/TokenRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/TokenRequest.java @@ -1,13 +1,11 @@ package com.twtw.backend.domain.member.dto.request; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; +import lombok.*; @Getter +@NoArgsConstructor @AllArgsConstructor public class TokenRequest { - String accessToken; - String refreshToken; + private String accessToken; + private String refreshToken; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java index 59daa45d..adc5d5fc 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java @@ -1,8 +1,6 @@ package com.twtw.backend.domain.member.dto.response; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; +import lombok.*; @Getter @AllArgsConstructor diff --git a/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java b/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java new file mode 100644 index 00000000..566ffcdd --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/mapper/MemberMapper.java @@ -0,0 +1,24 @@ +package com.twtw.backend.domain.member.mapper; + +import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; +import com.twtw.backend.domain.member.entity.AuthType; +import com.twtw.backend.domain.member.entity.Member; +import com.twtw.backend.domain.member.entity.OAuth2Info; +import org.springframework.stereotype.Component; + +@Component +public class MemberMapper { + + public Member toMemberEntity(MemberSaveRequest request) + { + Member member = new Member(request.getNickname(), request.getProfileImage(), request.getPhoneNumber(), request.getRole()); + return member; + } + + public OAuth2Info toOAuthInfo(String clientId, AuthType type) + { + OAuth2Info info = new OAuth2Info(clientId,type); + + return info; + } +} diff --git a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java index 1c347a3a..7f585c28 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java @@ -6,15 +6,16 @@ import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.entity.RefreshToken; import com.twtw.backend.config.security.jwt.TokenProvider; +import com.twtw.backend.domain.member.mapper.MemberMapper; import com.twtw.backend.domain.member.repository.RefreshTokenRepository; import com.twtw.backend.domain.member.client.KakaoWebClient; -import com.twtw.backend.domain.member.dto.request.OAuthRequest; -import com.twtw.backend.domain.member.entity.OAuth2Info; +import com.twtw.backend.domain.member.dto.request.OauthRequest; import com.twtw.backend.domain.member.repository.MemberRepository; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Optional; @@ -24,25 +25,14 @@ public class AuthService { private final RefreshTokenRepository refreshTokenRepository; private final TokenProvider tokenProvider; private final KakaoWebClient kakaoWebClient; + private final MemberMapper memberMapper; - public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider,KakaoWebClient kakaoWebClient) { + public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider,KakaoWebClient kakaoWebClient,MemberMapper memberMapper) { this.memberRepository = memberRepository; this.refreshTokenRepository = refreshTokenRepository; this.tokenProvider = tokenProvider; this.kakaoWebClient = kakaoWebClient; - } - - private Member toMemberEntity(MemberSaveRequest request) - { - Member member = new Member(request.getNickname(), request.getProfileImage(), request.getPhoneNumber(), request.getRole()); - return member; - } - - private OAuth2Info toOAuthInfo(String clientId, AuthType type) - { - OAuth2Info info = new OAuth2Info(clientId,type); - - return info; + this.memberMapper = memberMapper; } /* @@ -52,13 +42,15 @@ private OAuth2Info toOAuthInfo(String clientId, AuthType type) * 4. 저장 * 5. 토큰(jwt) 발급 * */ + + @Transactional public TokenDto saveMember(MemberSaveRequest request){ - Member member = toMemberEntity(request); + Member member = memberMapper.toMemberEntity(request); - String clientId = getClientId(request.getOAuthRequest()); + String clientId = getClientId(request.getOauthRequest()); - member.updateOAuth(toOAuthInfo(clientId,request.getOAuthRequest().getAuthType())); - member = memberRepository.save(member); + member.updateOAuth(memberMapper.toOAuthInfo(clientId,request.getOauthRequest().getAuthType())); + memberRepository.save(member); UsernamePasswordAuthenticationToken credit = tokenProvider.makeCredit(member); TokenDto tokenDto = saveRefreshToken(credit,member.getId().toString()); @@ -70,7 +62,7 @@ public TokenDto saveMember(MemberSaveRequest request){ * 2.JWT 토큰 발급 -> OAuth 정보 (clientId , AuthType)으로 진행 * * */ - public TokenDto getTokenByOAuth(OAuthRequest request) { + public TokenDto getTokenByOAuth(OauthRequest request) { String clientId = getClientId(request); Optional member = memberRepository.findByOAuthIdAndAuthType(clientId,request.getAuthType()); @@ -120,7 +112,7 @@ public TokenDto saveRefreshToken(Authentication authentication,String userName){ return token; } - private String getClientId(OAuthRequest request){ + private String getClientId(OauthRequest request){ if(request.getAuthType().equals(AuthType.KAKAO)){ return Long.toString(kakaoWebClient.requestKakao(request.getToken()).getId()); } From b0aca567ced76a8c162de3441f2b2cd67acc4b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:33:09 +0900 Subject: [PATCH 12/14] =?UTF-8?q?[ADD/FIX]=20Member=20Mapper=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20+=20=EB=B3=80=EC=88=98=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95(=EB=8C=80=EB=AC=B8=EC=9E=90=EC=98=80=EB=84=A4=20....)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/member/repository/MemberRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java index d969bb90..d09160a5 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java @@ -12,6 +12,6 @@ public interface MemberRepository extends JpaRepository { Optional findById(UUID uuid); - @Query("SELECT m FROM Member m WHERE m.oAuth2Info.clientId = :OAuthId AND m.oAuth2Info.authType = :authType") - Optional findByOAuthIdAndAuthType(String OAuthId, AuthType authType); + @Query("SELECT m FROM Member m WHERE m.oAuth2Info.clientId = :oauthId AND m.oAuth2Info.authType = :authType") + Optional findByOAuthIdAndAuthType(String oauthId, AuthType authType); } From 4aac8a2d3990c379e5ea90269ff06a3955dd37dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:34:02 +0900 Subject: [PATCH 13/14] =?UTF-8?q?[ADD/FIX]=20Member=20Mapper=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20+=20=EB=B3=80=EC=88=98=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95(=EB=8C=80=EB=AC=B8=EC=9E=90=EC=98=80=EB=84=A4=20....)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/member/repository/MemberRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java index d09160a5..76f8346c 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java @@ -12,6 +12,6 @@ public interface MemberRepository extends JpaRepository { Optional findById(UUID uuid); - @Query("SELECT m FROM Member m WHERE m.oAuth2Info.clientId = :oauthId AND m.oAuth2Info.authType = :authType") - Optional findByOAuthIdAndAuthType(String oauthId, AuthType authType); + @Query("SELECT m FROM Member m WHERE m.oAuth2Info.clientId = :oAuthId AND m.oAuth2Info.authType = :authType") + Optional findByOAuthIdAndAuthType(String oAuthId, AuthType authType); } From 93e653bfe37a061d99f8fa7f481d83980a76c8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=84=EC=A3=BC=EC=9B=90?= <84346055+jinjoo-lab@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:22:25 +0900 Subject: [PATCH 14/14] =?UTF-8?q?[FIX]=20WebClient=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?+=20clientId=20=EB=B0=94=EB=A1=9C=20=EB=B0=9B=EA=B8=B0=20+=20Re?= =?UTF-8?q?freshToken=20UUID=20PK=20=EC=B6=94=EA=B0=80=20+=20TokenDto=20ex?= =?UTF-8?q?pired=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/security/jwt/TokenProvider.java | 2 +- .../domain/member/client/KakaoWebClient.java | 36 ------------------- .../member/controller/AuthController.java | 4 +-- .../member/dto/request/MemberSaveRequest.java | 2 +- .../{OauthRequest.java => OAuthRequest.java} | 2 +- .../domain/member/dto/response/TokenDto.java | 2 +- .../domain/member/entity/RefreshToken.java | 7 ++++ .../domain/member/service/AuthService.java | 21 +++-------- backend/src/main/resources/application.yml | 2 +- 9 files changed, 19 insertions(+), 59 deletions(-) delete mode 100644 backend/src/main/java/com/twtw/backend/domain/member/client/KakaoWebClient.java rename backend/src/main/java/com/twtw/backend/domain/member/dto/request/{OauthRequest.java => OAuthRequest.java} (93%) diff --git a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java index 74822a66..3a27ad6a 100644 --- a/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java +++ b/backend/src/main/java/com/twtw/backend/config/security/jwt/TokenProvider.java @@ -63,7 +63,7 @@ public TokenDto createToken(Authentication authentication) { .signWith(key,SignatureAlgorithm.HS512) .compact(); - return new TokenDto(accessToken,refreshToken,validAccessDate.getTime()); + return new TokenDto(accessToken,refreshToken); } public Authentication getAuthentication(String accessToken) { diff --git a/backend/src/main/java/com/twtw/backend/domain/member/client/KakaoWebClient.java b/backend/src/main/java/com/twtw/backend/domain/member/client/KakaoWebClient.java deleted file mode 100644 index 39af205c..00000000 --- a/backend/src/main/java/com/twtw/backend/domain/member/client/KakaoWebClient.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.twtw.backend.domain.member.client; - -import com.twtw.backend.domain.member.dto.client.KakaoResponse; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.client.WebClient; - - -import java.nio.charset.StandardCharsets; - -@Component -public class KakaoWebClient { - private final WebClient webclient; - - public KakaoWebClient() { - this.webclient = generateWebClient(); - } - - public KakaoResponse requestKakao(final String token){ - return webclient - .get() - .headers(headers -> headers.setBearerAuth(token)) - .accept(MediaType.APPLICATION_JSON) - .acceptCharset(StandardCharsets.UTF_8) - .retrieve() - .bodyToMono(KakaoResponse.class) - .blockOptional() - .orElseThrow(RuntimeException::new); - } - - private WebClient generateWebClient(){ - return WebClient.builder() - .baseUrl("https://kapi.kakao.com/v2/user/me") - .build(); - } -} diff --git a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java index 6df12b13..7e5f8798 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/controller/AuthController.java @@ -3,7 +3,7 @@ import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.response.TokenDto; import com.twtw.backend.domain.member.service.AuthService; -import com.twtw.backend.domain.member.dto.request.OauthRequest; +import com.twtw.backend.domain.member.dto.request.OAuthRequest; import com.twtw.backend.domain.member.dto.request.TokenRequest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,7 +31,7 @@ public ResponseEntity saveMember(@RequestBody MemberSaveRequest member } @PostMapping("/login") - public ResponseEntity afterSocialLogin(@RequestBody OauthRequest request){ + public ResponseEntity afterSocialLogin(@RequestBody OAuthRequest request){ TokenDto tokenDto = authService.getTokenByOAuth(request); if(tokenDto == null){ diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java index 33937afd..3b8462a4 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/MemberSaveRequest.java @@ -20,5 +20,5 @@ public class MemberSaveRequest { @Enumerated(EnumType.STRING) private Role role; - private OauthRequest oauthRequest; + private OAuthRequest oauthRequest; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OauthRequest.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java similarity index 93% rename from backend/src/main/java/com/twtw/backend/domain/member/dto/request/OauthRequest.java rename to backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java index 4a780a82..8e0f2edd 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OauthRequest.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/request/OAuthRequest.java @@ -8,7 +8,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor -public class OauthRequest { +public class OAuthRequest { private String token; @Enumerated(EnumType.STRING) diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java index adc5d5fc..b923e6f8 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/TokenDto.java @@ -3,9 +3,9 @@ import lombok.*; @Getter +@NoArgsConstructor @AllArgsConstructor public class TokenDto { private String accessToken; private String refreshToken; - private final Long accessTokenExpiresIn; } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/entity/RefreshToken.java b/backend/src/main/java/com/twtw/backend/domain/member/entity/RefreshToken.java index 9f02387b..c7f03216 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/entity/RefreshToken.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/entity/RefreshToken.java @@ -1,16 +1,23 @@ package com.twtw.backend.domain.member.entity; +import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.UUID; + @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class RefreshToken { @Id + @GeneratedValue(generator = "uuid2") + @Column(name = "id",columnDefinition = "BINARY(16)") + private UUID id; private String tokenKey; private String tokenValue; diff --git a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java index 7f585c28..b540c2f8 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/service/AuthService.java @@ -2,14 +2,12 @@ import com.twtw.backend.domain.member.dto.request.MemberSaveRequest; import com.twtw.backend.domain.member.dto.response.TokenDto; -import com.twtw.backend.domain.member.entity.AuthType; import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.entity.RefreshToken; import com.twtw.backend.config.security.jwt.TokenProvider; import com.twtw.backend.domain.member.mapper.MemberMapper; import com.twtw.backend.domain.member.repository.RefreshTokenRepository; -import com.twtw.backend.domain.member.client.KakaoWebClient; -import com.twtw.backend.domain.member.dto.request.OauthRequest; +import com.twtw.backend.domain.member.dto.request.OAuthRequest; import com.twtw.backend.domain.member.repository.MemberRepository; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -24,14 +22,12 @@ public class AuthService { private final MemberRepository memberRepository; private final RefreshTokenRepository refreshTokenRepository; private final TokenProvider tokenProvider; - private final KakaoWebClient kakaoWebClient; private final MemberMapper memberMapper; - public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider,KakaoWebClient kakaoWebClient,MemberMapper memberMapper) { + public AuthService(MemberRepository memberRepository,RefreshTokenRepository refreshTokenRepository,TokenProvider tokenProvider,MemberMapper memberMapper) { this.memberRepository = memberRepository; this.refreshTokenRepository = refreshTokenRepository; this.tokenProvider = tokenProvider; - this.kakaoWebClient = kakaoWebClient; this.memberMapper = memberMapper; } @@ -47,7 +43,7 @@ public AuthService(MemberRepository memberRepository,RefreshTokenRepository refr public TokenDto saveMember(MemberSaveRequest request){ Member member = memberMapper.toMemberEntity(request); - String clientId = getClientId(request.getOauthRequest()); + String clientId = request.getOauthRequest().getToken(); member.updateOAuth(memberMapper.toOAuthInfo(clientId,request.getOauthRequest().getAuthType())); memberRepository.save(member); @@ -62,8 +58,8 @@ public TokenDto saveMember(MemberSaveRequest request){ * 2.JWT 토큰 발급 -> OAuth 정보 (clientId , AuthType)으로 진행 * * */ - public TokenDto getTokenByOAuth(OauthRequest request) { - String clientId = getClientId(request); + public TokenDto getTokenByOAuth(OAuthRequest request) { + String clientId = request.getToken(); Optional member = memberRepository.findByOAuthIdAndAuthType(clientId,request.getAuthType()); @@ -112,11 +108,4 @@ public TokenDto saveRefreshToken(Authentication authentication,String userName){ return token; } - private String getClientId(OauthRequest request){ - if(request.getAuthType().equals(AuthType.KAKAO)){ - return Long.toString(kakaoWebClient.requestKakao(request.getToken()).getId()); - } - return request.getToken(); - } - } diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 428b1c0e..d9820dc6 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: profiles: - include: oauth + include: env datasource: driver-class-name: org.mariadb.jdbc.Driver url: jdbc:mariadb://localhost:3306/TWTW