Create InitialSetup.java
This commit is contained in:
parent
e791fee38b
commit
d75e84bdff
1 changed files with 27 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
||||||
|
package stirling.software.SPDF.config.security;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import stirling.software.SPDF.model.Role;
|
||||||
|
@Component
|
||||||
|
public class InitialSetup {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
if(!userService.hasUsers()) {
|
||||||
|
String initialUsername = System.getenv("INITIAL_USERNAME");
|
||||||
|
String initialPassword = System.getenv("INITIAL_PASSWORD");
|
||||||
|
if(initialUsername != null && initialPassword != null) {
|
||||||
|
userService.saveUser(initialUsername, initialPassword, Role.ADMIN);
|
||||||
|
} else {
|
||||||
|
userService.saveUser("admin", "password", Role.ADMIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue