liveBook · Manning

Spring Data repository

As explained in Spring Security in Action, Second Edition

A Spring Data repository is an interface-based abstraction that provides data-access operations for an underlying data store.

A Spring Data repository is an interface-based data-access abstraction for an underlying SQL or NoSQL store. In a filtering scenario, a repository method can retrieve records matching both a search term and the authenticated user. section 12.3

Apply repository-level filtering in two ways:

  • Use @PreFilter or @PostFilter; @PostFilter works but can retrieve every matching record before filtering, creating memory and performance risks. section 12.3
  • Put authorization conditions directly in the repository query so the data store returns only permitted records. section 12.3

Owner-filtered product search

A ProductRepository can search product names while restricting results to authentication.name. A request from nikolai returns candy; a request from julien returns chocolate. Replacing @PostFilter with a query condition avoids loading unauthorized products into application memory. section 12.3

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains annotations, query conditions, authentication integration, and performance consequences through a runnable product example.
Examples
Uses a Product entity, ProductRepository, MySQL table, sample products, REST requests, and owner-filtered JSON responses.
What it assumes
Assumes Spring Data and authenticated application users while demonstrating the required repository and security integration.
What you can do after
Implement repository-level filtering and diagnose why post-retrieval filtering can exhaust memory or reduce performance.
How it connects
Connects Spring Data repositories with Spring Security method security, authorization rules, queries, authentication, and database filtering.

Also explained in

Compare how 2 books explain Spring Data repository →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.