SpringREST应用程序中安全约束的Java配置
我正在用SpringREST(不含web.xml)构建一个应用程序。REST调用工作正常,但我需要添加一些安全约束,这些约束很容易通过web.xml添加,但由于我使用的是Spring4,没有web.xml,因此我需要通过Java配置添加web.xml部分的帮助 My web.xml:SpringREST应用程序中安全约束的Java配置,java,spring,spring-mvc,spring-security,configuration,Java,Spring,Spring Mvc,Spring Security,Configuration,我正在用SpringREST(不含web.xml)构建一个应用程序。REST调用工作正常,但我需要添加一些安全约束,这些约束很容易通过web.xml添加,但由于我使用的是Spring4,没有web.xml,因此我需要通过Java配置添加web.xml部分的帮助 My web.xml: 全部的 测试 /* 全部的 我需要通过Java配置来配置这个web.xml的帮助。这可能可以通过Spring安全性添加,但不确定如何添加。这就是如何使用自定义约束实现安全性using@Configuratio
全部的
测试
/*
全部的
我需要通过Java配置来配置这个web.xml的帮助。这可能可以通过Spring安全性添加,但不确定如何添加。这就是如何使用自定义约束实现安全性using@Configuration并超越了WebSecurityConfigureAdapter类的配置方法
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
DataSource datasource;
Logger logger = LoggerFactory.getLogger(getClass());
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and().authorizeRequests().antMatchers("/public/**")
.permitAll().antMatchers("/admin/**").hasAuthority("admin")
.antMatchers("/user/**").hasAuthority("user")
.and()
.logout()
// Logout requires form submit. Bypassing the same.
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/index.html").and()
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
.csrf().disable();
}
}