Skip to content
ALTRONIXSOFTWARE — home
AI · Retrieval

Permission-aware RAG assistant

A company document assistant that answers each person only from the documents they may read, with sources cited.

Commercial project under NDA

Document-level access control enforced inside the vector search.

Spring Boot serviceAliceHR · all-staffBobEngineeringKeycloaklogin · PKCE · JWTOAuth2 resource servervalidates the JWT, reads groupsACL-filtered searchgroups → filter in the pgvector queryLLM answerpermitted chunks onlyPostgreSQL + pgvectordocuments · ACL · vectorsUploadowner from the tokenAnswercited from retrieved textAlice (HR) → answer with sourcesBob → hidden (404) → no informationSpring Boot serviceAliceBobKeycloakOAuth2 resource servervalidates the JWT, reads groupsACL-filtered searchfilter in the SQL querypgvectorLLM answerpermitted chunks onlyUploadAnswercited from retrieved textAlice (HR) → answer with sourcesBob → hidden (404) → no information
  • 4access paths covered by tests
  • 1SQL query for search and access filter
  • 404for documents you may not read
  • 2identity providers: Keycloak, Entra ID
Technologies and integrations
  • Java 25
  • Spring Boot 4.1
  • Spring AI 2.0
  • PostgreSQL + pgvector
  • Spring Security
  • Keycloak
  • Apache Tika
  • Next.js

Challenge

Employees ask questions about internal documents, but not everyone may read everything. A regular RAG chatbot can leak a document through its answer, however the question is phrased. The assistant had to answer each person only from the documents they are entitled to.

How it works

The same question about a salary band gets different answers: an HR employee receives it with the source cited, while an engineer is told there is no information, and their document list does not even show that the document exists.

Key areas of work

A RAG service was implemented with need-to-know access controls: access is checked before the language model runs. The work covered six areas.

  1. 01

    Upload and ingestion

    Users upload PDF, DOCX, Markdown and text files.

    Apache Tika reads them, each chunk is stored with its owner and group list, and a document can only be shared with the uploader's own groups.

  2. 02

    Access from the token

    The user is identified by a signed JWT from Keycloak or Microsoft Entra ID.

    Access rights come only from the token, never from request parameters.

  3. 03

    Filtered retrieval

    The access filter runs inside the pgvector similarity search, in the same SQL query.

    By design, forbidden chunks do not reach the model, the answer or the citations.

  4. 04

    Answers with citations

    The model answers from the permitted chunks.

    The citations are built from the chunks actually retrieved, never from what the model writes.

  5. 05

    Hidden documents, untrusted text

    A document the user may not read returns 404, so its existence is not revealed.

    Retrieved text and model output are untrusted: an instruction hidden in a document cannot widen access.

  6. 06

    Tested and operated

    Access matrix tests check, over HTTP against a real pgvector database, that one user cannot reach another's documents through search, chat, GET or DELETE.

    Health checks, logging and timeouts cover operations.

Architecture and implementation details

Architecture

  1. 01

    Employees

    People ask questions and upload documents in a single-page web app served by the same service.

  2. 02

    Keycloak

    Users sign in through Keycloak (authorization code with PKCE) and receive a signed JWT; Microsoft Entra ID can replace it by profile. Groups and roles are read from the token.

  3. 03

    Spring Boot service

    One application with upload, search and chat endpoints; Spring Security acts as the OAuth2 resource server.

  4. 04

    Access-filtered search

    The access filter is a jsonpath predicate in the same SQL query as the vector similarity search.

  5. 05

    PostgreSQL and pgvector

    Documents, access lists and embeddings are stored in PostgreSQL to simplify consistency management.

  6. 06

    Model provider

    OpenAI, Azure OpenAI or a local model, chosen by Spring profile; business logic depends only on Spring AI abstractions.

Related service: AI integration and automation

Working on something similar?

Describe your system and the outcome you need, and we will suggest the next step.