Class ActorController

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.ActorController

@Controller public class ActorController extends Object
Defines the behaviour of the web server for the path /benutzer.
  • Field Details

    • actorService

      private final ActorService actorService
      Used to retrieve and save Actors from the database.
    • pathLocaliser

      @NonNull private final @NonNull PathLocaliser pathLocaliser
      Used to resolve the URL paths in the correct Locale.
  • Constructor Details

  • Method Details

    • getActor

      @GetMapping({"/benutzer/@{userName}","/en/users/@{userName}"}) @PreAuthorize("#userName == authentication.principal.getUsername() or hasRole('FACULTY_ADMINISTRATION')") public String getActor(@NonNull @PathVariable @NonNull String userName, @NonNull @NonNull org.springframework.ui.Model model, @Nullable @Nullable ChangeUserNameDTO ignoredChangeUserNameDTO, @Nullable @Nullable ChangeNameDTO ignoredChangeNameDTO, @Nullable @Nullable ChangeEMailAddressDTO ignoredChangeEMailAddressDTO) throws NotFoundException
      Handles GET requests to /benutzer/@{userName}. Retrieves a specific Actor denoted by the path parameter {userName}.
      Parameters:
      userName - The path parameter userName denoting a specific Actor.
      model - Will be filled with the data for the Thymeleaf template.
      ignoredChangeUserNameDTO - Used only to prevent the form binding from breaking.
      ignoredChangeNameDTO - Used only to prevent the form binding from breaking.
      ignoredChangeEMailAddressDTO - Used only to prevent the form binding from breaking.
      Returns:
      The user.html template filled with the requested Actor.
      Throws:
      NotFoundException - If no Actor with the given userName exists.
      Implementation Note:
      The @PreAuthorize is there for the reasons explained in ActorService.findUserByUserName(String).
    • getActors

      @GetMapping({"/benutzer","/en/users"}) @NonNull public @NonNull String getActors(@NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws IllegalStateException
      Redirects the user to /admin/users.
      Parameters:
      response - The web server's response.
      Returns:
      The redirection.
      Throws:
      IllegalStateException - If the users' path is malformed.
    • getRegistrationForm

      @GetMapping({"/registrieren","/en/register","/registrieren/ldap","/en/register/ldap"}) @NonNull public @NonNull String getRegistrationForm(@NonNull @NonNull org.springframework.ui.Model model, @NonNull @ModelAttribute("localRegistrationActorDTO") @NonNull LocalRegistrationActorDTO localRegistrationActorDTO, @NonNull @ModelAttribute("ldapRegistrationActorDTO") @NonNull LdapRegistrationActorDTO ldapRegistrationActorDTO, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response)
      Handles GET requests to /register and returns an HTML form that allows the user to sign up at this service.
      Parameters:
      model - Will be filled with the data for the Thymeleaf template.
      localRegistrationActorDTO - Used to fill the local-registration form with default values.
      ldapRegistrationActorDTO - Used to fill the LDAP-registration form with default values.
      response - The web server's response to the admin's HTTP request.
      Returns:
      The HTML form for signing up.
    • registerLocally

      @PostMapping({"/registrieren","/en/register"}) @NonNull public @NonNull String registerLocally(@NonNull @NonNull org.springframework.ui.Model model, @NonNull @Valid @ModelAttribute("localRegistrationActorDTO") @NonNull @Valid LocalRegistrationActorDTO registerDTO, @NonNull @NonNull org.springframework.validation.BindingResult result, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull @ModelAttribute("ldapRegistrationActorDTO") @NonNull LdapRegistrationActorDTO ignoredDTO) throws IllegalStateException, IllegalHttpMethodException
      Handles POST requests to /register and allows the user to sign up at this service. Creates a new Actor whose account is disabled and is therefore still unusable.
      Parameters:
      model - Will be filled with the data for the Thymeleaf template.
      registerDTO - The user's form input as a data-transfer object.
      result - The result of the DTO validation.
      response - The web server's response to the admin's HTTP request.
      ignoredDTO - Used to fill the form with default values for the LDAP registration form in case of an error.
      Returns:
      A redirection to a success page. In case of error, the HTML form with an appropriate error message.
      Throws:
      IllegalStateException - If the existing Actor's path is malformed.
      IllegalHttpMethodException - If local registrations are disabled.
    • registerViaLdap

      @PostMapping({"/registrieren/ldap","/en/register/ldap"}) @NonNull public @NonNull String registerViaLdap(@NonNull @NonNull org.springframework.ui.Model model, @NonNull @Valid @ModelAttribute("ldapRegistrationActorDTO") @NonNull @Valid LdapRegistrationActorDTO registerDTO, @NonNull @NonNull org.springframework.validation.BindingResult result, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull @ModelAttribute("localRegistrationActorDTO") @NonNull LocalRegistrationActorDTO ignoredDTO) throws IllegalStateException, IllegalHttpMethodException
      Handles POST requests to /register and allows the user to sign up at this service. Creates a new Actor whose account is enabled and whose Actor.password() is stored on the uni's LDAP server.
      Parameters:
      model - Will be filled with the data for the Thymeleaf template.
      registerDTO - The user's form input as a data-transfer object.
      result - The result of the DTO validation.
      response - The web server's response to the admin's HTTP request.
      ignoredDTO - Used to fill the form with default values for the local registration form in case of an error.
      Returns:
      A redirection to a success page. In case of error, the HTML form with an appropriate error message.
      Throws:
      IllegalStateException - If the existing or new Actor's path is malformed.
      IllegalHttpMethodException - If LDAP registrations are disabled.
    • getAccountConfirmationPage

      @GetMapping({"/benutzer/best\u00e4tigen/{token}","/en/users/confirm/{token}"}) @NonNull public @NonNull String getAccountConfirmationPage(@NonNull @PathVariable @NonNull String token, @NonNull @NonNull org.springframework.ui.Model model, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws IllegalStateException
      Handles GET requests to /users/confirm/{token} and enables the Actor associated with the given VerificationToken.
      Parameters:
      token - The VerificationToken.token whose VerificationToken.actor shall be enabled.
      model - Used to display the correct message.
      response - The web server's response to the user's HTTP request.
      Returns:
      The ActorController.Template.REGISTRATION_CONFIRMATION page filled in with a success or failure message.
      Throws:
      IllegalStateException - If the user path is malformed.
    • getGenericChangePasswordPage

      @GetMapping("/change-password") @NonNull public @NonNull String getGenericChangePasswordPage() throws IllegalStateException
      Returns:
      Redirects to getChangePasswordPage(Model).
      Throws:
      IllegalStateException - If the change-password path is malformed.
    • getChangePasswordPage

      @GetMapping({"/passwort-\u00e4ndern","/en/change-password"}) @NonNull public @NonNull String getChangePasswordPage(@NonNull @NonNull org.springframework.ui.Model model) throws NotLoggedInException
      Handles GET requests to /change-password and returns the ActorController.Template.CHANGE_PASSWORD form.
      Parameters:
      model - Unused. Just there to prevent binding from breaking.
      Returns:
      The change-password form.
      Throws:
      NotLoggedInException - If the current Actor is unauthenticated.
    • changePassword

      @PostMapping({"/passwort-\u00e4ndern","/en/change-password"}) @NonNull public @NonNull String changePassword(@NonNull @Valid @NonNull @Valid ChangePasswordDTO changePasswordDTO, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws NotLoggedInException
      Handles POST requests to /change-password and lets the Actor update their Actor.password().
      Parameters:
      changePasswordDTO - The user's form input as a data-transfer object.
      bindingResult - The result of the DTO validation.
      response - The web server's response to the admin's HTTP request.
      Returns:
      A redirection to a success page. In case of error, the HTML form with an appropriate error message.
      Throws:
      NotLoggedInException - If the Actor is not authenticated.
    • changeUserName

      @PostMapping({"/benutzer/benutzername-\u00e4ndern","/en/users/change-username"}) @NonNull public @NonNull String changeUserName(@NonNull @NonNull org.springframework.ui.Model model, @NonNull @Valid @NonNull @Valid ChangeUserNameDTO changeUserNameDTO, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response, @Nullable @Nullable ChangeNameDTO ignoredChangeNameDTO, @Nullable @Nullable ChangeEMailAddressDTO ignoredChangeEMailAddressDTO) throws IllegalStateException, NotLoggedInException, de.gustavblass.commons.exceptions.IllegalArgumentException
      Handles POST requests to /user/change-username and updates the Actor.userName of the authenticated Actor to the given ChangeUserNameDTO.newUserName.
      Parameters:
      model - Unused. Just there to prevent binding from breaking.
      changeUserNameDTO - The user's form input as a data-transfer object.
      bindingResult - The result of the DTO validation.
      response - The web server's response to the user's HTTP request.
      ignoredChangeNameDTO - Used only to prevent the form binding from breaking.
      ignoredChangeEMailAddressDTO - Used only to prevent the form binding from breaking.
      Returns:
      The user's page.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the user is not authenticated or if the new user name is blank (should never happen).
      NotLoggedInException - If the user is not authenticated.
      IllegalStateException - If the user path is malformed.
    • changeName

      @PostMapping({"/benutzer/name-\u00e4ndern","/en/users/change-name"}) @NonNull public @NonNull String changeName(@NonNull @NonNull org.springframework.ui.Model model, @NonNull @Valid @NonNull @Valid ChangeNameDTO changeNameDTO, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response, @Nullable @Nullable ChangeUserNameDTO ignoredChangeUserNameDTO, @Nullable @Nullable ChangeEMailAddressDTO ignoredChangeEMailAddressDTO) throws IllegalStateException, NotLoggedInException, de.gustavblass.commons.exceptions.IllegalArgumentException
      Handles POST requests to /user/change-name and updates the Actor.name of the authenticated Actor to the given ChangeNameDTO.newName.
      Parameters:
      model - Unused. Just there to prevent binding from breaking.
      changeNameDTO - The user's form input as a data-transfer object.
      bindingResult - The result of the DTO validation.
      response - The web server's response to the user's HTTP request.
      ignoredChangeUserNameDTO - Used only to prevent the form binding from breaking.
      ignoredChangeEMailAddressDTO - Used only to prevent the form binding from breaking.
      Returns:
      The user's page.
      Throws:
      NotLoggedInException - If the user is not authenticated.
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the user is not authenticated or if the new name is blank (should never happen).
      IllegalStateException - If the user path is malformed.
    • changeEMailAddress

      @PostMapping({"/benutzer/email-\u00e4ndern","/en/users/change-email"}) @NonNull public @NonNull String changeEMailAddress(@NonNull @NonNull org.springframework.ui.Model model, @NonNull @Valid @NonNull @Valid ChangeEMailAddressDTO changeEMailAddressDTO, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response, @Nullable @Nullable ChangeUserNameDTO ignoredChangeUserNameDTO, @Nullable @Nullable ChangeNameDTO ignoredChangeNameDTO, @NonNull @NonNull org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) throws IllegalStateException, NotLoggedInException
      Handles POST requests to /user/change-email and allows the currently logged-in Actor to request a change of their Actor.eMailAddress. The user will receive an e-mail with an EMailVerificationToken asking them to confirm their new e-mail address.
      Parameters:
      model - The Actor object is filled in there.
      changeEMailAddressDTO - The user's form input as a data-transfer object.
      bindingResult - The result of the DTO validation.
      response - The web server's response to the user's HTTP request.
      ignoredChangeUserNameDTO - Used only to prevent the form binding from breaking.
      ignoredChangeNameDTO - Used only to prevent the form binding from breaking.
      redirectAttributes - Used to pass the eMailChangeRequested boolean variable to the user page.
      Returns:
      The user's page.
      Throws:
      NotLoggedInException - If the user is not authenticated or if the new e-mail address is blank.
      IllegalStateException - If the user path is malformed.
    • getEMailConfirmationPage

      @GetMapping({"/benutzer/email-\u00e4ndern/best\u00e4tigen/{token}","/en/users/change-email/confirm/{token}"}) @NonNull public @NonNull String getEMailConfirmationPage(@NonNull @PathVariable @NonNull String token, @NonNull @NonNull org.springframework.ui.Model model, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws IllegalStateException, NotLoggedInException
      Handles GET requests to /users/change-email/confirm/{token} and updates the Actor.eMailAddress of the Actor associated with the given EMailVerificationToken to the value EMailVerificationToken.eMailAddress.
      Parameters:
      token - The VerificationToken.token whose VerificationToken.actor's e-mail address shall be updated.
      model - Used to display the correct message.
      response - The web server's response to the user's HTTP request.
      Returns:
      The ActorController.Template.NEW_EMAIL_CONFIRMATION page filled in with a success or failure message.
      Throws:
      IllegalStateException - If the user path is malformed.
      NotLoggedInException - If the user is not authenticated.