One policy model, two places to run it
Security, logging, tenancy and the other horizontal concerns are written once as interceptors. The same contract runs at the API gateway and inside each service, and the service registry decides where each policy applies.
Exchange
Payload
At the API gateway
Terminate authentication, coarse authorization, rate-limiting and request normalization at the edge — so bad traffic never reaches your services. Chenile ships an auth gateway and resource-server starters in chenile-security.
At the last mile
Fine-grained authorization, multi-tenancy, i18n, idempotency and business-aware logging run inside each service's interception pipeline — where the domain context actually exists. Same interceptor contract, different deployment.
New policy data needs no framework change
A policy is two things: the data that configures it, and the interceptor that enforces it. Chenile already knows how to carry the data. Write an annotation for it, mark that annotation with @ChenileAnnotation, and Chenile records it for every operation or service that uses it. @SecurityConfig works exactly this way.
// 1. The policy's data: any annotation, marked @ChenileAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@ChenileAnnotation
public @interface AuditTrail {
String category();
}
// 2. Use it on an operation (or on the controller, for every operation)
@PostMapping("/order/{id}/approve")
@AuditTrail(category = "orders")
@InterceptedBy("auditTrailInterceptor")
public ResponseEntity<GenericResponse<Order>> approve(…) { … }
// 3. The interceptor reads it from the exchange
public class AuditTrailInterceptor extends BaseChenileInterceptor {
@Override
protected void doPostProcessing(ChenileExchange exchange) {
AuditTrail audit = getExtensionByAnnotation(AuditTrail.class, exchange);
if (audit == null) return; // this operation is not audited
// record audit.category(), the user and the outcome
}
}What Chenile does with it
At startup, Chenile scans each controller and each operation for annotations whose type carries @ChenileAnnotation, and stores them in the service and operation definitions it keeps in ChenileConfiguration, its registry of everything the deployable serves. Each one is kept twice: as the annotation itself, and as a map of its attributes under the annotation's simple name.
How an interceptor finds it
exchange.getExtensionByAnnotation(AuditTrail.class) (or the same helper on BaseChenileInterceptor) returns the operation's annotation, falling back to the one on the controller, so an operation can override a service-wide setting. No change to chenile-core, no registration code, no new model class.
Then decide where it runs
Attach the interceptor to an operation with @InterceptedBy (or interceptorComponentNames on a service or operation in a JSON service definition), or to every service in the deployable with chenile.pre.processors / chenile.post.processors. Where an operation has no annotation, the interceptor returns early, as in the example.
Policies that must act before traffic reaches the service, such as rate limits, belong at the edge instead; publishing their data to the service registry for that is planned.