Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringREST应用程序中安全约束的Java配置_Java_Spring_Spring Mvc_Spring Security_Configuration - Fatal编程技术网

SpringREST应用程序中安全约束的Java配置

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

我正在用SpringREST(不含web.xml)构建一个应用程序。REST调用工作正常,但我需要添加一些安全约束,这些约束很容易通过web.xml添加,但由于我使用的是Spring4,没有web.xml,因此我需要通过Java配置添加web.xml部分的帮助

My web.xml:


全部的
测试
/*
全部的


我需要通过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();

        }
}