Hello!
I guess you added annotation on the method that runs another thread. However you should setup authentication inside of run thread. In Jmix, depends on requirements you can use:
- Background Tasks :: Jmix Documentation
- Quartz :: Jmix Documentation
If you want to use TaskExecutor
, you can do the following to setup authentication:
@Component
public class UsersService {
private final TaskExecutor taskExecutor;
private final SystemAuthenticator systemAuthenticator;
private final DataManager dataManager;
//...
public void clearNotActiveUsers() {
taskExecutor.execute(() -> {
systemAuthenticator.runWithSystem(() -> {
List<User> users = dataManager.load(User.class).all().list();
// ...
});
});
}
}
You aslo can use UnconstrainedDataManager
that does not check authentication:
@Component
public class UsersService {
private final UnconstrainedDataManager unconstrainedDataManager;
// ...
public void clearNotActiveUsers() {
taskExecutor.execute(() -> {
List<User> users = unconstrainedDataManager.load(User.class).all().list();
// ...
});
}
}
Or configure the @Async
annotation in application class using @EnableAsync
(see Task Execution and Scheduling :: Spring Framework).
@Component
public class UsersService {
private final DataManager dataManager;
// ...
@Async
@Authenticated
public void clearNotActiveUsers() {
List<User> users = dataManager.load(User.class).all().list();
// ...
}
}