1 package fr.tiogars.domaintemplate.domains.auth.services;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.springframework.boot.ApplicationArguments;
6 import org.springframework.boot.ApplicationRunner;
7 import org.springframework.stereotype.Component;
8 import org.springframework.transaction.annotation.Transactional;
9
10 import fr.tiogars.domaintemplate.config.AdminAccountProperties;
11 import fr.tiogars.domaintemplate.domains.auth.role.services.RoleService;
12 import fr.tiogars.domaintemplate.domains.auth.user.services.UserService;
13
14
15 @Component
16 class AuthBootstrapRunner implements ApplicationRunner {
17
18 private static final Logger LOGGER = LoggerFactory.getLogger(AuthBootstrapRunner.class);
19
20 private final AdminAccountProperties adminAccountProperties;
21 private final RoleService roleService;
22 private final UserService userService;
23
24 AuthBootstrapRunner(AdminAccountProperties adminAccountProperties, RoleService roleService, UserService userService) {
25 this.adminAccountProperties = adminAccountProperties;
26 this.roleService = roleService;
27 this.userService = userService;
28 }
29
30 @Override
31 @Transactional
32 public void run(ApplicationArguments args) {
33 roleService.seedDefaultRoles();
34 userService.forceAdminUser(adminAccountProperties.username(), adminAccountProperties.password());
35 LOGGER.info("Forced administrator account '{}' is ready", adminAccountProperties.username());
36 }
37 }