@PreAuthorize
@PreAuthorize is a Spring Security annotation that evaluates an authorization expression before permitting an annotated method invocation.
Spring Security in Action, Second Edition
@PreAuthorize is a Spring Security annotation that authorizes a method invocation by evaluating a Spring Expression Language expression before the method runs.
- How it is used
- Protects service or other application-layer methods before invocation, extending authorization beyond endpoint rules.
- How deep it goes
- Demonstrates enabling method security, annotating methods, evaluating authorities and parameters, and testing allowed and denied calls.
- Examples
- Uses write-authorized users, a protected greeting service, secret-name ownership, Java listings, and cURL responses.
- What you can do after
- Operate method security by enabling it, writing SpEL rules, and testing permitted and forbidden invocations.
Read how Spring Security in Action, Second Edition explains @PreAuthorize →
Spring AI in Action
@PreAuthorize is a Spring Security annotation that permits a method invocation only when its authorization expression evaluates to true.
- How it is used
- Protects Spring bean methods, including LLM-invoked tools, from unauthorized execution.
- How deep it goes
- Explains configuration, SpEL evaluation, role checking, and failure behavior, while deferring other method-security annotations.
- Examples
- Uses getGameComplexity, the PREMIUM_USER role, Function.apply(), and authorized or refused Burger Battle requests.
- What you can do after
- Configure role-based method authorization for tools and prevent unauthorized invocations.
Related concepts
- Spring Expression Languageuses · Spring Expression Language is an expression language integrated with Spring for querying and manipulating object graphs and evaluating values, conditions, and configuration rules.
- @PostAuthorizealternative to · @PostAuthorize is a Spring Security annotation that evaluates an authorization expression after a method returns and can inspect or reject its result.
- AccessDeniedExceptionproduces · AccessDeniedException is a security exception indicating that an authorization check rejected access to a protected resource or operation.
- authorizationconfigures · Authorization is the determination and enforcement of rules governing which subjects may access resources or perform operations.
- preauthorizationused by · Preauthorization is authorization checking performed before a protected method executes, preventing the call when its conditions are not satisfied.
- method-level securityconfigures · Method-level security is authorization enforced on individual method invocations according to the caller’s identity or authorities.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

