在SpringBoot Web安全性中,localhost的限制不起作用。通过注释configure方法内容,URL(http://127.0.0.1:8080/SPPA/runSPPAJob)正在运行,否则会出现错误。
代码:
@EnableWebSecurity
@Configuration
public class AllowOnlyLocalhostFilter extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/SPPA/**").
access("hasIpAddress('127.0.0.1')").anyRequest().authenticated();
}
}
网页回复:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 29 16:05:46 IST 2017
There was an unexpected error (type=Forbidden, status=403).
Access Denied
日志:
2017-05-29 16:05:46.482 INFO 3644 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/SPPA] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-05-29 16:05:46.482 [http-nio-8080-exec-1] INFO
o.a.c.c.C.[.[localhost].[/SPPA]-Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-05-29 16:05:46.485 INFO 3644 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-05-29 16:05:46.485 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization started
2017-05-29 16:05:46.684 INFO 3644 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 199 ms
2017-05-29 16:05:46.684 [http-nio-8080-exec-1] INFO
o.s.web.servlet.DispatcherServlet-FrameworkServlet 'dispatcherServlet': initialization completed in 199 ms