728x90
์๋ฌ ์ค๋ช
์๋ฐ ํ๋ก์ ํธ์์ SecurityConfig.java๋ฅผ ํตํด ์ํ๋ฆฌํฐ ํํฐ๋ฅผ ๊ฑฐ์ณ ์น ํ์ด์ง ์ ๊ทผํ ๋ ์๊ธด ์๋ฌ
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.formLogin().disable()
.httpBasic().disable()
.authorizeRequests()
.antMatchers("/api/v1/user/**")
.access("hasRole('ROLE_USER') or hasRole('ROLE_MANAGER') or hasROLE('ROLE_ADMIN')")
.antMatchers("/api/v1/manager/**")
.access("hasRole('ROLE_MANAGER') or hasRole('ROLE_ADMIN')")
.antMatchers("/api/v1/admin/**")
.access("hasRole('ROLE_ADMIN')")
.anyRequest().permitAll();
}
}
ํด๊ฒฐ
์์ธํ ๋ณด๋ฉด ์ฝ๋์์ hasRole('ROLE_ADMIN') ์ ์ ์ 16๋ฒ์งธ ์ค์ hasRole์ด ์๋๋ผ hasROLE์ด๋ผ๊ณ ์๋ชป ์ ํ์๋ค.
.access() ํจ์๋ ํ๋ผ๋ฏธํฐ๋ก "hasRole('ROLE_USER') and hasRole('ROLE_SUPER')" ์ด๋ฐ์์ผ๋ก ์ ์ด์ผํ๊ธฐ ๋๋ฌธ์ ์กฐ๊ธ์ด๋ผ๋ ํ๋ฆฌ๋ฉด ์๋ฌ๊ฐ ๋จ๋ ๊ฒ์ด๋ค.
์ง์ง ์ฌ์ํ ์ค์๋ ์๋ฐ๋ ์ฉ์ํ์ง ์๋๋ค..๐ฅฒ
ํ๋ฆฐ ์ฝ๋ (16๋ฒ์งธ ์ค)
.access("hasRole('ROLE_USER') or hasRole('ROLE_MANAGER') or hasROLE('ROLE_ADMIN')")
์์ ํ ์ฝ๋
.access("hasRole('ROLE_USER') or hasRole('ROLE_MANAGER') or hasRole('ROLE_ADMIN')")
๋๊ธ