Control usernameParameter for UserDetailsService
This commit is contained in:
@@ -4,6 +4,7 @@ import demo.api.jwt.dtos.TokenDto;
|
|||||||
import demo.api.user.domain.User;
|
import demo.api.user.domain.User;
|
||||||
import demo.api.user.dtos.UserSignInRequest;
|
import demo.api.user.dtos.UserSignInRequest;
|
||||||
import demo.api.user.dtos.UserSignUpRequest;
|
import demo.api.user.dtos.UserSignUpRequest;
|
||||||
|
import java.util.Objects;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -29,7 +30,7 @@ public class AuthController {
|
|||||||
public String signUp(@Validated UserSignUpRequest signUpReq) throws Exception {
|
public String signUp(@Validated UserSignUpRequest signUpReq) throws Exception {
|
||||||
User user = authService.signUp(signUpReq);
|
User user = authService.signUp(signUpReq);
|
||||||
|
|
||||||
if(user.getEmail() != "") {
|
if(!Objects.isNull(user)) {
|
||||||
return "redirect:/user/signIn";
|
return "redirect:/user/signIn";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class SecurityConfig {
|
|||||||
.csrf().disable()
|
.csrf().disable()
|
||||||
.formLogin()
|
.formLogin()
|
||||||
.loginPage("/auth/signIn")
|
.loginPage("/auth/signIn")
|
||||||
|
.usernameParameter("email")
|
||||||
.defaultSuccessUrl("/")
|
.defaultSuccessUrl("/")
|
||||||
.failureUrl("/auth/signIn?fail=true");
|
.failureUrl("/auth/signIn?fail=true");
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String email) throws UserNotFoundException {
|
public UserDetails loadUserByUsername(String email) throws UserNotFoundException {
|
||||||
|
System.out.println("email in loadUserByUsername = " + email);
|
||||||
User user = userRepository.findByEmail(email)
|
User user = userRepository.findByEmail(email)
|
||||||
.orElseThrow(UserNotFoundException::new);
|
.orElseThrow(UserNotFoundException::new);
|
||||||
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class JwtTokenFilter extends OncePerRequestFilter {
|
|||||||
SecurityContextHolder.getContext().setAuthentication(auth); // 정상 토큰이면 SecurityContext에 저장
|
SecurityContextHolder.getContext().setAuthentication(auth); // 정상 토큰이면 SecurityContext에 저장
|
||||||
}
|
}
|
||||||
} catch (CustomException ex) {
|
} catch (CustomException ex) {
|
||||||
//this is very important, since it guarantees the user is not authenticated at all
|
|
||||||
SecurityContextHolder.clearContext();
|
SecurityContextHolder.clearContext();
|
||||||
response.sendError(ex.getHttpStatus().value(), ex.getMessage());
|
response.sendError(ex.getHttpStatus().value(), ex.getMessage());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class UserController {
|
|||||||
|
|
||||||
@GetMapping("/profile")
|
@GetMapping("/profile")
|
||||||
public String profile(Model model, @AuthenticationPrincipal UserDetails userDetails) {
|
public String profile(Model model, @AuthenticationPrincipal UserDetails userDetails) {
|
||||||
|
System.out.println("userDetails = " + userDetails);
|
||||||
if (userDetails != null) {
|
if (userDetails != null) {
|
||||||
User userDetail = userService.findByEmail(userDetails.getUsername())
|
User userDetail = userService.findByEmail(userDetails.getUsername())
|
||||||
.orElseThrow(() -> new UserNotFoundException());
|
.orElseThrow(() -> new UserNotFoundException());
|
||||||
|
|||||||
Reference in New Issue
Block a user