There is a servlet written using Spring. The method runs in time as CRON (also uses Spring Scheduler). Is it possible in this method to create a session with a specific user, to create a stream with a context configured for this user with access to the database, and then for the Cron task to work in this context? Well, it’s as if the user has connected and that’s all for him.

  • Yes exactly. I tried to run, but it seems that it does not create its context. Now I will try again and write more precisely. - Helena2977
  • Well, yes, the user context is missing, and so everything falls out when trying to access it. - Helena2977
  • Unfortunately, I do not know that in this case "user context". - KoVadim
  • What specific data is needed from the context? If you mean the context of Spring Security, which stores the current user, then his hands can be set. - iksuy
  • Yes, this is exactly what is needed. And how his hands, he is taken from the request? - Helena2977

1 answer 1

Send the correct username and password to connect to the database. This will solve 90% of the problem.
If you use any specific client that is tied to the user's environment, look in its settings for the ability to transfer this very environment.
If he is so poor and is written crookedly, then the writing of the PATH environment variable with the correct paths usually helps. Cron also allows you to set the user name from which the client is running.

Example cron file:

PATH=/home/pupkin/.program_config:$PATH # mh dom mon dow user command 17 * * * * pupkin cd / && ./super_proga 

In some cases, the environment is configured in .bash_rc. In this case, simply load it when you run the task. Somewhere like this:

 17 * * * * pupkin source /home/pupkin/.bash_rc && cd / && ./super_proga 
  • Ox, incorrectly worded. Speech about servlet goes. It has a piece that runs as CRON. The servlet is written using Spring, and everything is tied to the user context. - Helena2977
  • like crowns or with a krone? - KoVadim
  • What do you mean? - Helena2977
  • What's the Difference? - Helena2977
  • from under the crown - this is from under the crown - that is, an entry is added to the crontab file. Like crowns - this is a simulation of a crown with some kind of left utility / package. To be honest, I do not understand how you are going to run the servlet. - KoVadim