Class PhonePageController

java.lang.Object
com.irurueta.authserver.authorization.api.web.ott.PhonePageController
All Implemented Interfaces:
PhonePageApi

@Controller public class PhonePageController extends Object implements PhonePageApi
Serves the phone account page and the session-protected form posts it uses, as the contract apis/auth-server/web-pages/auth-server-pages-v1.yaml describes them through the generated PhonePageApi. A browser page has a session, not a bearer token, so it cannot call the REST API (/api/account/phone, which ApiSecurityConfig keeps bearer-only); the forms call the same use cases instead, with the same limits, and each answers by redirecting back to the page (post/redirect/get) with the outcome in the status parameter. The number is shown masked, as the REST API answers it.
  • Field Details

    • PHONE_PATH

      public static final String PHONE_PATH
      Path of the page, taken from the contract.
      See Also:
    • VIEW_NAME

      static final String VIEW_NAME
      Name of the template of the page.
      See Also:
    • PHONE_ATTRIBUTE

      static final String PHONE_ATTRIBUTE
      Name of the model attribute that holds the masked verified number, absent when there is none.
      See Also:
    • STATUS_ATTRIBUTE

      static final String STATUS_ATTRIBUTE
      Name of the model attribute that holds the outcome of the previous post.
      See Also:
    • PENDING

      static final String PENDING
      Status of a code that was requested.
      See Also:
    • VERIFIED

      static final String VERIFIED
      Status of a number that was verified.
      See Also:
    • REMOVED

      static final String REMOVED
      Status of a number that was removed.
      See Also:
    • INVALID_PHONE

      static final String INVALID_PHONE
      Status of a number that is not valid.
      See Also:
    • COUNTRY_NOT_ALLOWED

      static final String COUNTRY_NOT_ALLOWED
      Status of a number of a country SMS messages are not sent to.
      See Also:
    • INVALID_CODE

      static final String INVALID_CODE
      Status of a wrong code.
      See Also:
    • RATE_LIMITED

      static final String RATE_LIMITED
      Status of a request over a limit.
      See Also:
    • STEP_UP_REQUIRED

      static final String STEP_UP_REQUIRED
      Status of an enrolment or a removal that needs a recent multi-factor sign-in.
      See Also:
    • STATUSES

      private static final Set<String> STATUSES
      The statuses the page tells; any other value of the parameter is ignored.
    • currentAccountResolver

      private final CurrentAccountResolver currentAccountResolver
      Resolves the account of the request.
    • findUserPhoneUseCase

      private final FindUserPhoneUseCase findUserPhoneUseCase
      Finds the verified phone of the account.
    • startPhoneEnrolmentUseCase

      private final StartPhoneEnrolmentUseCase startPhoneEnrolmentUseCase
      Starts an enrolment.
    • confirmPhoneUseCase

      private final ConfirmPhoneUseCase confirmPhoneUseCase
      Confirms an enrolment.
    • removePhoneUseCase

      private final RemovePhoneUseCase removePhoneUseCase
      Removes the phone.
    • stepUp

      private final PhoneSessionStepUp stepUp
      Requires a recent multi-factor sign-in before the phone is replaced or removed.
    • rateLimiter

      private final OttRateLimiter rateLimiter
      Limits the requests.
    • phoneDtoMapper

      private final PhoneDtoMapper phoneDtoMapper
      Maps the phone onto its masked form.
    • pageRenderer

      private final PageRenderer pageRenderer
      Renders the page.
    • request

      private final jakarta.servlet.http.HttpServletRequest request
      The current request, injected as a thread-bound proxy, which tells the address of the client.
  • Constructor Details

    • PhonePageController

      public PhonePageController()
  • Method Details

    • phonePage

      public org.springframework.http.ResponseEntity<String> phonePage(String status)
      Renders the page.
      Specified by:
      phonePage in interface PhonePageApi
      Parameters:
      status - outcome of the previous post, ignored when it is not one of the known ones.
      Returns:
      the page, never cached.
    • startPhoneEnrolmentPage

      public org.springframework.http.ResponseEntity<Void> startPhoneEnrolmentPage(String phone)
      Sends the verification code to the number, when the session shows a recent enough multi-factor sign-in for an account that already has a confirmed second factor (the new number would replace the verified one).
      Specified by:
      startPhoneEnrolmentPage in interface PhonePageApi
      Parameters:
      phone - the number.
      Returns:
      a redirect to the page; the status is pending whether or not the number belongs to another account.
    • verifyPhonePage

      public org.springframework.http.ResponseEntity<Void> verifyPhonePage(String code)
      Confirms the number with the code.
      Specified by:
      verifyPhonePage in interface PhonePageApi
      Parameters:
      code - the code received by SMS.
      Returns:
      a redirect to the page, with the outcome.
    • removePhonePage

      public org.springframework.http.ResponseEntity<Void> removePhonePage()
      Removes the phone, when the session shows a recent enough multi-factor sign-in.
      Specified by:
      removePhonePage in interface PhonePageApi
      Returns:
      a redirect to the page, with the outcome.
    • redirect

      private org.springframework.http.ResponseEntity<Void> redirect(String status)
      Builds the redirect back to the page.
      Parameters:
      status - the outcome.
      Returns:
      303 See Other to the page.