Spring data jpa - changing a request before executing

I am working on a project that stores some access control information in a database. We use this access control information to filter what the user can see. The filter we use is based on the roles that the user has. We would like to use the repository abstraction provided by Spring Data, but we would like to be able to customize the generated queries before executing them. Is there a way to connect a listener or interceptor that will be called before the request is executed? Thus, we can get a link to the request object and make any changes to the request that we need before the request is completed.

What we're going to do is create our own JpaRepositoryFactoryBean so that we can override SimpleJpaRepository, as described here . We would redefine SimpleJpaRepository.getQuery to make adjustments to the query. Then, for all the generated search methods, we thought about extending PartTreeJpaQuery and overriding PartTreeJpaQuery $ QueryPreparer. In QueryPreparer, we will override the QueryPreparer.createQuery methods. We were not sure that this is the easiest way to access all the requests before they are completed.

We thought about adding org.springframework.data.repository.core.support.QueryCreationListener, but it will only execute when the request is created. I think we need something more dynamic.

+4
source share
1 answer

I'm not sure what you already know, but Spring Data Team is working on this feature for the next version so Spring Security team can add ACL support.

Add infrastructure for an overall increase in requests

Spring Security Issue That Locked Previous: Spring Security / Spring Acl Data Integration

JpaRepositoryFactoryBean, , ACL, findAll findOne, Spring Data , , . , , , Spring Security/Data.

1 . ?

+1

Source: https://habr.com/ru/post/1533903/


All Articles