How it works · Service policies

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.

One service policy model at the gateway and the last mile A client calls an API. The API gateway validates the JWT, derives the tenant from the issuer and relays trusted claims as headers, or rejects the call with 401. Inside order-service the chenile-highway copies the headers into the context, the security interceptor checks the operation's @SecurityConfig authorities against the caller's and rejects with 403 if none match, the other policies run, and the business logic runs. The edge · API gateway The last mile · inside order-service ClientPOST …/approve chenile-security-gateway Spring Cloud Gateway validate JWT401 if missing or bad resolve tenantfrom the issuer relay claimsas x- headers HttpEntryPointan exchange copy headersvalidate-copy-headers security@SecurityConfig other policiestenancy · i18n · logging OrderServiceImplapprove(id) needs: order.approve caller has: … response, or the error where the request stopped
caller
view
Step 1

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.

Adding a policy

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.