#9 admin-password #10

Merged
romanov73 merged 1 commits from 9-admin-password into master 2022-03-18 11:39:58 +04:00
3 changed files with 4 additions and 1 deletions

Binary file not shown.

View File

@ -2,6 +2,7 @@ package ru.ulstu.user;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
@ -24,6 +25,8 @@ public class UserService implements UserDetailsService {
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
private final UserRepository userRepository; private final UserRepository userRepository;
private final UserRoleRepository userRoleRepository; private final UserRoleRepository userRoleRepository;
@Value("${admin-password}")
private String adminPassword;
public UserService(PasswordEncoder passwordEncoder, public UserService(PasswordEncoder passwordEncoder,
UserRepository userRepository, UserRepository userRepository,
@ -63,7 +66,6 @@ public class UserService implements UserDetailsService {
public void initDefaultAdmin() { public void initDefaultAdmin() {
String adminLogin = "admin"; String adminLogin = "admin";
String adminPassword = "adminadmin";
if (getUserByLogin(adminLogin) == null) { if (getUserByLogin(adminLogin) == null) {
UserRole adminRole = userRoleRepository.save(new UserRole(UserRoleConstants.ADMIN)); UserRole adminRole = userRoleRepository.save(new UserRole(UserRoleConstants.ADMIN));
createUser(new User(adminLogin, adminPassword, Set.of(adminRole))); createUser(new User(adminLogin, adminPassword, Set.of(adminRole)));

View File

@ -3,6 +3,7 @@
# You may use, distribute and modify this code, please write to: romanov73@gmail.com. # You may use, distribute and modify this code, please write to: romanov73@gmail.com.
# #
# #
admin-password=admin
spring.main.banner-mode=off spring.main.banner-mode=off
logging.level.tech.athene=DEBUG logging.level.tech.athene=DEBUG
server.port=8080 server.port=8080