Quarkus turns agent security advice into Java enforcement points
A live-coding session maps prompt injection, broken authorization and excessive agency to OIDC, tool boundaries, ordered guardrails and deterministic tests.
Quarkus has followed its broad agent-security guidance with a code-level walkthrough for LangChain4j applications. The session and companion workshop start from four failure classes—prompt injection, broken authorization, excessive agency and sensitive-information disclosure—and place controls in the application path rather than relying on the model’s system prompt.
That makes this distinct from Red Hat’s earlier enterprise roundtable. The roundtable argued for human approvals, audit trails and sandboxed execution as operating policy. This Quarkus material shows where Java developers can enforce narrower permissions and validate model traffic inside an application.
Carry identity to the action
The authentication step adds the Quarkus OIDC extension and configures a hybrid application so the same service can accept browser code-flow sessions and bearer tokens. The example protects every HTTP path, while also showing @Authenticated and @RolesAllowed as endpoint-level alternatives.
The important implementation choice is to inject Quarkus SecurityIdentity into the application rather than treating login as a front-door check. That identity can travel with the request to the point where a tool or API decision is made. It is the concrete answer to broken authorization: a model deciding to call a function does not grant the caller permission to perform it.
Make tools explicit and guardrails ordered
The workshop registers an external location lookup as a LangChain4j @Tool and exposes it to the AI service through @ToolBox. That small example makes the agency boundary visible in code: the model can choose among only the capabilities developers register, while the underlying REST client remains an ordinary Quarkus integration where authentication, authorization and logging can be applied.
Input and output controls are separate. A configurable MaxLength input guardrail counts Unicode code points and returns a fatal result before the model is called when the request exceeds its budget. An AllowedLocationsGuardrail checks the generated answer against an application allowlist and reprompts when the output does not contain an approved value.
The workshop recommends one rule per guardrail and emphasizes ordering: the first fatal failure stops the chain, so cheap and likely rejection paths should run early. That is a more testable design than one large prompt that asks the model to police itself.
Test policy without paying for inference
The final step adds LangChain4j’s test helpers and exercises guardrails as deterministic Java functions. Tests assert success, reprompt and fatal outcomes in milliseconds without contacting an LLM. Teams can therefore put input budgets and output-policy checks in ordinary CI, reserving model-based scoring for cases where semantic comparison is actually needed.
The result is defense in depth rather than a complete agent sandbox. Quarkus supplies identity, endpoint policy, explicit tool registration, ordered validation and observable integration points; runtime isolation and human approval still belong around consequential actions. The practical shift is that those controls now have named Java enforcement points developers can review and test.
sources
comments · 0