Class TotpSecondFactorFragment

java.lang.Object
com.irurueta.authserver.authorization.api.web.totp.TotpSecondFactorFragment
All Implemented Interfaces:
SecondFactorFragment

@Component public class TotpSecondFactorFragment extends Object implements SecondFactorFragment
Contributes the TOTP forms to the second-factor page, as every second factor does through the SecondFactorFragment extension point. What the fragment shows depends on the signed-in user:
  • without a confirmed authenticator app but with another confirmed second factor (for example a passkey), nothing: that factor completes the sign-in, so no secret is generated and no enrolment is offered;
  • without any confirmed second factor, the enrolment form: a new secret is generated (replacing any pending one), shown as a QR code and as its otpauth URI, and the first code confirms it;
  • with one, the form of its code and the recovery-code form, plus a warning when 3 or fewer recovery codes are left.
  • Field Details

    • ORDER

      public static final int ORDER
      Position of the TOTP forms in the second-factor page.
      See Also:
    • OFFERED_ATTRIBUTE

      public static final String OFFERED_ATTRIBUTE
      Model attribute telling the fragment to show anything at all.
      See Also:
    • ENROLMENT_ATTRIBUTE

      public static final String ENROLMENT_ATTRIBUTE
      Model attribute telling the fragment to show the enrolment form.
      See Also:
    • OTPAUTH_URI_ATTRIBUTE

      public static final String OTPAUTH_URI_ATTRIBUTE
      Model attribute with the otpauth URI of the enrolment.
      See Also:
    • QR_CODE_ATTRIBUTE

      public static final String QR_CODE_ATTRIBUTE
      Model attribute with the QR code of the enrolment, as a data: URI.
      See Also:
    • CODES_LEFT_ATTRIBUTE

      public static final String CODES_LEFT_ATTRIBUTE
      Model attribute with the number of unused recovery codes.
      See Also:
    • CODES_LOW_ATTRIBUTE

      public static final String CODES_LOW_ATTRIBUTE
      Model attribute telling the fragment to warn that few recovery codes are left.
      See Also:
    • userResolver

      private final SecondFactorUserResolver userResolver
      Resolves the identifier of the account of the signed-in user.
    • isTotpEnabledUseCase

      private final IsTotpEnabledUseCase isTotpEnabledUseCase
      Tells whether the user has a confirmed authenticator app.
    • hasConfirmedSecondFactorUseCase

      private final HasConfirmedSecondFactorUseCase hasConfirmedSecondFactorUseCase
      Tells whether the user has confirmed another second factor.
    • enrollTotpUseCase

      private final EnrollTotpUseCase enrollTotpUseCase
      Starts an enrolment.
    • countRecoveryCodesUseCase

      private final CountRecoveryCodesUseCase countRecoveryCodesUseCase
      Counts the unused recovery codes.
    • qrCodeRenderer

      private final QrCodeRenderer qrCodeRenderer
      Renders the enrolment URI as a QR code.
  • Constructor Details

    • TotpSecondFactorFragment

      public TotpSecondFactorFragment()
  • Method Details

    • templateName

      public String templateName()
      Description copied from interface: SecondFactorFragment
      Gets the name of the template that holds the fragment.
      Specified by:
      templateName in interface SecondFactorFragment
      Returns:
      the template name.
    • fragmentName

      public String fragmentName()
      Description copied from interface: SecondFactorFragment
      Gets the name of the fragment inside the template.
      Specified by:
      fragmentName in interface SecondFactorFragment
      Returns:
      the fragment name.
    • order

      public int order()
      Description copied from interface: SecondFactorFragment
      Gets the position of the fragment in the page; lower values are rendered first.
      Specified by:
      order in interface SecondFactorFragment
      Returns:
      the order.
    • modelAttributes

      public Map<String,Object> modelAttributes(org.springframework.security.core.Authentication authentication)
      Supplies the enrolment (a new pending secret) to a user without any confirmed second factor, the number of recovery codes left to a user with a confirmed authenticator app, and hides the forms from a user whose only confirmed second factors are other ones.
      Specified by:
      modelAttributes in interface SecondFactorFragment
      Parameters:
      authentication - the authentication of the user the page is rendered for.
      Returns:
      the model attributes; none when nobody is signed in.