【发布时间】:2019-05-11 21:28:17
【问题描述】:
我有一个应用程序暴露了一堆我没想到的端点。例如 localhost:8080/app/ 返回一个 URL 列表,其中包括与休眠实体相关的信息。
我不想启用基本身份验证,因为我配置了自己的身份验证。 但是,如果 URL 不是由我编写的 RestController 表示的 URL,那么我希望它到我拥有的现有禁止页面。
这是我当前的配置,但它不会阻止不需要的端点:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/api/**").antMatchers("/v2/**").antMatchers("/webjars/**").antMatchers("/swagger-resources/**")
.antMatchers("/swagger-ui.html");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.httpBasic().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.csrf().disable();
http.authenticationProvider(new CustomAuthenticationProvider()).authorizeRequests().anyRequest().authenticated()
.antMatchers("/v2/**").permitAll().antMatchers("/webjars/**").permitAll().antMatchers("/swagger-resources/**").permitAll()
.antMatchers("/swagger-ui.html").permitAll()
.antMatchers("/health").permitAll();
http.rememberMe().rememberMeServices(rememberMeService).useSecureCookie(useSecureCookie);
//Show 403 on denied access
http.exceptionHandling().authenticationEntryPoint(new Forbidden());
}
所以在这种情况下 localhost:8080/app/api/SearchControler/{var} 应该可以工作,但 localhost:8080/app/ 应该转到我的 Forbidden 入口点。而是 localhost:8080/app/ 进入 spring 用户名和密码页面。
首先我不知道为什么这些端点在没有 RestController 的情况下甚至会出现,其次为什么重定向到 403 页面如此困难。
我不确定我缺少什么配置。
* 编辑 *
我也试过了:
http.formLogin().and().httpBasic().disabled();
还有:
@EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class})
似乎没有什么能阻止 spring 接管并做任何想做的事情。
【问题讨论】:
标签: spring spring-boot spring-security