From 30e6e0f198f59ecdf77f5d0b501e454015a3eb7b Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 27 May 2023 19:33:52 +0900 Subject: [PATCH] site user --- .../example/mindongjoon/sbb/security/SecurityConfig.java | 7 +++++++ .../example/mindongjoon/sbb/service/SiteUserService.java | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sbb/src/main/java/com/example/mindongjoon/sbb/security/SecurityConfig.java b/sbb/src/main/java/com/example/mindongjoon/sbb/security/SecurityConfig.java index 9b78096..dbf7c3a 100644 --- a/sbb/src/main/java/com/example/mindongjoon/sbb/security/SecurityConfig.java +++ b/sbb/src/main/java/com/example/mindongjoon/sbb/security/SecurityConfig.java @@ -4,6 +4,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @@ -20,4 +22,9 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception { } + @Bean + PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + } diff --git a/sbb/src/main/java/com/example/mindongjoon/sbb/service/SiteUserService.java b/sbb/src/main/java/com/example/mindongjoon/sbb/service/SiteUserService.java index e40f9c1..095813c 100644 --- a/sbb/src/main/java/com/example/mindongjoon/sbb/service/SiteUserService.java +++ b/sbb/src/main/java/com/example/mindongjoon/sbb/service/SiteUserService.java @@ -4,6 +4,7 @@ import com.example.mindongjoon.sbb.repository.SiteUserRepository; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @RequiredArgsConstructor @@ -11,12 +12,12 @@ public class SiteUserService { private final SiteUserRepository siteUserRepository; + private final PasswordEncoder passwordEncoder; public SiteUser create(String username, String email, String password) { SiteUser user = new SiteUser(); user.setUsername(username); user.setEmail(email); - BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); user.setPassword(passwordEncoder.encode(password)); this.siteUserRepository.save(user); return user;