2
在
春季启动Web应用程序我有以下安全配置:春天开机 - 返回403禁止的,而不是重定向到登录页面
@Override
public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.headers().frameOptions().disable()
.and()
.antMatcher("/**").authorizeRequests()
.antMatchers("/actuator/health").permitAll()
.antMatchers("/actuator/**").hasAuthority(Authority.Type.ROLE_ADMIN.getName())
.antMatchers("/login/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login")
.failureUrl("/login?error").permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login?logout")
.and()
.csrf().csrfTokenRepository(csrfTokenRepository())
.and()
.addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
// @formatter:on
}
现在,当我尝试下面的URL访问,例如:/api/v1.0/user
它会将我重定向到/api/login
页面。
如何配置此为了返回403 Forbidden
而不是重定向到登录页面?
猜你需要写你的AuthenticationEntryPoint – Tong
@Tong的感谢!我已将'.exceptionHandling()。authenticationEntryPoint(new Http403ForbiddenEntryPoint())'添加到我的配置中,现在它按预期工作 – alexanoid