Business

8 min read

How Broadleaf Handles the Complexities of Securing Microservices

Sam

Written by Sam

Published on Nov 24, 2026

Secure microservices

A stolen token that keeps working after the user logs out. A cart service that trusts the wrong caller. One tenant reading another tenant's catalog. These are the failures that make security teams nervous about microservices, and they are fair things to ask a commerce vendor about.

This post shows what Broadleaf does: which parts are standard Spring patterns, and which parts Broadleaf adds because commerce needs more than the framework provides.

Why distributed security is hard

In a monolith, a user authenticates once and the session lives in one place. In microservices, every service has to confirm a request is authenticated without phoning a central auth service each time. That one constraint creates four problems.

Services need to trust each other: when Cart calls Pricing, Pricing must know the caller is a legitimate internal service. Stateless tokens solve distributed authentication but add refresh, scoping, and storage to worry about. Tenants sharing the same services must stay invisible to one another. And an admin editing a catalog is a different security problem from a shopper browsing it, even though both hit the same APIs.

Standard patterns, plus what commerce needs

Broadleaf's security model is built on Spring Security's OAuth2 support. Where commerce requirements go beyond what Spring provides out of the box, Broadleaf supplies the missing pieces on top of Spring's authorization server: the permission model, the tenant-scoping layer, and pre-registered service clients.

Sign-in lives in one service

AuthenticationServices is a dedicated microservice that acts as both authentication provider and OAuth2 authorization server. Users sign in one of two ways.

With first-party login, AuthenticationServices hosts the login, registration, and password-reset forms. Users are redirected there and back on completion. Broadleaf calls this Centralized Universal Login and recommends it by default.

With a third-party identity provider, any OIDC-compliant provider such as Google or Okta can be wired in through Spring Security's OAuth2 client library. Stored client secrets are AES-256 encrypted, and each registration carries a tenant ID, so different tenants can use different identity providers on shared infrastructure.

Either path gives the user a session cookie. That cookie authenticates them to AuthenticationServices and lets them obtain OAuth2 access tokens through the standard protocol.

Sessions, access tokens, and refresh tokens

Three token types do three different jobs.

The session token is managed by AuthenticationServices and represents a login with that service. It is used for requests to AuthenticationServices itself, such as asking /oauth/authorize for a new access token, and its lifetime is a configurable sliding window.

The access token is what actually reaches your services. It is a permission-scoped OAuth2 bearer token with a much shorter lifetime, and calls to downstream services like catalog or cart rely only on it. Access tokens are signed JWTs (RS256 by default), so each microservice validates one locally against the authorization server's public key, with no call back to AuthenticationServices.

The optional refresh token gets a new access token when the current one expires, so users aren't sent back through login.

The authorization server supports several grant types, including the authorization code grant for front-end applications (PKCE is required by default), the client credentials grant for service-to-service calls, the refresh token grant, and API keys.

Where the gateways fit

Broadleaf runs two Spring Cloud Gateway instances, one for the Unified Admin and one for the storefront. Both route requests and give the front end a single origin, which saves you from configuring CORS at every service. Since 3.0.0, both gateways can also run an optional access token blacklist check, a niche option covered below.

Sign-in happens in AuthenticationServices, and each microservice decides what a caller may do. A gateway misconfiguration therefore can't authorize a request the service would reject.

Service-to-service calls

When Cart calls Pricing, Pricing has to trust the request. Broadleaf uses the OAuth2 client credentials flow: each service holds its own client registration and gets its own access token.

You write no token-fetching code. Declare the registration in properties, reference that client in your WebClient configuration, and Spring Security's OAuth2 client library obtains the token before the request goes out:

spring:

  security:

    oauth2:

      client:

        registration:

          catalog:

            authorization-grant-type: client_credentials

            client-id: catalog

            client-secret: ${CATALOG_CLIENT_SECRET}

        provider:

          catalog:

            token-uri: https://localhost:8443/oauth/token

Broadleaf ships seed data that registers a client in AuthenticationServices for every out-of-the-box microservice that calls another, with secrets stored as BCrypt hashes. A client for a custom integration takes the same handful of properties plus a registration record. The Broadleaf Initializr can also help define and register these values.

Multi-tenant context

Context is explicit. Tenant, sandbox, application, and catalog context travel in the X-Context-Request header on API calls, whether the caller is a browser or another microservice. The receiving service can inspect and validate what the caller supplied, while what the caller is entitled to reach travels separately in the access token's claims. The requested context is checked against those claims.

Enforcement happens in Broadleaf's policy layer, after Spring Security validates the token. The @Policy annotation on endpoints and repository methods declares what is required, and the engine checks four things:

  • Visibility: is the entity in a tenant, application, catalog, and sandbox the caller can see?
  • Permission: does the caller hold the right operation on the right resource, such as READ_PRODUCT or UPDATE_PRODUCT?
  • Ownership: for customer-owned resources like carts and orders, do the token claims identify the caller as the owner?
  • Mutability: can this entity be modified in the caller's current context at all?

Visibility failures return HTTP 404 instead of 403. An unauthorized caller gets no error code to map what exists in another tenant.

Admin users and customers

Broadleaf keeps admin users and customer users separate at the data level, and the two gateways are configured so APIs aren't needlessly exposed to the wrong front end. Admin users get roles that map to commerce operations. Customers get only what a shopping experience needs: a customer can read products and never update them.

Both can use first-party Universal Login or third-party OIDC login. Managing admin users in an external provider is optional, and you choose whether roles live in Broadleaf or with the provider. When the provider owns them, roles come from the ID token's blc_roles claim and map through external role mapping records. Roles assigned that way are read-only inside Broadleaf.

Session security when there is no session

Stateless tokens change the threat model. There is no server-side session object to steal, and access tokens are short-lived and narrowly scoped. In exchange, anyone holding a valid JWT can use it until it expires, and refresh token compromise becomes its own attack path.

All traffic runs over TLS. Session cookies are HttpOnly and Secure, with SameSite settings and CSRF protection. Refresh tokens are optional, and when you use them, rotation is on by default with a 60-second rotation interval: if a refresh token is reused outside that window, Broadleaf logs a security violation and invalidates the whole authorization lineage, which cuts off an attacker replaying a stolen token.

The limit worth knowing about

Stateless tokens buy independent validation, and the price is revocation. By default, an access token is valid until it expires. Each service checks the signature and expiry locally and consults no central list, because checking one on every call is the round trip signed tokens exist to avoid.

Since 3.0.0, Broadleaf offers an opt-in answer. Session token blacklisting in AuthenticationServices invalidates a session's whole lineage of session tokens when the user logs out or logs in again. For access tokens, an optional gateway filter checks each incoming token against a shared blacklist, backed by Redis in production, before routing the request. Both are opt-in and off by default, and you can use session token blacklisting without the access token half. If the blacklist store times out or its circuit breaker trips, the gateway lets the request through and signature and expiry validation still apply.

Even with the filter on, access token lifetime sets your worst case when the blacklist can't answer. Shortening the lifetime costs a few extra refresh calls. If your compliance posture requires a session to die the instant someone logs out, raise it early, because it shapes a deployment.

Questions to ask any commerce platform

These questions separate a considered security model from a checklist:

  1. Where does authentication happen, and which component validates tokens on each request?
  2. How is tenant context passed between services, and who can forge it?
  3. When a user lacks access to a record, does the error reveal that it exists?
  4. How wide is your token revocation gap, and what is it configured to by default?

The Bottom Line

Microservices security is complex, and no platform removes that. Broadleaf's answer is mostly Spring best practice, and that is the point: a dedicated authentication service built on Spring's authorization server, a commerce-shaped policy model, pre-registered service clients, explicit tenant scoping, and identity provider integration for admin and storefront, already working together.

Want the configuration detail? The developer documentation covers it in depth, or talk to our architecture team about your security and compliance requirements.