Class AuthenticationController
java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.controller.AuthenticationController
@RestController
@CrossOrigin
@RequestMapping("/auth")
public class AuthenticationController
extends Object
Controller used for registering and logging in a user and returning
access and refresh tokens
- Since:
- 17.4.24
- Version:
- 1.0
- Author:
- Lars N, Harry X.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<String> bioAuthRegistration
(org.springframework.security.core.userdetails.UserDetails userDetails) Initiates the biometric authentication registration process for a user.org.springframework.http.ResponseEntity
<LoginRegisterResponse> finishLogin
(String username, BioAuthRequest credential) Completes the biometric authentication login process for a user.org.springframework.http.ResponseEntity
<Void> finishRegistration
(BioAuthRequest credential, org.springframework.security.core.userdetails.UserDetails userDetails) Completes the passkey authentication registration process for a user.org.springframework.http.ResponseEntity
<LoginRegisterResponse> login
(AuthenticationRequest authRequest) Log in an existing user with username and passwordorg.springframework.http.ResponseEntity
<LoginRegisterResponse> register
(RegisterRequest registerRequest) Registers a new user with a given username, password, email, first name and last nameorg.springframework.http.ResponseEntity
<AccessTokenResponse> renewAccessToken
(String bearerToken) Refreshes the access token using a valid refresh token.org.springframework.http.ResponseEntity
<String> startBioLogin
(String username) Initiates the biometric authentication login process for a user.
-
Constructor Details
-
AuthenticationController
public AuthenticationController()
-
-
Method Details
-
register
@PostMapping("/register") public org.springframework.http.ResponseEntity<LoginRegisterResponse> register(@RequestBody RegisterRequest registerRequest) throws BadInputException, ObjectNotValidException, UserAlreadyExistsException Registers a new user with a given username, password, email, first name and last name- Parameters:
registerRequest
- Wrapper for user info- Returns:
- ResponseEntity containing access and refresh tokens upon successful registration
- Throws:
BadInputException
- If the username, first name last name or email is invalid or the password is too weakUserAlreadyExistsException
- If the username is already takenObjectNotValidException
-
login
@PostMapping("/login") public org.springframework.http.ResponseEntity<LoginRegisterResponse> login(@RequestBody AuthenticationRequest authRequest) throws BadInputException, ObjectNotValidException Log in an existing user with username and password- Parameters:
authRequest
- Wrapper for username and password- Returns:
- ResponseEntity containing access and refresh tokens upon successful login
- Throws:
BadInputException
- If the username or password is incorrectObjectNotValidException
-
renewAccessToken
@GetMapping("/renewToken") public org.springframework.http.ResponseEntity<AccessTokenResponse> renewAccessToken(@RequestHeader("Authorization") String bearerToken) Refreshes the access token using a valid refresh token.- Parameters:
bearerToken
- Bearer token in authorization header- Returns:
- ResponseEntity containing a new access token
-
bioAuthRegistration
@PostMapping("/bioRegistration") public org.springframework.http.ResponseEntity<String> bioAuthRegistration(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws UserNotFoundException, com.fasterxml.jackson.core.JsonProcessingException Initiates the biometric authentication registration process for a user.- Parameters:
userDetails
- The details of the authenticated user- Returns:
- ResponseEntity containing the options for biometric authentication registration
- Throws:
UserNotFoundException
- If the user is not foundcom.fasterxml.jackson.core.JsonProcessingException
- If an error occurs during JSON processing
-
finishRegistration
@PostMapping("/finishBioRegistration") public org.springframework.http.ResponseEntity<Void> finishRegistration(@RequestBody BioAuthRequest credential, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) throws com.yubico.webauthn.exception.RegistrationFailedException, IOException Completes the passkey authentication registration process for a user.- Parameters:
credential
- The biometric authentication credentialuserDetails
- The details of the authenticated user- Returns:
- ResponseEntity indicating the success of the registration process
- Throws:
com.yubico.webauthn.exception.RegistrationFailedException
- If the registration failsIOException
- If an I/O error occurs
-
startBioLogin
@PostMapping("/bioLogin/{username}") public org.springframework.http.ResponseEntity<String> startBioLogin(@PathVariable String username) throws com.fasterxml.jackson.core.JsonProcessingException Initiates the biometric authentication login process for a user.- Parameters:
username
- The username of the user- Returns:
- ResponseEntity containing the options for biometric authentication login
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If an error occurs during JSON processing
-
finishLogin
@PostMapping("/finishBioLogin/{username}") public org.springframework.http.ResponseEntity<LoginRegisterResponse> finishLogin(@PathVariable String username, @RequestBody BioAuthRequest credential) throws IOException, com.yubico.webauthn.exception.AssertionFailedException Completes the biometric authentication login process for a user.- Parameters:
username
- The username of the usercredential
- The biometric authentication credential- Returns:
- ResponseEntity containing access and refresh tokens upon successful login
- Throws:
IOException
- If an I/O error occurscom.yubico.webauthn.exception.AssertionFailedException
- If the assertion fails
-