diff --git a/build.gradle b/build.gradle
index f607ed6..28c6679 100644
--- a/build.gradle
+++ b/build.gradle
@@ -32,11 +32,17 @@ dependencies {
// H2
runtimeOnly 'com.h2database:h2'
+ // MySQL
+ runtimeOnly 'com.mysql:mysql-connector-j'
+
// JWT (Java JSON Web Token)
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
+ // Swagger
+ implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
+
// Lombok (Optional)
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
diff --git a/src/main/java/com/kuit/kuit4serverauth/argumentResolver/UserInfoArgumentResolver.java b/src/main/java/com/kuit/kuit4serverauth/argumentResolver/UserInfoArgumentResolver.java
new file mode 100644
index 0000000..dd72a11
--- /dev/null
+++ b/src/main/java/com/kuit/kuit4serverauth/argumentResolver/UserInfoArgumentResolver.java
@@ -0,0 +1,27 @@
+package com.kuit.kuit4serverauth.argumentResolver;
+
+import com.kuit.kuit4serverauth.dto.UserInfo;
+import jakarta.servlet.http.HttpServletRequest;
+import org.springframework.core.MethodParameter;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.support.WebDataBinderFactory;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
+import org.springframework.web.method.support.ModelAndViewContainer;
+
+@Component
+public class UserInfoArgumentResolver implements HandlerMethodArgumentResolver {
+ @Override
+ public boolean supportsParameter(MethodParameter parameter) {
+ return parameter.getParameterType().equals(UserInfo.class);
+ }
+
+ @Override
+ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
+
+ HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
+ String username = (String)request.getAttribute("username");
+ String role = (String)request.getAttribute("role");
+ return new UserInfo(username, role);
+ }
+}
diff --git a/src/main/java/com/kuit/kuit4serverauth/config/SwaggerConfig.java b/src/main/java/com/kuit/kuit4serverauth/config/SwaggerConfig.java
new file mode 100644
index 0000000..24d7ffd
--- /dev/null
+++ b/src/main/java/com/kuit/kuit4serverauth/config/SwaggerConfig.java
@@ -0,0 +1,19 @@
+package com.kuit.kuit4serverauth.config;
+
+import io.swagger.v3.oas.models.info.Info;
+import io.swagger.v3.oas.models.OpenAPI;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class SwaggerConfig {
+
+ @Bean
+ public OpenAPI openAPI() {
+ return new OpenAPI()
+ .info(info);
+ }
+
+ Info info = new Info().title("Kuit4 Server Auth").version("0.0.1").description(
+ "
Kuit4 Server Auth
");
+}
diff --git a/src/main/java/com/kuit/kuit4serverauth/config/WebConfig.java b/src/main/java/com/kuit/kuit4serverauth/config/WebConfig.java
index a0b47b4..3eb2413 100644
--- a/src/main/java/com/kuit/kuit4serverauth/config/WebConfig.java
+++ b/src/main/java/com/kuit/kuit4serverauth/config/WebConfig.java
@@ -1,20 +1,30 @@
package com.kuit.kuit4serverauth.config;
+import com.kuit.kuit4serverauth.argumentResolver.UserInfoArgumentResolver;
import com.kuit.kuit4serverauth.interceptor.AuthInterceptor;
+import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import java.util.List;
+
@Configuration
+@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {
private final AuthInterceptor authInterceptor;
+ private final UserInfoArgumentResolver userInfoArgumentResolver;
- public WebConfig(AuthInterceptor authInterceptor) {
- this.authInterceptor = authInterceptor;
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(authInterceptor)
+ .addPathPatterns("/profile")
+ .addPathPatterns("/admin");
}
@Override
- public void addInterceptors(InterceptorRegistry registry) {
- // TODO /profile, /admin 앞에 붙이기
+ public void addArgumentResolvers(List argumentResolvers) {
+ argumentResolvers.add(userInfoArgumentResolver);
}
}
diff --git a/src/main/java/com/kuit/kuit4serverauth/controller/AuthController.java b/src/main/java/com/kuit/kuit4serverauth/controller/AuthController.java
index e8f7e24..d22d6ba 100644
--- a/src/main/java/com/kuit/kuit4serverauth/controller/AuthController.java
+++ b/src/main/java/com/kuit/kuit4serverauth/controller/AuthController.java
@@ -1,43 +1,32 @@
package com.kuit.kuit4serverauth.controller;
-import com.kuit.kuit4serverauth.exception.CustomException;
-import com.kuit.kuit4serverauth.exception.ErrorCode;
-import com.kuit.kuit4serverauth.model.User;
+import com.kuit.kuit4serverauth.dto.LoginRequest;
+import com.kuit.kuit4serverauth.dto.TokenDTO;
import com.kuit.kuit4serverauth.repository.UserRepository;
+import com.kuit.kuit4serverauth.service.AuthService;
import com.kuit.kuit4serverauth.service.JwtUtil;
-import org.springframework.http.HttpStatus;
+import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
-import java.util.HashMap;
-import java.util.Map;
-
@RestController
+@RequiredArgsConstructor
public class AuthController {
private final UserRepository userRepository;
private final JwtUtil jwtUtil;
-
- public AuthController(UserRepository userRepository, JwtUtil jwtUtil) {
- this.userRepository = userRepository;
- this.jwtUtil = jwtUtil;
- }
+ private final AuthService authService;
@PostMapping("/login")
- public ResponseEntity