-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/bundle #17
Feature/bundle #17
Conversation
ํ์ฌ ๋ฐฉ์์ ์๋์ ํ์ง๋ง, ์ธ์ฆ ๊ด๋ จ ์ฑ ์์ ๋ถ๋ฆฌํ๋ ๊ฒ์ด ๋ ์ข์ต๋๋ค @Service
@RequiredArgsConstructor
public class AuthenticationService {
/**
* ํ์ฌ ์ธ์ฆ๋ ์ฌ์ฉ์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฉ์๋
*/
public User getCurrentUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || !authentication.isAuthenticated()) {
throw new UnauthorizedException("์ธ์ฆ๋์ง ์์ ์ฌ์ฉ์์
๋๋ค.");
}
String userId = authentication.getName();
return userRepository.findById(Long.valueOf(userId))
.orElseThrow(() -> new UserNotFoundException("์ฌ์ฉ์๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."));
}
}
// ์ฌ์ฉ ์์
@Service
@RequiredArgsConstructor
public class BundleService {
private final AuthenticationService authenticationService;
public BundleResponse createBundle(BundleRequest request) {
User currentUser = authenticationService.getCurrentUser();
// ์ด๋ฐ์์ผ๋ก ์จ๋ ๊ด์ฐฎ์ ๊ฑฐ ๊ฐ์ต๋๋ค.
}
}
TestJwtTokenProvider๋ฅผ ํ์ฉํด์ ๋ค์๊ณผ ๊ฐ์ด ๊ฐ๋ฐ ํ๊ฒฝ์ฉ ํ ํฐ ๋ฐ๊ธ API๋ฅผ ๊ตฌํํ๋ฉด ๋ ๊ฑฐ ๊ฐ์ต๋๋ค. @Profile("dev") // ๊ฐ๋ฐ ํ๊ฒฝ์์๋ง ํ์ฑํ
@RestController
@RequestMapping("/api/test")
@RequiredArgsConstructor
public class TestAuthController {
@GetMapping("/token")
public ResponseEntity<Map<String, String>> getTestToken() {
String token = TestJwtTokenProvider.generateTestToken("test-user");
return ResponseEntity.ok(Map.of("token", token));
}
} ๊ทธ๋ฆฌ๊ณ SecurityConfig์์ ์ด ํ ์คํธ ์๋ํฌ์ธํธ์ ๋ํ ์ ๊ทผ์ ํ์ฉํด์ฃผ๋ฉด ๋ฉ๋๋ค: .requestMatchers("/api/test/token").permitAll() ์ด๋ ๊ฒ ํ๋ฉด ๊ฐ๋ฐ ํ๊ฒฝ์์
ํ์ฌ์ฒ๋ผ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ๋ฐํํ๋ ๊ฒ๋ณด๋ค๋, ์ฉ๋์ ๋ง๊ฒ ์๋ต์ ๋ถ๋ฆฌํ๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. |
Pull Request
๐ก PR ์์ฝ
๋ณด๋ฐ๋ฆฌ ์ต์ด ์์ฑ API๋ฅผ ๊ฐ๋ฐํ์์ต๋๋ค.
JWT ๊ธฐ๋ฐ ์ฌ์ฉ์ ์ธ์ฆ์ ์ถ๊ฐํ์ฌ, ํ์ฌ ๋ก๊ทธ์ธํ ์ฌ์ฉ์ ์ ๋ณด๋ฅผ ํ์ฉํ๋๋ก ํ์์ต๋๋ค.
์ต์ด ์์ฑ๋ ๋ณด๋ฐ๋ฆฌ์๋ ๋ณด๋ฐ๋ฆฌ๋ช ์ธ์๋ ์ ๋ฌผ๊ฐ์ฒด๋ค, ์ ๋ฌผ์ด๋ฏธ์ง ๊ด๋ จ ๋ฐ์ดํฐ๋ค์ด ํฌํจ๋ฉ๋๋ค.
๐ ์ฃผ์ ๋ณ๊ฒฝ์ฌํญ
๐ ์ฐ๊ด๋ ์ด์
๐ธ ์คํฌ๋ฆฐ์ท (์ ํ)
โ ์ฒดํฌ๋ฆฌ์คํธ
๐ ๋ฆฌ๋ทฐ์ด ์ฐธ๊ณ ์ฌํญ
๐ ์ถ๊ฐ ์ปจํ ์คํธ (์ ํ)