Skip to content

Salem B. - #6

Open
Barboud wants to merge 3 commits into
HackYourAssignment:mainfrom
Barboud:main
Open

Barboud wants to merge 3 commits into
HackYourAssignment:mainfrom
Barboud:main

Conversation

@Barboud

@Barboud Barboud commented Jul 8, 2026

Copy link
Copy Markdown

Summary

Implemented JWT-based authentication using Spring Security.

Changes

  • SecurityConfig: filter chain, BCrypt (strength 12), stateless sessions.
  • /register, /login public; /logout, /profile protected.
  • AppUserDetailsService connects UserRepository to Spring Security.
  • JwtService generates and validates tokens.
  • JwtAuthenticationFilter checks the token on each request.
  • /logout is stateless.


public LoginResponse login(LoginRequest request) {
throw new UnsupportedOperationException("TODO: implement login");
Authentication authentication = authenticationManager.authenticate(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authenticationManager.authenticate() throws AuthenticationException if credentials are invalid. Make sure you're handling that somewhere (either here with a try-catch or globally with a @ControllerAdvice) so the user gets a clean 401 response instead of a 500.

throw new UnsupportedOperationException("TODO: implement registration");

String encodedPassword = passwordEncoder.encode(request.password());
User user = new User(UUID.randomUUID().toString(), request.username(), encodedPassword);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now if someone registers with an existing username, you'll likely get an unhandled database exception. Add a check:

if (userRepository.findByUsername(request.username()).isPresent()) {
    throw new ResponseStatusException(HttpStatus.CONFLICT, "Username already taken");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants