Spring method security: putting the permission check on the method
URL rules protect endpoints, but the same service method may also be called from a scheduled job, a message listener or another controller. Method security puts the check on the method itself, with annotations such as @PreAuthorize that Spring enforces through a proxy. This page runs each annotation, shows how rules read method arguments and return values, and demonstrates the cases where a check is silently skipped.
Contents
How method security works @PreAuthorize: roles, authorities and arguments @PostAuthorize: checking what the method returned @PreFilter and @PostFilter: filtering collections Custom rules: beans in expressions and meta-annotations Masking instead of failing: @HandleAuthorizationDenied Checks that silently do nothing Choosing between URL rules and method rules
How method security works
Method security moves authorization from the URL to the Java method. You annotate a service method with a rule, and Spring checks it every time the method is called, whatever the caller is. A rule can also use what URL rules never see: the method's arguments, and the object it returns.
@EnableMethodSecurity
- Read the
of the current thread fromAuthentication . With none, throwSecurityContextHolder .AuthenticationCredentialsNotFoundException - Evaluate the
expression, a SpEL expression that can refer to@PreAuthorize and to the arguments by name. If it is false, throwauthentication without running the method.AuthorizationDeniedException - Run the method.
- Evaluate
with the result available as@PostAuthorize , and apply anyreturnObject .@PostFilter
Because it is a proxy, method security shares every limit of Spring AOP: a call on this
| Annotation | Checked | Enabled by | Best for |
|---|---|---|---|
@PreAuthorize | Before the call, SpEL | Default | Most checks: roles, authorities, rules on arguments |
@PostAuthorize | After the call, SpEL with returnObject | Default | Ownership of the loaded object |
@PreFilter@PostFilter | Each element of a collection argument or result | Default | Removing elements the caller may not see or change |
@AuthorizeReturnObject | Proxies the returned object, so its own annotations apply | Default, since 6.3 | Field-level rules on domain objects |
@HandleAuthorizationDenied | Replaces the exception with a value | Default, since 6.3 | Masking a value instead of failing the call |
@Secured | Before the call, a list of authorities | securedEnabled = true | Older code |
@RolesAllowed | Before the call, JSR-250 roles | jsr250Enabled = true | Code shared with Jakarta EE |
@EnableMethodSecurity@EnableGlobalMethodSecurityprePostEnabled = trueAuthenticationSecurityContextHolder
@PreAuthorize: roles, authorities and arguments
The three methods below show the three kinds of rule people write most: a role, a fine-grained authority, and a comparison with an argument. Each is called first with nobody signed in, then by a user and by an admin, so every outcome appears:
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
public class PreAuthorizeDemo {
static class AccountService {
@PreAuthorize("hasRole('ADMIN')")
public String closeAccount(long id) {
return "closed account " + id;
}
@PreAuthorize("hasAuthority('account:read')")
public String balance(long id) {
return "balance of " + id + " is 120";
}
@PreAuthorize("#owner == authentication.name or hasRole('ADMIN')")
public String statements(String owner) {
return "statements of " + owner;
}
}
@Configuration
@EnableMethodSecurity
static class Config {
@Bean
AccountService accountService() {
return new AccountService();
}
}
static void signIn(String user, String... authorities) {
SecurityContextHolder.getContext().setAuthentication(
UsernamePasswordAuthenticationToken.authenticated(user, null,
AuthorityUtils.createAuthorityList(authorities)));
}
interface Call {
String run();
}
static void attempt(String label, Call call) {
try {
System.out.println(" " + label + " -> " + call.run());
} catch (AuthorizationDeniedException e) {
System.out.println(" " + label + " -> " + e.getClass().getSimpleName()
+ ": " + e.getMessage());
} catch (AuthenticationCredentialsNotFoundException e) {
System.out.println(" " + label + " -> " + e.getClass().getSimpleName());
}
}
public static void main(String[] args) {
try (var context = new AnnotationConfigApplicationContext(Config.class)) {
AccountService accounts = context.getBean(AccountService.class);
System.out.println("No one signed in:");
attempt("balance(7)", () -> accounts.balance(7));
signIn("ann", "ROLE_USER", "account:read");
System.out.println("ann, authorities [ROLE_USER, account:read]:");
attempt("balance(7)", () -> accounts.balance(7));
attempt("statements(\"ann\")", () -> accounts.statements("ann"));
attempt("statements(\"bob\")", () -> accounts.statements("bob"));
attempt("closeAccount(7)", () -> accounts.closeAccount(7));
signIn("root", "ROLE_ADMIN");
System.out.println("root, authorities [ROLE_ADMIN]:");
attempt("statements(\"bob\")", () -> accounts.statements("bob"));
attempt("closeAccount(7)", () -> accounts.closeAccount(7));
attempt("balance(7)", () -> accounts.balance(7));
}
}
}
No one signed in:
balance(7) -> AuthenticationCredentialsNotFoundException
ann, authorities [ROLE_USER, account:read]:
balance(7) -> balance of 7 is 120
statements("ann") -> statements of ann
statements("bob") -> AuthorizationDeniedException: Access Denied
closeAccount(7) -> AuthorizationDeniedException: Access Denied
root, authorities [ROLE_ADMIN]:
statements("bob") -> statements of bob
closeAccount(7) -> closed account 7
balance(7) -> AuthorizationDeniedException: Access Denied
- With nobody signed in,
threwbalance(7) , not a denial: there was no user to check. In a web application the filter chain normally prevents this case by putting an anonymous user in the context.AuthenticationCredentialsNotFoundException could read balances, because she has the authorityann , and her own statements, becauseaccount:read compared the argument#owner == authentication.name with her name."ann"- For
andstatements("bob") ,closeAccount(7) gotann , and the methods never ran.AuthorizationDeniedException: Access Denied could read bob's statements and close the account throughroot , but was refusedhasRole('ADMIN') : the rolebalance(7) does not include the authorityADMIN . Roles and authorities are just strings, and nothing makes one imply another unless you configure aaccount:read bean.RoleHierarchy
#ownerjavac -parameters@P("owner")AuthorizationDeniedExceptionAccessDeniedExceptionExceptionTranslationFilter
@PostAuthorize: checking what the method returned
Some rules depend on data you only have after loading it, such as the owner of a document. @PostAuthorizeann
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
public class PostAuthorizeDemo {
record Document(long id, String owner, String title) {
}
static class DocumentService {
final List<String> auditLog = new ArrayList<>();
@PostAuthorize("returnObject.owner == authentication.name")
public Document open(long id) {
Document doc = id == 1 ? new Document(1, "ann", "Ann's tax return")
: new Document(2, "bob", "Bob's payslip");
auditLog.add("opened " + id + " (marked as read)"); // side effect
return doc;
}
public List<String> auditLog() {
return auditLog;
}
}
@Configuration
@EnableMethodSecurity
static class Config {
@Bean
DocumentService documentService() {
return new DocumentService();
}
}
public static void main(String[] args) {
try (var context = new AnnotationConfigApplicationContext(Config.class)) {
DocumentService docs = context.getBean(DocumentService.class);
SecurityContextHolder.getContext().setAuthentication(
UsernamePasswordAuthenticationToken.authenticated("ann", null,
AuthorityUtils.createAuthorityList("ROLE_USER")));
for (long id : new long[] {1, 2}) {
try {
System.out.println("open(" + id + ") -> " + docs.open(id));
} catch (AuthorizationDeniedException e) {
System.out.println("open(" + id + ") -> " + e.getMessage());
}
}
System.out.println("audit log: " + docs.auditLog());
}
}
}
open(1) -> Document[id=1, owner=ann, title=Ann's tax return]
open(2) -> Access Denied
audit log: [opened 1 (marked as read), opened 2 (marked as read)]
- Document 1 belongs to
, soann was true and she received it.returnObject.owner == authentication.name - Document 2 belongs to
. The method ran, loaded it, and only then was the result refused withbob .Access Denied - The audit log has two entries. The denied call still marked document 2 as read, because a post check cannot undo what the method already did.
Use @PostAuthorize@PreAuthorize@Transactional
@PreFilter and @PostFilter: filtering collections
Filtering annotations evaluate an expression for each element of a collection, with the element as filterObjectann
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreFilter;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
public class FilterDemo {
record Invoice(int id, String owner) {
}
static class InvoiceService {
int rowsLoaded;
@PostFilter("filterObject.owner == authentication.name")
public List<Invoice> all() {
List<Invoice> rows = new ArrayList<>();
for (int i = 1; i <= 1000; i++) {
rows.add(new Invoice(i, i % 250 == 0 ? "ann" : "someone-else"));
}
rowsLoaded += rows.size();
return rows;
}
public int rowsLoaded() {
return rowsLoaded;
}
@PostFilter("filterObject.owner == authentication.name")
public List<Invoice> immutable() {
return List.of(new Invoice(1, "ann"), new Invoice(2, "bob"));
}
@PreFilter("filterObject.owner == authentication.name")
public String deleteAll(List<Invoice> invoices) {
return "deleting " + invoices;
}
}
@Configuration
@EnableMethodSecurity
static class Config {
@Bean
InvoiceService invoiceService() {
return new InvoiceService();
}
}
public static void main(String[] args) {
try (var context = new AnnotationConfigApplicationContext(Config.class)) {
InvoiceService service = context.getBean(InvoiceService.class);
SecurityContextHolder.getContext().setAuthentication(
UsernamePasswordAuthenticationToken.authenticated("ann", null,
AuthorityUtils.createAuthorityList("ROLE_USER")));
List<Invoice> mine = service.all();
System.out.println("@PostFilter: loaded " + service.rowsLoaded()
+ " rows, returned " + mine.size() + ": " + mine);
List<Invoice> request = new ArrayList<>(List.of(new Invoice(4, "ann"),
new Invoice(5, "bob"), new Invoice(6, "ann")));
System.out.println("@PreFilter: " + service.deleteAll(request));
System.out.println("caller's list afterwards: " + request);
List<Invoice> fromImmutable = service.immutable();
System.out.println("@PostFilter on List.of(...): " + fromImmutable + ", a "
+ fromImmutable.getClass().getSimpleName());
}
}
}
@PostFilter: loaded 1000 rows, returned 4: [Invoice[id=250, owner=ann], Invoice[id=500, owner=ann], Invoice[id=750, owner=ann], Invoice[id=1000, owner=ann]]
@PreFilter: deleting [Invoice[id=4, owner=ann], Invoice[id=6, owner=ann]]
caller's list afterwards: [Invoice[id=4, owner=ann], Invoice[id=6, owner=ann]]
@PostFilter on List.of(...): [Invoice[id=1, owner=ann]], a ArrayList
returned only@PostFilter 's invoices 250, 500, 750 and 1000, but the method loaded all 1,000 rows first. The filtering happens in memory, after the database has done all the work.ann removed bob's invoice 5 from the argument before the method saw it, so only 4 and 6 were deleted.@PreFilter- The caller's own list also lost invoice 5.
changes the collection that was passed in, which surprises callers that use the list again afterwards.@PreFilter on an immutable@PostFilter worked and returned a newList.of(...) , so you do not have to return a mutable list.ArrayList
The filters are convenient for small lists, but for anything that can grow, filter in the query instead, for example with a WHERE owner = ?findByOwner
Custom rules: beans in expressions and meta-annotations
Expressions grow hard to read once a rule needs data, such as who owns a project. Two features keep annotations short: calling a Spring bean from the expression with @beanName
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Map;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AnnotationTemplateExpressionDefaults;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
public class CustomExpressions {
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("hasAnyRole({roles})")
@interface AllowRoles {
String[] roles();
}
static class ProjectAccess {
private final Map<Long, String> owners = Map.of(10L, "ann", 20L, "bob");
public boolean canEdit(long projectId, Authentication auth) {
System.out.println(" projectAccess.canEdit(" + projectId + ", " + auth.getName()
+ ")");
return auth.getName().equals(owners.get(projectId));
}
}
static class ProjectService {
@PreAuthorize("@projectAccess.canEdit(#projectId, authentication)")
public String rename(long projectId, String name) {
return "project " + projectId + " renamed to " + name;
}
@AllowRoles(roles = {"'MANAGER'", "'ADMIN'"})
public String budget(long projectId) {
return "budget of " + projectId + " is 5000";
}
}
@Configuration
@EnableMethodSecurity
static class Config {
@Bean
static AnnotationTemplateExpressionDefaults templateDefaults() {
return new AnnotationTemplateExpressionDefaults();
}
@Bean
ProjectAccess projectAccess() {
return new ProjectAccess();
}
@Bean
ProjectService projectService() {
return new ProjectService();
}
}
interface Call {
String run();
}
static void attempt(String label, Call call) {
System.out.println(" " + label);
try {
System.out.println(" -> " + call.run());
} catch (AuthorizationDeniedException e) {
System.out.println(" -> " + e.getMessage());
}
}
public static void main(String[] args) {
try (var context = new AnnotationConfigApplicationContext(Config.class)) {
ProjectService projects = context.getBean(ProjectService.class);
SecurityContextHolder.getContext().setAuthentication(
UsernamePasswordAuthenticationToken.authenticated("ann", null,
AuthorityUtils.createAuthorityList("ROLE_MANAGER")));
System.out.println("ann, ROLE_MANAGER:");
attempt("rename(10, \"Apollo\")", () -> projects.rename(10, "Apollo"));
attempt("rename(20, \"Gemini\")", () -> projects.rename(20, "Gemini"));
attempt("budget(10)", () -> projects.budget(10));
SecurityContextHolder.getContext().setAuthentication(
UsernamePasswordAuthenticationToken.authenticated("bob", null,
AuthorityUtils.createAuthorityList("ROLE_USER")));
System.out.println("bob, ROLE_USER:");
attempt("budget(10)", () -> projects.budget(10));
}
}
}
ann, ROLE_MANAGER:
rename(10, "Apollo")
projectAccess.canEdit(10, ann)
-> project 10 renamed to Apollo
rename(20, "Gemini")
projectAccess.canEdit(20, ann)
-> Access Denied
budget(10)
-> budget of 10 is 5000
bob, ROLE_USER:
budget(10)
-> Access Denied
called the bean named@projectAccess.canEdit(#projectId, authentication) , and its print line shows the arguments it received. It returned true for project 10, owned byprojectAccess , and false for project 20, owned byann .bob expanded to@AllowRoles(roles = {"'MANAGER'", "'ADMIN'"}) , sohasAnyRole('MANAGER', 'ADMIN') , a manager, could read the budget andann , a plain user, could not.bob
A bean method is ordinary Java: it can be unit tested, use a repository, and be reused from many annotations. It is usually the clearest way to write ownership rules. Templates in meta-annotations, such as {roles}AnnotationTemplateExpressionDefaultsstatic@IsAdmin@PreAuthorize("hasRole('ADMIN')")
Masking instead of failing: @HandleAuthorizationDenied
Sometimes a denial should not fail the whole call: a support agent may see a customer record but not the email address. Spring Security 6.3 added two annotations for this. @AuthorizeReturnObject@HandleAuthorizationDenied
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authorization.AuthorizationResult;
import org.springframework.security.authorization.method.AuthorizeReturnObject;
import org.springframework.security.authorization.method.HandleAuthorizationDenied;
import org.springframework.security.authorization.method.MethodAuthorizationDeniedHandler;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
public class DeniedHandling {
public static class Mask implements MethodAuthorizationDeniedHandler {
@Override
public Object handleDeniedInvocation(MethodInvocation invocation,
AuthorizationResult result) {
return "****";
}
}
public static class Customer {
private final String name;
private final String email;
public Customer(String name, String email) {
this.name = name;
this.email = email;
}
public String getName() {
return name;
}
@PreAuthorize("hasAuthority('customer:pii')")
@HandleAuthorizationDenied(handlerClass = Mask.class)
public String getEmail() {
return email;
}
}
static class CustomerService {
@AuthorizeReturnObject
public Customer find(long id) {
return new Customer("Ann Lee", "ann@example.com");
}
}
@Configuration
@EnableMethodSecurity
static class Config {
@Bean
Mask mask() {
return new Mask();
}
@Bean
CustomerService customerService() {
return new CustomerService();
}
}
static void show(CustomerService service, String user, String... authorities) {
SecurityContextHolder.getContext().setAuthentication(
UsernamePasswordAuthenticationToken.authenticated(user, null,
AuthorityUtils.createAuthorityList(authorities)));
Customer c = service.find(1);
System.out.println(user + ": name = " + c.getName() + ", email = " + c.getEmail());
}
public static void main(String[] args) {
try (var context = new AnnotationConfigApplicationContext(Config.class)) {
CustomerService service = context.getBean(CustomerService.class);
show(service, "support", "ROLE_SUPPORT");
show(service, "dpo", "ROLE_SUPPORT", "customer:pii");
System.out.println("returned object class: "
+ service.find(1).getClass().getSimpleName());
}
}
}
support: name = Ann Lee, email = ****
dpo: name = Ann Lee, email = ann@example.com
returned object class: DeniedHandling$Customer$$SpringCGLIB$$0
- For
,support returnedgetName() , andAnn Lee returnedgetEmail() . The**** on the getter failed, and the@PreAuthorize handler supplied a value instead of an exception.Mask - For
, who has the authoritydpo , the real email came back.customer:pii - The returned object's class is
:Customer$$SpringCGLIB$$0 returned a proxy around thefind , which is how annotations on a plain domain object take effect.Customer
The proxy needs a class it can subclass, so the domain class must not be final
Checks that silently do nothing
A missing check does not fail; it just lets the call through. This program runs the same calls under two configurations to show the two most common ways a rule is ignored:
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
public class MethodSecurityTraps {
static class AdminService {
public String dashboard() {
return "dashboard, then " + this.purgeCache(); // call on 'this'
}
@PreAuthorize("hasRole('ADMIN')")
public String purgeCache() {
return "cache purged";
}
@Secured("ROLE_ADMIN")
public String legacyPurge() {
return "legacy purge ran";
}
}
@Configuration
@EnableMethodSecurity // securedEnabled is false by default
static class Defaults {
@Bean
AdminService adminService() {
return new AdminService();
}
}
@Configuration
@EnableMethodSecurity(securedEnabled = true)
static class WithSecured {
@Bean
AdminService adminService() {
return new AdminService();
}
}
interface Call {
String run();
}
static void attempt(String label, Call call) {
try {
System.out.println(" " + label + " -> " + call.run());
} catch (AuthorizationDeniedException e) {
System.out.println(" " + label + " -> denied");
}
}
public static void main(String[] args) {
SecurityContextHolder.getContext().setAuthentication(
UsernamePasswordAuthenticationToken.authenticated("ann", null,
AuthorityUtils.createAuthorityList("ROLE_USER")));
for (Class<?> config : new Class<?>[] {Defaults.class, WithSecured.class}) {
System.out.println("ann (ROLE_USER), config " + config.getSimpleName() + ":");
try (var context = new AnnotationConfigApplicationContext(config)) {
AdminService admin = context.getBean(AdminService.class);
attempt("purgeCache()", admin::purgeCache);
attempt("dashboard()", admin::dashboard);
attempt("legacyPurge()", admin::legacyPurge);
}
}
}
}
ann (ROLE_USER), config Defaults:
purgeCache() -> denied
dashboard() -> dashboard, then cache purged
legacyPurge() -> legacy purge ran
ann (ROLE_USER), config WithSecured:
purgeCache() -> denied
dashboard() -> dashboard, then cache purged
legacyPurge() -> denied
- Called directly,
was denied topurgeCache() in both configurations.ann - Called from
on the same bean, it ran: the output readsdashboard() . The internal call ondashboard, then cache purged went to the target object, not through the proxy, so the rule was never evaluated. A rule on a method that is also called from inside its class protects only the outside entrance.this - With the default
,@EnableMethodSecurity , markedlegacyPurge() , ran for a plain user.@Secured("ROLE_ADMIN") is off unless@Secured , and an annotation nobody reads changes nothing.securedEnabled = true - With
, the same call was denied.securedEnabled = true
Other ways a rule is skipped:
- Private and final methods: the proxy cannot intercept them, so their annotations are ignored.
- Objects created with new: only Spring beans get a proxy.
- Other threads:
methods and executors run without the caller's security context unless it is propagated, as the@AsyncSpring Security page shows with .DelegatingSecurityContextExecutorService
Write a test for each important rule that calls the method as a user who must be refused. spring-security-test@WithMockUser(roles = "USER")
Choosing between URL rules and method rules
| Rule | Best place |
|---|---|
Whole areas of the application: /admin/** | URL rules in the SecurityFilterChain |
| A role or authority for one operation | @PreAuthorize("hasAuthority('orders:refund')") |
| A rule that compares an argument with the user | @PreAuthorize("#owner == authentication.name") |
| Ownership that needs a database lookup | A bean method called from @PreAuthorize |
| Ownership of the loaded object, for read-only methods | @PostAuthorize |
| Hiding rows the user may not see | A filter in the query; @PostFilter |
| Hiding single fields | @AuthorizeReturnObject@HandleAuthorizationDenied |
| Permissions granted per object and stored in tables | |
| The same rule used in many places | A meta-annotation such as @IsAdmin |
Most applications use both kinds: coarse URL rules as the outer wall, and method rules for anything that depends on the data. For OAuth2 scopes in method rules, such as hasAuthority('SCOPE_orders.read')MonoFlux