오류 설명
Java 프로젝트에서 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();
}
}
해결하다
자세히 살펴보면 코드의 16번째 줄에서 hasRole(‘ROLE_ADMIN’)은 다음과 같이 말합니다. 역할이 있다~ 아니다 역할이 있음철자가 틀리다
.access() 함수는 이런 식으로 매개변수로 작성해야 하므로 조금 틀리면 오류가 발생합니다.
자바는 아주 작은 실수도 용서하지 않습니다..
잘못된 코드(16행)
.access(“hasRole(‘ROLE_USER’) 또는 hasRole(‘ROLE_MANAGER’) 또는 역할이 있음(‘ROLE_ADMIN’)”)
변경된 코드
.access(“hasRole(‘ROLE_USER’) 또는 hasRole(‘ROLE_MANAGER’) 또는 역할이 있다(‘ROLE_ADMIN’)”)