diff --git a/src/main/java/io/hexlet/blog/component/DataInitializer.java b/src/main/java/io/hexlet/blog/component/DataInitializer.java index 6556880..4202a7d 100644 --- a/src/main/java/io/hexlet/blog/component/DataInitializer.java +++ b/src/main/java/io/hexlet/blog/component/DataInitializer.java @@ -33,7 +33,7 @@ public void run(ApplicationArguments args) throws Exception { var email = "hexlet@example.com"; var userData = new User(); userData.setEmail(email); - userData.setPassword("qwerty"); + userData.setPasswordDigest("qwerty"); userService.createUser(userData); var user = userRepository.findByEmail(email).get(); diff --git a/src/main/java/io/hexlet/blog/config/SecurityConfig.java b/src/main/java/io/hexlet/blog/config/SecurityConfig.java index ab96df7..3765083 100644 --- a/src/main/java/io/hexlet/blog/config/SecurityConfig.java +++ b/src/main/java/io/hexlet/blog/config/SecurityConfig.java @@ -18,17 +18,15 @@ import org.springframework.web.servlet.handler.HandlerMappingIntrospector; import io.hexlet.blog.service.CustomUserDetailsService; -import lombok.AllArgsConstructor; @Configuration @EnableWebSecurity -@AllArgsConstructor public class SecurityConfig { @Autowired - private final JwtDecoder jwtDecoder; + private JwtDecoder jwtDecoder; @Autowired - private final PasswordEncoder passwordEncoder; + private PasswordEncoder passwordEncoder; @Autowired private CustomUserDetailsService userService; diff --git a/src/main/java/io/hexlet/blog/controller/api/AuthenticationController.java b/src/main/java/io/hexlet/blog/controller/api/AuthenticationController.java index d4b18ef..d29dea8 100644 --- a/src/main/java/io/hexlet/blog/controller/api/AuthenticationController.java +++ b/src/main/java/io/hexlet/blog/controller/api/AuthenticationController.java @@ -23,11 +23,11 @@ public class AuthenticationController { @PostMapping("/login") public String create(@RequestBody AuthRequest authRequest) { var authentication = new UsernamePasswordAuthenticationToken( - authRequest.username(), authRequest.password()); + authRequest.getUsername(), authRequest.getPassword()); authenticationManager.authenticate(authentication); - var token = jwtUtils.generateToken(authRequest.username()); + var token = jwtUtils.generateToken(authRequest.getUsername()); return token; } } diff --git a/src/main/java/io/hexlet/blog/dto/AuthRequest.java b/src/main/java/io/hexlet/blog/dto/AuthRequest.java index d1f64cb..90a1a8d 100644 --- a/src/main/java/io/hexlet/blog/dto/AuthRequest.java +++ b/src/main/java/io/hexlet/blog/dto/AuthRequest.java @@ -1,4 +1,11 @@ package io.hexlet.blog.dto; -public record AuthRequest(String username, String password) { +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class AuthRequest { + private String username; + private String password; } diff --git a/src/main/java/io/hexlet/blog/model/User.java b/src/main/java/io/hexlet/blog/model/User.java index 5afd210..4c05398 100644 --- a/src/main/java/io/hexlet/blog/model/User.java +++ b/src/main/java/io/hexlet/blog/model/User.java @@ -60,8 +60,7 @@ public class User implements UserDetails, BaseEntity { @ToString.Include private String lastName; - @NotBlank - private String password; + private String passwordDigest; @LastModifiedDate private Date updatedAt; @@ -71,7 +70,7 @@ public class User implements UserDetails, BaseEntity { @Override public String getPassword() { - return password; + return passwordDigest; } @Override diff --git a/src/main/java/io/hexlet/blog/service/CustomUserDetailsService.java b/src/main/java/io/hexlet/blog/service/CustomUserDetailsService.java index 06fb434..077f456 100644 --- a/src/main/java/io/hexlet/blog/service/CustomUserDetailsService.java +++ b/src/main/java/io/hexlet/blog/service/CustomUserDetailsService.java @@ -30,8 +30,8 @@ public UserDetails loadUserByUsername(String email) throws UsernameNotFoundExcep public void createUser(UserDetails userData) { var user = new User(); user.setEmail(userData.getUsername()); - String hashedPassword = passwordEncoder.encode(userData.getPassword()); - user.setPassword(hashedPassword); + var hashedPassword = passwordEncoder.encode(userData.getPassword()); + user.setPasswordDigest(hashedPassword); userRepository.save(user); } diff --git a/src/main/java/io/hexlet/blog/util/JWTUtils.java b/src/main/java/io/hexlet/blog/util/JWTUtils.java index 95454c6..14ddf10 100644 --- a/src/main/java/io/hexlet/blog/util/JWTUtils.java +++ b/src/main/java/io/hexlet/blog/util/JWTUtils.java @@ -8,10 +8,8 @@ import org.springframework.security.oauth2.jwt.JwtEncoder; import org.springframework.security.oauth2.jwt.JwtEncoderParameters; import org.springframework.stereotype.Component; -import lombok.AllArgsConstructor; @Component -@AllArgsConstructor public class JWTUtils { @Autowired