Spring security authorize request for url & method using HttpSecurity

前端 未结 3 386
不思量自难忘°
不思量自难忘° 2020-12-28 12:49

Is there any way to authorize post request to a specific url using org.springframework.security.config.annotation.web.builders.HttpSecurity ?

I\'m usin

相关标签:
3条回答
  • 2020-12-28 13:06

    I know this question is a bit old but I don't believe disabling csrf support is an acceptable answer. I had this same problem but don't feel good able using csrf.disable(). Instead I added the following line at the bottom of the page inside the form tags.

    <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
    
    0 讨论(0)
  • 2020-12-28 13:27

    Just Mention the path you need to remove Authentication like this

        http
           .httpBasic().and()
           .authorizeRequests()
           .antMatchers("/employees" , "/employees/**")
           .permitAll().anyRequest().authenticated()
           .and().csrf().disable()
    
    0 讨论(0)
  • 2020-12-28 13:28

    Take a look here https://github.com/spring-projects/spring-data-examples/tree/master/rest/security which has

    http
      .httpBasic().and()
      .authorizeRequests()
        .antMatchers(HttpMethod.POST, "/employees").hasRole("ADMIN")
        .antMatchers(HttpMethod.PUT, "/employees/**").hasRole("ADMIN")
        .antMatchers(HttpMethod.PATCH, "/employees/**").hasRole("ADMIN");
    
    0 讨论(0)
提交回复
热议问题