Class ActorController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.ActorController
Defines the behaviour of the web server for the path
/benutzer.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents templates in the resources, allowing one or several Actors to be rendered as HTML. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ActorServiceUsed to retrieve and save Actors from the database.private final @NonNull PathLocaliserUsed to resolve the URL paths in the correctLocale. -
Constructor Summary
ConstructorsConstructorDescriptionActorController(@NonNull ActorService actorService, @NonNull PathLocaliser pathLocaliser) Constructs a newActorController. -
Method Summary
Modifier and TypeMethodDescription@NonNull StringchangeEMailAddress(@NonNull org.springframework.ui.Model model, @NonNull @Valid ChangeEMailAddressDTO changeEMailAddressDTO, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull jakarta.servlet.http.HttpServletResponse response, @Nullable ChangeUserNameDTO ignoredChangeUserNameDTO, @Nullable ChangeNameDTO ignoredChangeNameDTO, @NonNull org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) HandlesPOSTrequests to/user/change-emailand allows the currently logged-inActorto request a change of theirActor.eMailAddress.@NonNull StringchangeName(@NonNull org.springframework.ui.Model model, @NonNull @Valid ChangeNameDTO changeNameDTO, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull jakarta.servlet.http.HttpServletResponse response, @Nullable ChangeUserNameDTO ignoredChangeUserNameDTO, @Nullable ChangeEMailAddressDTO ignoredChangeEMailAddressDTO) HandlesPOSTrequests to/user/change-nameand updates theActor.nameof the authenticatedActorto the givenChangeNameDTO.newName.@NonNull StringchangePassword(@NonNull @Valid ChangePasswordDTO changePasswordDTO, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull jakarta.servlet.http.HttpServletResponse response) @NonNull StringchangeUserName(@NonNull org.springframework.ui.Model model, @NonNull @Valid ChangeUserNameDTO changeUserNameDTO, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull jakarta.servlet.http.HttpServletResponse response, @Nullable ChangeNameDTO ignoredChangeNameDTO, @Nullable ChangeEMailAddressDTO ignoredChangeEMailAddressDTO) HandlesPOSTrequests to/user/change-usernameand updates theActor.userNameof the authenticatedActorto the givenChangeUserNameDTO.newUserName.@NonNull StringgetAccountConfirmationPage(@NonNull String token, @NonNull org.springframework.ui.Model model, @NonNull jakarta.servlet.http.HttpServletResponse response) HandlesGETrequests to/users/confirm/{token}and enables theActorassociated with the givenVerificationToken.getActor(@NonNull String userName, @NonNull org.springframework.ui.Model model, @Nullable ChangeUserNameDTO ignoredChangeUserNameDTO, @Nullable ChangeNameDTO ignoredChangeNameDTO, @Nullable ChangeEMailAddressDTO ignoredChangeEMailAddressDTO) HandlesGETrequests to/benutzer/@{userName}.@NonNull StringgetActors(@NonNull jakarta.servlet.http.HttpServletResponse response) Redirects the user to/admin/users.@NonNull StringgetChangePasswordPage(@NonNull org.springframework.ui.Model model) HandlesGETrequests to/change-passwordand returns theActorController.Template.CHANGE_PASSWORDform.@NonNull StringgetEMailConfirmationPage(@NonNull String token, @NonNull org.springframework.ui.Model model, @NonNull jakarta.servlet.http.HttpServletResponse response) HandlesGETrequests to/users/change-email/confirm/{token}and updates theActor.eMailAddressof theActorassociated with the givenEMailVerificationTokento the valueEMailVerificationToken.eMailAddress.@NonNull String@NonNull StringgetRegistrationForm(@NonNull org.springframework.ui.Model model, @NonNull LocalRegistrationActorDTO localRegistrationActorDTO, @NonNull LdapRegistrationActorDTO ldapRegistrationActorDTO, @NonNull jakarta.servlet.http.HttpServletResponse response) HandlesGETrequests to/registerand returns an HTML form that allows the user to sign up at this service.@NonNull StringregisterLocally(@NonNull org.springframework.ui.Model model, @NonNull @Valid LocalRegistrationActorDTO registerDTO, @NonNull org.springframework.validation.BindingResult result, @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull LdapRegistrationActorDTO ignoredDTO) HandlesPOSTrequests to/registerand allows the user to sign up at this service.@NonNull StringregisterViaLdap(@NonNull org.springframework.ui.Model model, @NonNull @Valid LdapRegistrationActorDTO registerDTO, @NonNull org.springframework.validation.BindingResult result, @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull LocalRegistrationActorDTO ignoredDTO) HandlesPOSTrequests to/registerand allows the user to sign up at this service.
-
Field Details
-
Constructor Details
-
ActorController
public ActorController(@NonNull @NonNull ActorService actorService, @NonNull @NonNull PathLocaliser pathLocaliser) Constructs a newActorController.- Parameters:
actorService- TheactorService.pathLocaliser- ThepathLocaliser.
-
-
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 HandlesGETrequests to/benutzer/@{userName}. Retrieves a specificActordenoted by the path parameter{userName}.- Parameters:
userName- The path parameteruserNamedenoting 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.htmltemplate filled with the requested Actor. - Throws:
NotFoundException- If no Actor with the givenuserNameexists.- Implementation Note:
- The
@PreAuthorizeis there for the reasons explained inActorService.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) HandlesGETrequests to/registerand 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 HandlesPOSTrequests to/registerand allows the user to sign up at this service. Creates a newActorwhose 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 HandlesPOSTrequests to/registerand allows the user to sign up at this service. Creates a newActorwhose account is enabled and whoseActor.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 HandlesGETrequests to/users/confirm/{token}and enables theActorassociated with the givenVerificationToken.- Parameters:
token- TheVerificationToken.tokenwhoseVerificationToken.actorshall 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_CONFIRMATIONpage 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 HandlesGETrequests to/change-passwordand returns theActorController.Template.CHANGE_PASSWORDform.- Parameters:
model- Unused. Just there to prevent binding from breaking.- Returns:
- The change-password form.
- Throws:
NotLoggedInException- If the currentActoris 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 - 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 HandlesPOSTrequests to/user/change-usernameand updates theActor.userNameof the authenticatedActorto the givenChangeUserNameDTO.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 HandlesPOSTrequests to/user/change-nameand updates theActor.nameof the authenticatedActorto the givenChangeNameDTO.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 HandlesPOSTrequests to/user/change-emailand allows the currently logged-inActorto request a change of theirActor.eMailAddress. The user will receive an e-mail with anEMailVerificationTokenasking 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 theeMailChangeRequestedboolean 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 HandlesGETrequests to/users/change-email/confirm/{token}and updates theActor.eMailAddressof theActorassociated with the givenEMailVerificationTokento the valueEMailVerificationToken.eMailAddress.- Parameters:
token- TheVerificationToken.tokenwhoseVerificationToken.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_CONFIRMATIONpage filled in with a success or failure message. - Throws:
IllegalStateException- If the user path is malformed.NotLoggedInException- If the user is not authenticated.
-