Spring Security
@PreAuthorize
Check authorization before a proxied method invocation. Boot 4.0.10 / Security 7.0.9 companion project; source-reviewed, not executed.
Formal Syntax & Structure
java syntaxjava
@PreAuthorize("hasAuthority('SCOPE_report.read') and @tenantAccess.allowed(authentication, #tenant)")Working Example
Example Snippetjava
package example.tenant;import org.springframework.security.access.prepost.PreAuthorize;import org.springframework.security.core.parameters.P;import org.springframework.stereotype.Service;@Servicepublic class ReportService { @PreAuthorize("hasAuthority('SCOPE_report.read') and @tenantAccess.allowed(authentication, #tenant)") public String report(@P("tenant") String tenant) { return "report for " + tenant; // Synthetic response; no database. }}