Я разрабатываю приложение для начальной загрузки, и его конфигурация безопасности для пружин выглядит следующим образом:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
.antMatchers("/actuator/**", "/login*", "/logout*")
.permitAll();
httpSecurity
.cors().and()
.csrf().disable()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/taas/v1/**").hasRole("admin")
.antMatchers("/taas/v1/teams", "/taas/v1/profiles", "/taas/v1/tests/summary").hasRole("tester")
.antMatchers( "/taas/v1/teams", "/taas/v1/tests/summary").hasRole("user")
.anyRequest().authenticated()
.and()
.exceptionHandling().accessDeniedHandler(customAccessDeniedHandler)
.and()
.httpBasic()
.and()
.formLogin()
.successHandler(customAuthenticationSuccessHandler)
.failureHandler(customAuthenticationFailureHandler)
.and()
.logout()
.logoutSuccessHandler(customLogoutSuccessHandler())
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID");
}
}
Несмотря на то, что я установил шаблон URL для каждой роли. Все пользователи могут получить доступ ко всем конечным точкам, как указано в antMatchers (). Пользователь с ролью user
не должен иметь доступ к /taas/v1/profiles
. Но когда я пытаюсь получить доступ к этой конечной точке, войдя в систему как user
, я получаю ответ, но ожидаемый ответ - 403 forbidden
.
. Я прошу кого-нибудь предоставить мне обходной путь.