Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable spring security for POST method

I have a spring security configuration like follows.

http.authorizeRequests().antMatchers("/css/**").permitAll().and().authorizeRequests().antMatchers("/imgs/**").permitAll().anyRequest()
    .fullyAuthenticated().and()
    //.csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, "/updatepass/**").permitAll().anyRequest().fullyAuthenticated().and()
    .formLogin().loginPage("/login")
    .failureUrl("/login?error=401").permitAll().and()
    //.csrf().ignoringAntMatchers("/updatepass").and()
    .logout().permitAll().and().csrf().disable()
    .authorizeRequests().antMatchers("/register").hasRole("ADMIN").and()
    .authorizeRequests().antMatchers("/registeruser").hasRole("ADMIN");     

I want to allow /updatepass POST method allowed for any request even if it's not a autherized request. I tried the following commented configurations, but still it's throwing me login page.

My target POST URL to be opened for is an API which would recieve a JSON request. and the complete URL is /updatepass I tried adding /** nothing works. Please don't suggest XML Configuration. Only Java configuration please.

like image 586
Pasupathi Rajamanickam Avatar asked Oct 26 '25 03:10

Pasupathi Rajamanickam


1 Answers

Try adding the overloaded method of configure(WebSecurity web) with following implementation.

public void configure(WebSecurity web)
               throws Exception {
     web.ignoring().antMatchers(HttpMethod.POST, "/updatepass/**");
}
like image 177
shazin Avatar answered Oct 28 '25 15:10

shazin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!