77import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
88import jakarta .servlet .http .HttpServletRequest ;
99import jakarta .servlet .http .HttpServletResponse ;
10+ import jakarta .validation .Valid ;
1011import org .slf4j .Logger ;
1112import org .slf4j .LoggerFactory ;
1213import org .springframework .beans .factory .annotation .Autowired ;
1314import org .springframework .http .HttpStatus ;
1415import org .springframework .http .ResponseEntity ;
15- import org .springframework .security .core .userdetails .UserDetails ;
1616import org .springframework .web .bind .annotation .PostMapping ;
1717import org .springframework .web .bind .annotation .RequestBody ;
1818import org .springframework .web .bind .annotation .RequestMapping ;
@@ -44,7 +44,7 @@ public AuthenticationController(
4444 description = "User logged in successfully"
4545 )
4646 public ResponseEntity <?> login (
47- @ RequestBody final LoginRequest loginRequest ,
47+ @ Valid @ RequestBody final LoginRequest loginRequest ,
4848 final HttpServletResponse response ) {
4949 String email = authenticationService .login (loginRequest , response );
5050 LOGGER .info ("User {} logged in" , email );
@@ -63,7 +63,7 @@ public ResponseEntity<?> login(
6363 description = "User registered successfully"
6464 )
6565 public ResponseEntity <?> registerUser (
66- @ RequestBody final SignupRequest signupRequest ) {
66+ @ Valid @ RequestBody final SignupRequest signupRequest ) {
6767 authenticationService .registerAccount (signupRequest );
6868 LOGGER .info ("User {} registered" , signupRequest .getEmail ());
6969 return new ResponseEntity <>("Account registered." ,
@@ -113,9 +113,8 @@ public ResponseEntity<?> refreshToken(
113113 responseCode = "200" ,
114114 description = "User details fetched successfully"
115115 )
116- public UserDetails getCurrentUser () {
117- UserDetails userDetails = authenticationService .getCurrentUserDetails ();
118- LOGGER .info ("Fetched details for user {}" , userDetails .getUsername ());
119- return userDetails ;
116+ public void addUserDetailsInHeader (final HttpServletResponse response ) {
117+ authenticationService .addUserDetailsInHeader (response );
118+ LOGGER .info ("Fetching current user details and adding to header" );
120119 }
121120}
0 commit comments