Является ли аннотированный метод @Scheduled вне какого-либо SecurityContext? Когда я пытаюсь использовать следующее, значение Securitycontext/auth всегда равно нулю. Если это невозможно, то как правильно запустить запланированное задание с учетом аутентификации конкретного пользователя?
@Scheduled(fixedDelay = 10000)
// This method will send notifications to the current user
public void sendUserNotifications() {
SecurityContext sc = SecurityContextHolder.getContext();
Authentication auth = sc.getAuthentication();
if(auth == null) {
log.info(">> SecurityContext=[{}], Authentication[auth] is {}, please login to receive notifications", sc, auth);
return;
}