liveBook · Manning

denyAll

As explained in Spring Security in Action, Second Edition

denyAll is a Spring Security authorization configuration method that denies access to every request matched by a rule.

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

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines the method, shows SecurityFilterChain configuration, and defers detailed path and variable matching syntax.
Examples
Uses email suffix filtering and gateways that deny paths outside their assigned services.
What it assumes
Assumes basic authentication and authorization configuration, while distinguishing authentication from authorization.
What you can do after
Configure Spring Security to reject all requests matching a selected authorization rule.
How it connects
Connects authorization with authentication, permitAll(), requestMatchers(), roles, and authorities.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.