diff --git a/src/main/java/kr/re/etri/security/jwt/controllers/AuthController.java b/src/main/java/kr/re/etri/security/jwt/controllers/AuthController.java index a549d58..01e5e4a 100644 --- a/src/main/java/kr/re/etri/security/jwt/controllers/AuthController.java +++ b/src/main/java/kr/re/etri/security/jwt/controllers/AuthController.java @@ -15,6 +15,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.web.bind.annotation.*; @@ -63,12 +64,11 @@ public class AuthController { @Autowired RefreshTokenService refreshTokenService; - @Operation(summary = "User login", description = "Authenticate user and return JWT and refresh token cookies.") + @Operation(summary = "로그인", description = "사용자 인증 후 JWT 및 리프레시 토큰 쿠키를 반환합니다.") @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Login successful"), - @ApiResponse(responseCode = "401", description = "Invalid credentials") + @ApiResponse(responseCode = "200", description = "로그인 성공"), + @ApiResponse(responseCode = "401", description = "잘못된 사용자명 또는 비밀번호") }) - @PostMapping("/signin") public ResponseEntity authenticateUser(@Valid @RequestBody LoginRequest loginRequest) { Authentication authentication = authenticationManager.authenticate( @@ -87,7 +87,7 @@ public class AuthController { ResponseCookie jwtRefreshCookie = jwtUtils.generateRefreshJwtCookie(refreshToken.getToken()); List roles = userDetails.getAuthorities().stream() - .map(item -> item.getAuthority()) + .map(GrantedAuthority::getAuthority) .collect(Collectors.toList()); return ResponseEntity.ok() @@ -101,6 +101,11 @@ public class AuthController { )); } + @Operation(summary = "회원가입", description = "새로운 사용자를 등록합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "회원가입 성공"), + @ApiResponse(responseCode = "400", description = "중복된 사용자명 또는 이메일") + }) @PostMapping("/signup") public ResponseEntity registerUser(@Valid @RequestBody SignupRequest signUpRequest) { if (userRepository.existsByUsername(signUpRequest.getUsername())) { @@ -144,8 +149,10 @@ public class AuthController { return ResponseEntity.ok(new MessageResponse("User registered successfully!")); } - @Operation(summary = "Logout", description = "Logout current user by deleting cookies and refresh token.") - @ApiResponse(responseCode = "200", description = "Logged out successfully") + @Operation(summary = "로그아웃", description = "현재 사용자를 로그아웃하고 쿠키 및 리프레시 토큰을 삭제합니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "로그아웃 성공") + }) @PostMapping("/signout") public ResponseEntity logoutUser() { Object principle = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); @@ -163,10 +170,10 @@ public class AuthController { .body(new MessageResponse("You've been signed out!")); } - @Operation(summary = "Refresh token", description = "Get a new access token using the refresh token from cookie.") + @Operation(summary = "토큰 갱신", description = "쿠키에 저장된 리프레시 토큰을 통해 새로운 엑세스 토큰을 발급합니다.") @ApiResponses({ - @ApiResponse(responseCode = "200", description = "Token refreshed successfully"), - @ApiResponse(responseCode = "400", description = "Refresh token is missing or invalid") + @ApiResponse(responseCode = "200", description = "토큰 갱신 성공"), + @ApiResponse(responseCode = "400", description = "리프레시 토큰이 없거나 유효하지 않음") }) @PostMapping("/refreshtoken") public ResponseEntity refreshtoken(HttpServletRequest request) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0b07387..807a35a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,6 +5,11 @@ spring.datasource.password=cuuva spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect spring.jpa.hibernate.ddl-auto= create-drop +spring.sql.init.mode=always + +spring.jpa.defer-datasource-initialization=true + + # App Properties bezkoder.app.jwtCookieName= bezkoder-jwt bezkoder.app.jwtRefreshCookieName= bezkoder-jwt-refresh diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql new file mode 100644 index 0000000..14e282c --- /dev/null +++ b/src/main/resources/data.sql @@ -0,0 +1,5 @@ +-- src/main/resources/data.sql + +INSERT INTO tb_role (id, name) VALUES (1, 'ROLE_USER'); +INSERT INTO tb_role (id, name) VALUES (2, 'ROLE_MODERATOR'); +INSERT INTO tb_role (id, name) VALUES (3, 'ROLE_ADMIN');