Class AuthController

java.lang.Object
me.josephsf.jobportaljosephsfeir.controller.AuthController

@CrossOrigin(origins="*", maxAge=3600L) @RestController @RequestMapping("/api/auth") public class AuthController extends Object
REST controller for handling authentication operations in the Job Portal system.

This controller provides endpoints for user authentication operations including user registration (signup) and login (signin). It manages JWT token generation for authenticated users and handles user role assignments during registration. The endpoints in this controller are publicly accessible without authentication.

Since:
2025-05-14
  • Constructor Details

    • AuthController

      public AuthController(org.springframework.security.authentication.AuthenticationManager authenticationManager, UserRepository userRepository, org.springframework.security.crypto.password.PasswordEncoder encoder, JwtUtils jwtUtils)
      Constructs an AuthController with the specified dependencies.
      Parameters:
      authenticationManager - The manager for authenticating user credentials
      userRepository - The repository for user data operations
      encoder - The password encoder for securely hashing passwords
      jwtUtils - Utility for JWT token generation and validation
  • Method Details

    • authenticateUser

      @PostMapping("/signin") public ResponseEntity<?> authenticateUser(@Valid @RequestBody @Valid LoginDto loginRequest)
      Authenticates a user and generates a JWT token.

      This endpoint processes login requests by validating the provided credentials against the stored user data. Upon successful authentication, it generates a JWT token that can be used for subsequent authorized API requests. The response includes the token, user ID, username, email, and assigned roles.

      Parameters:
      loginRequest - The DTO containing login credentials (username and password)
      Returns:
      ResponseEntity with JWT token and user information on success
    • registerUser

      @PostMapping("/signup") public ResponseEntity<?> registerUser(@Valid @RequestBody @Valid RegisterDto signUpRequest)
      Registers a new user in the system.

      This endpoint handles user registration by validating the request data, checking for existing username or email conflicts, and creating a new user account with the specified roles. If no role is specified, the user is assigned the default CANDIDATE role. The password is securely encoded before storage.

      Parameters:
      signUpRequest - The DTO containing registration details (username, email, password, roles)
      Returns:
      ResponseEntity with success message or error details