How Can I get the SecurityContext of Spring Boot inside Zeebe Worker

Hello All,

I am using Zeebe Worker to update a table, however this table consists of Audit Columns which include createdBy and updatedBy. I am calling my repository inside the Zeebe Worker to save details, however inside the AuditAware class I would get SecurityContext as null, since the worker doesn’t know the security Context. So the question is, Is it a good practice to update application table via a Zeebe Worker? If Yes, How do i get the security Context?

I haave the same need.

Hey @satyaram413 and also @Leonardo_Muniz welcome to the forum.

The SecurityContext usually depends on the scope where a request happens (for example a WebRequest). As the zeebe worker is executing jobs independent from a WebRequest it doesnt have any security context attached to it. If you want to store the worker name in the audit record or pass information from the job context into the audit log via the SecurityContext you would have to construct it and pass the authentication object yourself via SecurityContextHolder (spring-security-docs 6.1.5 API)