首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >春季安全-基本安全

春季安全-基本安全
EN

Stack Overflow用户
提问于 2015-05-26 21:18:41
回答 2查看 2.1K关注 0票数 2

我试图使用POST请求插入数据,但是我得到了一个403错误。当我使用GET时,基本身份验证是有效的。测试用的是Fiddler。

有什么问题吗?

安全配置:

代码语言:javascript
复制
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/**").hasRole("USER").and()
                .httpBasic();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth)
            throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user")
                    .password("password")
                    .roles("USER");
    }
}

请求-员额:

代码语言:javascript
复制
User-Agent: Fiddler
Host: localhost:8080
Content-Length: 200
Content-Type: application/json
Authorization: Basic dXNlcjpwYXNzd29yZA==

请求机构:

代码语言:javascript
复制
{"name" : "name1",
"description" : "desc1"}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-05-26 23:46:37

它可能是CSRF,它是spring安全默认启用的。在GET请求中查找标头,并在POST中使用该标头和值。

在做这件事之前要三思,但是你可以用

代码语言:javascript
复制
http.csrf().disable()

https://docs.spring.io/spring-security/site/docs/current/reference/html/web-app-security.html#csrf

票数 6
EN

Stack Overflow用户

发布于 2015-05-26 21:31:50

试试这个:

代码语言:javascript
复制
@Configuration
@EnableWebSecurity
public class HelloWebSecurityConfiguration
   extends WebSecurityConfigurerAdapter {

  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) {
    auth
      .inMemoryAuthentication()
        .withUser("user").password("password").roles("USER");
  }
}

来源:http://spring.io/blog/2013/07/03/spring-security-java-config-preview-web-security/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30469093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档