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.
source
share