Class AuthenticationController

java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.user.AuthenticationController

@RestController @RequestMapping("/api/auth") public class AuthenticationController extends Object
AuthenticationController defines the endpoint for user authentication, authenticating user credentials and generating a JWT token.
Version:
1.0
Author:
Anders
  • Constructor Summary

    Constructors
    Constructor
    Description
    AuthenticationController(TokenService tokenService, org.springframework.security.authentication.AuthenticationManager authenticationManager)
    Constructs a new AuthController with the specified TokenService and AuthenticationManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<?>
    token(LoginRequest userLogin)
    Generates a token for the given user login request if the authentication is successful.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AuthenticationController

      public AuthenticationController(TokenService tokenService, org.springframework.security.authentication.AuthenticationManager authenticationManager)
      Constructs a new AuthController with the specified TokenService and AuthenticationManager. The parameters may be autowired by Spring BOOT.
      Parameters:
      tokenService - The TokenService instance responsible for generating tokens.
      authenticationManager - The AuthenticationManager instance responsible for authenticating user credentials.
  • Method Details

    • token

      @PostMapping("/credentials") public org.springframework.http.ResponseEntity<?> token(@RequestBody LoginRequest userLogin)
      Generates a token for the given user login request if the authentication is successful. Input data is validated before the authentication is attempted.
      Parameters:
      userLogin - A LoginRequest object containing the user's username and password.
      Returns:
      A ResponseEntity containing the generated token or an error message.