October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Spring Security: Match Access Rules to the Right Boundary

Spring Security checks granted authorities: roles use a configurable prefix convention, while permission-like checks can match exact authority strings. Learn when to enforce each rule on requests or methods.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Spring Security treats roles and permissions as GrantedAuthority values. With the default role-prefix convention, hasRole("ADMIN") checks for ROLE_ADMIN; hasAuthority("invoice:read") checks for that exact string. Use request rules for broad URL policy and method security when a rule belongs to a business operation or depends on a particular object.

How roles and permissions map to authorities

An authenticated user has a collection of granted authorities. A role is a conventional kind of authority, commonly used for broad groupings such as administrators. A permission-like authority can represent a more specific capability, such as reading invoices or approving a payment. Spring Security ultimately evaluates authority values; the distinction is primarily in the check you write and the naming convention you choose.

As an Amazon Associate I earn from qualifying purchases.

  • hasRole("ADMIN") applies the default ROLE_ prefix and checks for ROLE_ADMIN.
  • hasAuthority("invoice:read") checks for the exact authority string invoice:read.

The role prefix is configurable, so ROLE_ is a default convention, not an immutable rule. Choose authority names and role mappings that reflect your application’s policy; Spring Security does not decide what “admin,” “read,” or “approve” should mean.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Restrict HTTP requests with authorizeHttpRequests

For Servlet applications, the current documented DSL is authorizeHttpRequests. It uses AuthorizationManager and AuthorizationFilter. Request matchers are evaluated in declaration order, so put specific rules before broad ones and finish with an intentional fallback.

#1 Best Overall
FortiGate-40F Firewall Appliance - 5 Gigabit Ethernet RJ45 Ports, Ideal for Small Businesses (Appliance Only, No Subscription) (FG-40F)
  • Compact and Efficient Design: The FortiGate 40F is designed for small to mid-sized businesses and enterprise branch offices, featuring a compact, fanless desktop form factor that ensures quiet operation and minimizes space usage.
  • Robust Connectivity Options: Equipped with 5 GE RJ45 ports, including 1 WAN port and 4 internal ports, this model provides essential connectivity and flexibility for various network configurations in a small-scale environment.
  • High-Performance Security: Offers up to 1 Gbps IPS throughput and 600 Mbps threat protection throughput, using Fortinet’s purpose-built security processor technology to deliver industry-leading performance and protection for SSL encrypted traffic.
  • Advanced Threat Protection: Integrated with Fortinet’s AI-powered FortiGuard Labs, the FortiGate 40F offers comprehensive cybersecurity, identifying and mitigating both known and unknown threats to maintain robust security across your network.
  • Simplified Management and Deployment: Features a user-friendly management console that provides comprehensive network automation and visibility, coupled with Zero Touch Integration with Fortinet’s Security Fabric for easy deployment.
@Bean
SecurityFilterChain app(HttpSecurity http) throws Exception {
    http.authorizeHttpRequests(authorize -> authorize
        .requestMatchers("/admin/**").hasRole("ADMIN")
        .requestMatchers(HttpMethod.GET, "/invoices/**").hasAuthority("invoice:read")
        .requestMatchers(HttpMethod.POST, "/invoices/**").hasAuthority("invoice:write")
        .anyRequest().denyAll()
    );
    return http.build();
}

This is an illustrative policy, not a complete application configuration. Configure the authentication mechanisms your application needs, and confirm that the matchers and their order cover the intended routes. The .anyRequest().denyAll() fallback rejects requests that do not match an earlier rule; if an application instead needs a different fallback, state that policy explicitly rather than leaving unmatched routes ambiguous. See the Spring Security request authorization reference.

Prefer type-safe rules when they fit

The Spring Security reference recommends using type-safe authorization managers instead of SpEL where possible. Expressions can still be useful when they make a policy clearer and the project’s version supports the API. WebExpressionAuthorizationManager is documented as a migration path for expression-based rules.

Rank #2
FortiGate-60F Network Security Appliance Plus 1 Year FortiGuard Unified Threat Protection (UTP) and FortiCare Premium (FG-60F-BDL-950-12)
  • HARDWARE PLUS SECURITY SERVICES: FortiGate-60F Firewall Appliance bundled with 1 year of FortiCare Premium and FortiGuard Unified Threat Protection.
  • UNIFIED THREAT PROTECTION (UTP): Secures against advanced online threats with comprehensive web filtering and anti-botnet technologies.
  • OPTIMIZED FOR MEDIUM-SIZED BUSINESSES: Tailored for businesses needing robust security without the infrastructure of larger enterprises.
  • RELIABLE CUSTOMER SUPPORT: FortiCare Premium ensures high-quality support and service continuity.
  • EFFECTIVE PROTECTION: Employs advanced filtering technologies to safeguard against sophisticated threats.

Use method security for business operations and object rules

Request checks answer whether a caller may reach a URL under a path-and-method policy. They do not necessarily express whether that caller may perform a particular business operation or access a specific record. Method security places the decision at the method boundary, which can protect an operation reached through more than one route and can use method arguments.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
@PreAuthorize("hasAuthority('invoice:approve')")
public void approveInvoice(long invoiceId) {
    // Business operation
}

Enable method security in the application configuration before relying on method annotations. The exact surrounding configuration depends on the application and Spring Security version.

Rank #3
GL.iNet GL-MT5000 Brume 3 Wired VPN Security Gateway NO Wi-Fi
  • 【Up to 1100 Mbps VPN Speed 】 Hardware-accelerated WireGuard and OpenVPN-DCO deliver up to 1100 Mbps VPN throughput, over 3× faster than Brume 2 for smooth remote access and file transfers.
  • 【Three 2.5G Ports & Multi-WAN】Tri-port 2.5GbE design with flexible WAN LAN configuration supports multi-gigabit wired setups, dual-ISP Multi-WAN and failover to keep home and SOHO networks online.
  • 【Stealth VPN Obfuscation】VPN obfuscation disguises VPN traffic as regular HTTPS, helping you evade blocking, bypass restrictive networks and maintain stable, private connections.
  • 【DPI protection】Deep Packet Inspection with visual dashboards blocks adult/gambling/malicious sites, while SQM and QoS prioritize gaming, calls, and video when bandwidth is tight
  • 【OpenWrt & USB 3.0 Expansion】OpenWrt with 1GB DDR4 and 8GB eMMC lets you install plugins and build VPN, ad-blocking or NAS, while USB 3.0 Type‑C connects high-speed storage or 4G/5G dongles

Check ownership with care

@PostAuthorize can inspect the returned object, for example to verify that its owner matches the current user. The method runs before this check, however. A post-invocation decision may therefore be too late if the method has side effects or if the underlying read itself must be restricted. In those cases, prefer a pre-invocation check or constrain the data query so unauthorized records are not fetched. Spring Security’s method security reference describes post-authorization ownership checks and their relevance to insecure direct object reference protection.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the enforcement boundary that matches the rule

Question Request authorization Method authorization
Where does it enforce? At the URL and HTTP request boundary At method invocation
What policy context is available? Request path and HTTP method Method arguments; post-authorization can inspect a returned object
Can it cover multiple entry points? It applies when a request matches the configured route rules It can protect the operation wherever that secured method is invoked
When is it most useful? Broad route policy, such as restricting an administrative path Operation-specific permissions and rules tied to a particular object

These boundaries can complement each other: a request rule can set broad access expectations while a method rule protects a sensitive operation or object. There is no universal layering rule for every application; keep each policy visible at the boundary that best represents what it protects.

Version context for older examples

Older tutorials may use authorizeRequests and the legacy Access API. Do not mix those examples with the current authorizeHttpRequests DSL without accounting for the version difference. The Spring Security 7 reference says AccessDecisionManager, AccessDecisionVoter, and related Access API types moved to the legacy spring-security-access module; new applications do not need that dependency. This is a note about the documented Spring Security 7 transition, not a compatibility guide for every historical release. Consult the reference for the version used by your project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.