use of ua.springweb.security.repository.UserRepository in project Logos_Materials_October_2017 by VolodymyrZavada.
the class SpringBootSecurityWebAppApplication method addAdmin.
static void addAdmin(ConfigurableApplicationContext context) {
String email = "admin@gmail.com";
String password = "123";
UserRepository userRepository = context.getBean(UserRepository.class);
UserEntity entity = userRepository.findUserByEmail(email);
if (entity == null) {
PasswordEncoder passwordEncoder = context.getBean(PasswordEncoder.class);
entity = new UserEntity();
entity.setEmail(email);
entity.setPassword(passwordEncoder.encode(password));
entity.setRole(Role.ROLE_ADMIN);
userRepository.save(entity);
}
}
Aggregations