Skip to main content

Method-Level Security

Learn Method-Level Security (Spring Security, Spring Boot) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Why Secure Methods and Not Only URLs? URL rules in the SecurityFilterChain are the front door. But the same service method may be called from a controller, a scheduled job, a message listener and another service - none of which pass through a URL rule. Method security puts the check on the method itself, so it applies however it is reached, and it can look at the method's arguments and return value. Switch it on once with @EnableMethodSecurity . (In Spring Security 6 this replaces @EnableGlobalMethodSecurity , and @PreAuthorize is enabled by default.)

More lessons in Spring Security