denyAll() is a Spring Security authorization rule that rejects every request matched by it. It is the opposite of permitAll(), and authorization runs after authentication. section 7.1.3 section 7.2
Selective endpoint denial
A rule can allow email-address paths ending in .com while applying denyAll() to other formats, such as .net. A gateway can similarly serve one path and deny requests for paths handled elsewhere. section 7.1.3
Listing 7.12 Using the denyAll() method to restrict access to endpoints
@Configuration
public class ProjectConfig {
// Omitted code
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http)
throws Exception {
http.httpBasic(Customizer.withDefaults());
http.authorizeHttpRequests(
c -> c.anyRequest().denyAll()
); #1
return http.basic();
}
}
Configure a SecurityFilterChain with HTTP Basic authentication and apply denyAll() to every request. section 7.1.3
