Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class SecondFactorAuthenticationFilter

  1. Object
  2. SecondFactorAuthenticationFilter

ImplementsSecondFactorPolicy, SecurityFilter

Asks a user who has a second factor for it, between their password being accepted and their being signed in.

It is the chain’s SecondFactorPolicy: handed an authentication whose first factor has passed, it signs nobody in. It notes in the session who is waiting – a marker that is not a security context, and that lasts five minutes unless set otherwise – and redirects to the page that asks for the code. Until the code arrives every request of that session is anonymous.

It is also the filter that takes the code, at POST /login/mfa unless changed, in the field code: a one-time code from the user’s authenticator app, the code that was mailed to them, or one of their recovery codes. A user whose only second factor is the mailed code is sent one as they reach the page; one who has an authenticator app too asks for it there, by posting the field send. A right code completes the sign-in through the chain’s SessionSignIn – the session id changes, the context is stored, remember-me is issued if it was asked for at the first step, and the user goes where they were going.

Wrong codes are counted twice: for the user, whatever address and session they come from, and for the user at the client’s network. Too many of either are answered 429 until time has passed. See MfaConfigurer for the numbers, and for what the two counts together do and do not promise.

Fields

public static final String PENDING = "CN1_SECURITY_SECOND_FACTOR_PENDING"The session attribute the pending sign-in is kept under.

Methods

public HttpServer.Response intercept(HttpServer.Request request, Authentication authentication, boolean rememberMe)Decides whether authentication, whose first factor has just been accepted, must present a second.
public boolean requires(Authentication authentication)Whether authentication is of a user who has a second factor, so that a first factor alone must not make a request theirs.
public void satisfied(HttpServer.Request request, Authentication authentication)A passkey that verified the user signed them in.
public HttpServer.Response doFilter(HttpServer.Request request, FilterChain chain) throws ExceptionThe answer to request; null when nothing under the chain routes it, which the server answers 404.

Inherited methods

Field details

PENDING

public static final String PENDING = "CN1_SECURITY_SECOND_FACTOR_PENDING"
The session attribute the pending sign-in is kept under.

Method details

intercept

public HttpServer.Response intercept(HttpServer.Request request, Authentication authentication, boolean rememberMe)
Decides whether authentication, whose first factor has just been accepted, must present a second.

Parameters

request HttpServer.Request
Not documented.
authentication Authentication
Not documented.
rememberMe boolean
whether the user asked to be remembered: to be handed back to SessionSignIn.complete, since the request that finishes the sign-in is not the one that asked

Returns

null to let the sign-in complete now; otherwise the answer to this request – a redirect to where the second factor is asked for – with the sign-in left pending

requires

public boolean requires(Authentication authentication)

Whether authentication is of a user who has a second factor, so that a first factor alone must not make a request theirs.

intercept is for a sign-in that can stop and ask. This is for the ways of presenting a first factor that cannot: credentials sent with every request, which have no second step to send a code in, and a remember-me cookie, which has nobody at the keyboard. Each asks here and refuses the user when the answer is true; see MfaConfigurer for the rule of each mechanism.

A policy that does not say is taken to require one of everybody.

satisfied

public void satisfied(HttpServer.Request request, Authentication authentication)
A passkey that verified the user signed them in. Whoever ran the count of wrong codes up was not them, or no longer matters: it is forgotten, so their next one-time code is not refused for somebody else’s guesses.

doFilter

public HttpServer.Response doFilter(HttpServer.Request request, FilterChain chain) throws Exception
The answer to request; null when nothing under the chain routes it, which the server answers 404.

Throws

Exception