How to disable spring security for particular url
When using permitAll
it means every authenticated user, however you disabled anonymous access so that won't work.
What you want is to ignore certain URLs for this override the configure
method that takes WebSecurity
object and ignore
the pattern.
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/api/v1/signup");
}
And remove that line from the HttpSecurity
part. This will tell Spring Security to ignore this URL and don't apply any filters to them.
How to enable spring security for particular url
http
.csrf().disable()
.httpBasic().and()
.authorizeRequests()
.antMatchers("/admin/**").hasAuthority("ADMIN")
.antMatchers("/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/adminLogin").failureUrl("/adminLogin?error=true")
.defaultSuccessUrl("/admin/dashboard")
.usernameParameter("email")
.passwordParameter("password")
.and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/adminLogin?logout=true").and().exceptionHandling()
.accessDeniedPage("/accessdenied");
works perfectly for me.
How to allow request from a certain url with spring security
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/script/**", "/css/**", "/getRegisterPage","/user/signup").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/getLoginPage")
.loginProcessingUrl("/login")
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/home", true)
.permitAll();
}
Related Topics
How to Replace Dot (.) in a String in Java
Eclipse No Tests Found Using Junit 5 Caused by Noclassdeffounderror for Launcherfactory
Kafka: How to Delete Records from a Topic Using Java API
Java.Time.Format.Datetimeparseexception: Text Could Not Be Parsed At Index 3
Java.Lang.Noclassdeffounderror: Com/Fasterxml/Jackson/Databind/Exc/Invaliddefinitionexception
Spring Security Configuration Filter Any Requests Except a Specific Endpoint
How to Sort Json Object in Java
Httprequest Maximum Allowable Size in Tomcat
How to Handle Errors in Spring-Webflux
Get Timezone of Area With Country Code in Java
How to Find Max Duplicate Number Count in Given Array Using for Loop
How to Exclude a Dependency from Parent'S Project in Maven
Remove Ns2 as Default Namespace Prefix
In Java, How to Combine Two Json Arrays of Objects
Create List of Object from Another Using Java 8 Streams
How to Know If Data Exists in a Firestore Query Snapshot
How to Get Full Name of an Employee by Joining First, Middle and Last Name Considering Null in Java