3030import org .apache .fineract .infrastructure .core .service .tenant .TenantDetailsService ;
3131import org .apache .fineract .infrastructure .event .external .service .JdbcTemplateFactory ;
3232import org .apache .fineract .infrastructure .jobs .domain .JobExecutionRepository ;
33- import org .apache .fineract .infrastructure .jobs .service .jobname .JobNameProvider ;
33+ import org .apache .fineract .useradministration .domain .AppUser ;
34+ import org .apache .fineract .useradministration .domain .AppUserRepositoryWrapper ;
3435import org .springframework .batch .core .configuration .JobRegistry ;
3536import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
3637import org .springframework .context .ApplicationListener ;
3738import org .springframework .context .event .ContextRefreshedEvent ;
3839import org .springframework .jdbc .core .namedparam .NamedParameterJdbcTemplate ;
40+ import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
41+ import org .springframework .security .core .context .SecurityContextHolder ;
3942import org .springframework .stereotype .Service ;
4043
4144@ Service
@@ -46,10 +49,10 @@ public class StuckJobListener implements ApplicationListener<ContextRefreshedEve
4649 private final JobExecutionRepository jobExecutionRepository ;
4750 private final JdbcTemplateFactory jdbcTemplateFactory ;
4851 private final TenantDetailsService tenantDetailsService ;
49- private final JobNameProvider jobNameProvider ;
5052 private final JobRegistry jobRegistry ;
5153 private final BusinessDateReadPlatformService businessDateReadPlatformService ;
5254 private final StuckJobExecutorService stuckJobExecutorService ;
55+ private final AppUserRepositoryWrapper userRepository ;
5356
5457 @ Override
5558 public void onApplicationEvent (ContextRefreshedEvent event ) {
@@ -64,6 +67,10 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
6467 HashMap <BusinessDateType , LocalDate > businessDates = businessDateReadPlatformService .getBusinessDates ();
6568 ThreadLocalContextUtil .setActionContext (ActionContext .DEFAULT );
6669 ThreadLocalContextUtil .setBusinessDates (businessDates );
70+ AppUser user = userRepository .fetchSystemUser ();
71+ UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken (user , user .getPassword (),
72+ user .getAuthorities ());
73+ SecurityContextHolder .getContext ().setAuthentication (auth );
6774 stuckJobNames .forEach (stuckJobExecutorService ::resumeStuckJob );
6875 } catch (Exception e ) {
6976 throw new RuntimeException ("Error while trying to restart stuck jobs" , e );
0 commit comments