Search in sources :

Example 1 with UserRepository

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);
    }
}
Also used : UserRepository(ua.springweb.security.repository.UserRepository) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UserEntity(ua.springweb.security.entity.UserEntity)

Aggregations

PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)1 UserEntity (ua.springweb.security.entity.UserEntity)1 UserRepository (ua.springweb.security.repository.UserRepository)1