Course contentsShow
← Software Engineering
Lesson 1030 of 1,93331. Authentication and AuthorizationFree lesson

Implementing Authorization in Applications

Learn where to enforce authorization: at API gateways, application layer, or database level, and consistency patterns.

Implementing Authorization in Applications

You'll learn where to enforce authorization checks in your system architecture and why consistency matters.

Authorization isn't a single checkpoint—it's a layered defense that must be enforced at multiple boundaries. The question isn't just whether to check permissions, but where and how consistently to apply them.

Enforcement Layers

API Gateway/Edge Layer: The first line of defense. Gateways can reject requests before they reach your application—blocking unauthorized traffic early, preventing wasted compute, and enabling coarse-grained checks (like verifying valid tokens or checking rate limits).

Application/Business Logic Layer: This is where fine-grained authorization lives. Here you enforce resource-specific rules: "Can this user edit this document?" or "Does this role allow invoice approval?" Your application understands context—user relationships, data ownership, and business rules—that outer layers cannot.

Database Layer: The last resort. Some databases support row-level security or view-based restrictions. This protects against bugs or compromised application code, but shouldn't be your primary authorization mechanism—it's slow and hard to express complex rules in SQL.

The Consistency Challenge

Authorization must be consistent across all paths to the same resource. If your REST API checks permissions but your GraphQL endpoint doesn't, you've created a vulnerability. If background jobs bypass authorization, you've opened a backdoor.

Think of it like building security: locks on the front door are useless if the back door is wide open.

The Pattern

Defense in Depth: Use multiple layers. Gateway blocks obviously bad requests. Application enforces business rules. Database acts as a safety net. Each layer protects against different failure modes—network attacks, application bugs, and privilege escalation.

Single Source of Truth: Centralize authorization logic in a reusable module, not scattered across controllers. This ensures consistency and makes policy updates manageable.

Key Takeaway: Authorization must be enforced at the application layer where business context exists, with API gateways providing coarse filtering and databases as a safety net—consistency across all access paths is non-negotiable.