File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed
src/main/java/com/helper/vavahelper Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1+ package com .helper .vavahelper .Config ;
2+
3+ import org .springframework .boot .CommandLineRunner ;
4+ import org .springframework .security .crypto .password .PasswordEncoder ;
5+ import org .springframework .stereotype .Component ;
6+
7+ import com .helper .vavahelper .Models .Role ;
8+ import com .helper .vavahelper .Models .User ;
9+ import com .helper .vavahelper .Repositories .UserRepository ;
10+
11+ @ Component
12+ public class AdminInitializerDSV implements CommandLineRunner {
13+
14+ private final UserRepository userRepository ;
15+ private final PasswordEncoder passwordEncoder ;
16+
17+ public AdminInitializerDSV (UserRepository userRepository , PasswordEncoder passwordEncoder ) {
18+ this .userRepository = userRepository ;
19+ this .passwordEncoder = passwordEncoder ;
20+ }
21+
22+ @ Override
23+ public void run (String ... args ) {
24+ if (userRepository .findByUsername ("admin" ).isEmpty ()) {
25+ User admin = new User ();
26+ admin .setUsername ("admin" );
27+ admin .setPassword (passwordEncoder .encode ("123" ));
28+ admin .setRole (Role .ROLE_ADMIN );
29+ userRepository .save (admin );
30+ System .out .println ("Usuário admin criado!" );
31+ }
32+ }
33+ }
34+
Original file line number Diff line number Diff line change 44
55import org .springframework .context .annotation .Bean ;
66import org .springframework .context .annotation .Configuration ;
7- import org .springframework .security .config .annotation .authentication .configuration .AuthenticationConfiguration ;
87import org .springframework .security .core .userdetails .UserDetailsService ;
98import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
109import org .springframework .security .crypto .password .PasswordEncoder ;
Original file line number Diff line number Diff line change 11package com .helper .vavahelper .Models ;
22
3- import com .helper .vavahelper .Models .Role ;
43import jakarta .persistence .*;
54import lombok .*;
65import java .time .LocalDateTime ;
You can’t perform that action at this time.
0 commit comments