- ํ์ฌ ์ํฉ : ๋ก๊ทธ์ธ ์ ์๋ ์ง๋ฌธ๋ฑ๋ก ํผ์ผ๋ก ๋ค์ด๊ฐ ์ ์๋ค.

Controller ์์ ๋จผ์ ๋ก๊ทธ์ธ์ด ์ธ์ฆ๋์ด์ผํ๋ ๋ถ๋ถ์ @PreAuthorize ์ด๋ ธํ ์ด์ ์ ์ถ๊ฐํ๋ค. ์ด๋ ๋ค์ ๋ถ์ "isAuthenticated()" ๋ ๋ก๊ทธ์ธ์ด ํ์ธ๋์ด์ผํ๋ค๋ ๋ป์ด๋ฉฐ, ํ์ธํ์ง ์์๋ ๋๋ค๋ฉด "isAnonymous()" ๋ฅผ ๋ถ์ด๋ฉด ๋์ง๋ง ๊ทธ๋ ๋ค๋ฉด ํด๋น ์ด๋ ธํ ์ด์ ์ ์กด์ฌ ์ด์ ๋ ์์ ๊ฒ์ด๋ค.
- Controller ๋ถ๋ถ
@PreAuthorize("isAuthenticated()")
@GetMapping("/create")
public String questionCreate(QuestionForm questionForm) {
return "question_form"
}
์ ์ํ๋ก ํ๋ก์ ํธ๋ฅผ ์คํ์์ผ๋ณด๋ฉด ์๊ฒ ์ง๋ง, @PreAuthorize ๋ฅผ ์ถ๊ฐํ๋ค๊ณ ๋ฐ๋ก ๊ฐ๋ฅํ ๊ฒ์ด ์๋๋ค. SecurityConfig ํ์ผ์๋ @EnableGlobalMethodSecurity ๋ฅผ ์ถ๊ฐํจ์ผ๋ก์ ์ ์ธ์ฆ์ ํ์ฑํ ์์ผ์ฃผ์ด์ผํ๋ค.
- SecurityConfig ๋ถ๋ถ
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
// Security ์ค์
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig { }
- @PreAuthorize ์ ์ฉ ํ ํ๋ฉด


์ด ๊ธ์ ์ ํ ํฌ ์คํ๋ง๋ถํธ (https://wikidocs.net/book/7601) ์ ํ์ต๋ด์ฉ ์ผ๋ถ๋ฅผ ์ ๋ฆฌํ ๊ธ ์ ๋๋ค.
'Spring Boot ๐ฟ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| (Spring) Spring Boot DevTools ์ฌ์ฉ๋ฒ (์๋ฒ ์ฌ์คํ ์์ด ์ฝ๋ ์์ ํ์ธ) (0) | 2022.10.06 |
|---|---|
| (Thymeleaf) DB๊ฐ์ผ๋ก๋ถํฐ ์ฒดํฌ๋ฐ์ค ์ฒดํฌ ์ฌ๋ถ ์ ํ (0) | 2022.09.27 |
| (Spring) ๋น๋๊ธฐ ์ฒ๋ฆฌ ๊ตฌํ 1 (0) | 2022.08.21 |
| (Spring) JPA ์ฌ์ฉ์ Truncate ์๋ฌ ํด๊ฒฐ (0) | 2022.08.11 |
| (Spring) DAO, DTO ๊ทธ๋ฆฌ๊ณ VO (0) | 2022.07.31 |