Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Your teams mix URL-based rules, @PreAuthorize annotations and manual checks in code, and audits cannot tell which endpoints are protected by what. What authorization standards would you set?

I would set a small number of standards and make tooling enforce them. Every service is deny-by-default at the URL level and every endpoint must declare an explicit rule; URL rules handle coarse access while method or domain checks handle object-level rules, with the split written down; a generated inventory shows each endpoint with its effective rules for auditors; teams use shared authorization beans and meta-annotations instead of copied SpEL strings; and authorization tests for each new endpoint are part of the definition of done.

Why this question is asked

Mixed authorization styles are normal in a company that grew quickly. One team protects everything with URL patterns, another annotates services, a third writes if (!user.isAdmin()) inside controllers. Each works on its own, but when an auditor asks which rule protects the refund endpoint, nobody can answer without reading code, and gaps hide in the seams. Interviewers ask this question to see whether we can set standards that improve security without freezing delivery. In this answer, we will look at why the mixture is risky, define deny-by-default, write down the split of responsibilities, build an endpoint inventory, replace copied expressions with shared building blocks, and make tests part of done.

1Why the Mixture Is a Problem

Each style on its own is reasonable. The risk comes from combining them without rules. A URL rule may assume a service check exists; the service author may assume the URL rule covers it; neither exists for a new endpoint added under a different path. Manual checks in code are the hardest to audit, because a search for annotations or rules does not find them, and they are easy to forget in one of several code paths.

So the goal is not to pick one mechanism for everything. It is to make every endpoint's protection explicit, findable and tested, and to make the missing case fail closed.

2Standard 1: Deny by Default, Explicit Everywhere

Every SecurityFilterChain ends in denyAll() for APIs, or authenticated() for ordinary web applications. On top of that, every controller method must carry an explicit authorization declaration, even if it is permitAll() for a public endpoint. Public must be a decision someone wrote down, not the result of forgetting.

The platform team ships this as a shared Spring Boot starter with a base security configuration, so teams get the default by adding a dependency instead of copying a configuration class and editing it.

3Standard 2: A Written Split of Responsibilities

Without a clear split, teams duplicate checks or skip them. We write a one-page standard that says where each kind of rule lives.

Where each authorization rule belongs
Rule typeExampleMechanism
Authentication requiredany /api/** callURL rule in the filter chain
Scope or broad roleSCOPE_orders.read, ROLE_STAFFURL rule in the filter chain
Object-level ownershiponly the invoice's customerMethod security or domain service
Tenant isolationonly rows of my tenantData access layer filter
Business state rulesrefund only within 30 daysDomain code, tested as logic
Manual checks in controllers are not on the list; they move into one of these places.

Notice that object-level rules have one home, method security or a domain service, not the controller. Controllers stay thin, which also means a second entry point, such as a message listener calling the same service, inherits the same protection automatically.

4Standard 3: An Inventory Generated From the Code

Auditors need a list of endpoints and their effective rules, and a hand-written list is out of date within a week. So we generate it. Spring MVC already knows every endpoint through RequestMappingHandlerMapping, and each handler method can be inspected for authorization annotations. A test can both produce the inventory and fail the build when an endpoint has no declaration.

Java
@SpringBootTest
class EndpointAuthorizationInventoryTest {
@Autowired RequestMappingHandlerMapping mappings;
@Test
void everyEndpointDeclaresAuthorization() {
List<String> missing = new ArrayList<>();
mappings.getHandlerMethods().forEach((info, method) -> {
boolean declared = AnnotatedElementUtils.hasAnnotation(method.getMethod(), PreAuthorize.class)
|| AnnotatedElementUtils.hasAnnotation(method.getBeanType(), PreAuthorize.class)
|| AnnotatedElementUtils.hasAnnotation(method.getMethod(), PublicEndpoint.class);
String line = info + " -> " + (declared ? describe(method) : "NONE");
inventory.add(line); // written to build/authz-inventory.txt for audit
if (!declared) missing.add(line);
});
assertThat(missing).isEmpty(); // fails: "{GET [/api/refunds/{id}]} -> NONE"
}
}

Notice that AnnotatedElementUtils also finds meta-annotations, which matters for the next standard. The generated file becomes the audit evidence: it is versioned with the code and always matches what is deployed. Teams using URL rules for coarse checks can extend the report by running each endpoint through the chain in a test with a few typical users and recording the result.

5Standard 4: Shared Building Blocks Instead of Copied SpEL

Copied strings such as @PreAuthorize("hasRole('ADMIN') or hasRole('FINANCE')") drift. One copy gets a new role, another does not, and a typo in a string is only found at runtime. We replace them with named annotations and beans that express business meaning.

Java
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("@invoiceAccess.canRead(authentication, #invoiceId)")
public @interface CanReadInvoice { }
@Component("invoiceAccess")
class InvoiceAccess {
boolean canRead(Authentication auth, long invoiceId) { ... } // plain Java, unit tested
}
@CanReadInvoice
public Invoice get(long invoiceId) { ... } // readable, searchable, one definition

Spring Security supports @PreAuthorize as a meta-annotation, and recent versions also support templated meta-annotations with placeholders, so @HasScope("orders.read") can be built once; the bean that enables templates was renamed between 6.x versions, so check your version. A search for @CanReadInvoice now finds every use, and the rule changes in one place.

6Standard 5: Tests in the Definition of Done

An endpoint is not done until it has authorization tests: one proving an allowed user succeeds and at least one proving a user who should be refused gets a 403 or 404, including a user from another tenant where that applies. The shared starter provides test helpers so this takes minutes. Code review checklists ask for these tests by name, and the inventory test above makes the declaration impossible to skip.

To roll this out without stopping delivery, we apply it to new endpoints immediately, generate the inventory for existing ones, and give teams a quarter to clear their NONE lines, highest-risk services first. Reporting the count of undeclared endpoints per team each sprint turns a vague standard into visible progress.

7Follow-up questions

Do you ban manual checks in code completely?

No. Business rules like refunds only within 30 days are legitimately domain logic. What we ban is authorization scattered in controllers. Such rules move into a domain service or an authorization bean with its own tests, so they are findable and reused by every entry point.

How do you handle endpoints that are intentionally public?

With an explicit marker, such as a @PublicEndpoint annotation backed by a permitAll() rule, which the inventory test accepts and the report lists separately. Security reviewers can then look at the public list on its own, which is usually short.

Is a central policy engine better than these standards?

It can be for complex shared rules, but it does not remove the need for these standards. Endpoints still need explicit enforcement points, an inventory and tests; the policy engine only changes where the decision logic lives.

8Conclusion

In this answer, we turned a mixture of URL rules, annotations and manual checks into a set of standards: deny-by-default with explicit declarations for every endpoint, a written split between coarse URL rules and object-level checks, an inventory generated from the code that also fails the build, shared meta-annotations and authorization beans instead of copied SpEL, and authorization tests as part of the definition of done, rolled out new endpoints first.

What to say in the interviewAbout 80 seconds aloud

Open with

I would not force one mechanism for everything; I would make every endpoint's protection explicit, findable and tested. First, deny-by-default: a shared Boot starter gives every service a filter chain ending in denyAll or authenticated, and every endpoint must declare a rule, even public ones with an explicit marker.

Then, if they want more

Second, a short written standard for the split: URL rules for authentication and scopes or broad roles, method security or domain services for object-level rules like ownership, the data layer for tenant isolation, and no authorization logic in controllers.

Third, an inventory generated from code: a test walks RequestMappingHandlerMapping, records each endpoint with its effective rule into a file auditors can use, and fails the build for any endpoint without a declaration. Fourth, reusable building blocks: meta-annotations like @CanReadInvoice backed by authorization beans with plain Java logic and unit tests, instead of SpEL strings copied across services.

Fifth, the definition of done requires authorization tests per endpoint, including a refused user and a user from another tenant. I would apply this to new endpoints immediately and give teams a quarter to clear existing gaps, reporting the count per team so progress is visible.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your teams mix URL-based rules, @PreAuthorize annotations and manual checks in code, and...": https://scrivio-interview-library.netlify.app/spring-boot/authorization/b6521f14f3/