drenda
drenda

Reputation: 6244

Spring repository vs Dao

I've a question about Spring. I've some repositories in my app (that extend JpaRepository) and I'm using that in my client (JavaFx) to transfer data. In every repository I've a @PreAuthorize("hasAnyRole('ROLE')") tag that prevents the client to invoke these method without an authentication.

Until here, all perfect, but I've a design question. Now I should invoke some methods that works on DB inside a task into my server. I can't call a method of the repository because otherwise I have an Exception due to the fact that the server can't login into itself.

So I read something about the difference between repositories and Dao, and I'm asking if the only way is to create a Dao without @PreAuthorize tag. I don't love very much this solution because in this way the code that interact with the db is two different places. So if you have CustomerRepository, then you have also to have CustomerDao.

Have you some better idea? Thanks!

Upvotes: 0

Views: 961

Answers (1)

Andres
Andres

Reputation: 10707

In order to invoke your repository methods from the server, you need a SecurityContext.

Here's how to create it:

http://www.petrikainulainen.net/programming/spring-framework/spring-from-the-trenches-invoking-a-secured-method-from-a-scheduled-job/

Upvotes: 3

Related Questions