I have a Spring Service layer that is secured with @PreAuthorize annotation. So far this has been used through a web application. Now I need to enable our SpringBatch jobs to use these services.
What’s the most straight-forward way to enable jobs to authorize them before calling these service methods?
I had the same problem, here is what I did to solve it :
In my tasklet, I called this method :
Here is the definition of my authenticateAs method written in my SecurityUtility class injected in my tasklet, implementing ApplicationContextAware :
It works well, let me know if you need more details 😉