Class AuthenticationController
java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.user.AuthenticationController
AuthenticationController defines the endpoint for user authentication,
authenticating user credentials and generating a JWT token.
- Version:
- 1.0
- Author:
- Anders
-
Constructor Summary
ConstructorsConstructorDescriptionAuthenticationController
(TokenService tokenService, org.springframework.security.authentication.AuthenticationManager authenticationManager) Constructs a new AuthController with the specified TokenService and AuthenticationManager. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<?>
token
(LoginRequest userLogin) Generates a token for the given user login request if the authentication is successful.
-
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.
-