Class DeviceVerificationRequestGuard
java.lang.Object
com.irurueta.authserver.authorization.api.web.implicit.DeviceVerificationRequestGuard
- All Implemented Interfaces:
org.springframework.security.web.authentication.AuthenticationConverter
public class DeviceVerificationRequestGuard
extends Object
implements org.springframework.security.web.authentication.AuthenticationConverter
Guards the device verification endpoint. It is installed first among the converters of the endpoint and never
converts anything: it either lets the request go on (returning
null) or refuses it. Every request that
carries a user code (the code typed on the verification page, a link that carries it, and the consent decision) is
counted against the limit on the attempts, and the multi-factor policy of the account and of the client must be
satisfied, as the authorization endpoint requires before it issues a code: a user who owes a second factor is sent
to the second-factor page and resumes afterwards. The framework's own MFA customizer covers only
/oauth2/authorize.
The client is the one the device authorization stored for the user code was issued to, because the code typed on
the page (or carried by the link) is the only thing the request names: so a client that requires multi-factor
authentication is enforced even when it skips the consent page. Only when no authorization holds the code (an
unknown or expired one, which the endpoint refuses anyway) is the client_id of the consent decision used.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MfaAuthorizationManagerApplies the multi-factor policy.private final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationServiceFinds the device authorization of a user code.private static final PatternEverything a user may type around the letters and digits of a code (dashes, spaces).private final DeviceVerificationRateLimiterLimits the attempts.private final org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepositoryFinds the client of a device authorization.private static final intPosition of the dash the framework stores a user code with.private static final intNumber of letters and digits of a user code.(package private) static final org.springframework.security.oauth2.server.authorization.OAuth2TokenTypeType of the token the user code is stored as. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringclientIdOf(jakarta.servlet.http.HttpServletRequest request) Finds the client a request is about: the client of the device authorization stored for its user code, or theclient_idparameter when no authorization holds that code.org.springframework.security.core.Authenticationconvert(jakarta.servlet.http.HttpServletRequest request) Checks the request.Normalises a user code as the framework stores it: upper case letters and digits in two groups of four, separated by a dash.
-
Field Details
-
USER_CODE_TOKEN_TYPE
static final org.springframework.security.oauth2.server.authorization.OAuth2TokenType USER_CODE_TOKEN_TYPEType of the token the user code is stored as. -
USER_CODE_LENGTH
private static final int USER_CODE_LENGTHNumber of letters and digits of a user code.- See Also:
-
USER_CODE_GROUP
private static final int USER_CODE_GROUPPosition of the dash the framework stores a user code with.- See Also:
-
NOT_ALPHANUMERIC
Everything a user may type around the letters and digits of a code (dashes, spaces). -
rateLimiter
Limits the attempts. -
authorizationManager
Applies the multi-factor policy. -
authorizationService
private final org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService authorizationServiceFinds the device authorization of a user code. -
registeredClientRepository
private final org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository registeredClientRepositoryFinds the client of a device authorization.
-
-
Constructor Details
-
DeviceVerificationRequestGuard
public DeviceVerificationRequestGuard()
-
-
Method Details
-
convert
public org.springframework.security.core.Authentication convert(jakarta.servlet.http.HttpServletRequest request) Checks the request.- Specified by:
convertin interfaceorg.springframework.security.web.authentication.AuthenticationConverter- Parameters:
request- the request.- Returns:
- always
null: this converter only vetoes requests. - Throws:
DeviceVerificationRateLimitedException- if the client address or the user made too many attempts.SecondFactorRequiredException- if the user still owes a second factor.
-
clientIdOf
Finds the client a request is about: the client of the device authorization stored for its user code, or theclient_idparameter when no authorization holds that code.- Parameters:
request- the request.- Returns:
- the client id, or
nullwhen neither tells it.
-
normalize
Normalises a user code as the framework stores it: upper case letters and digits in two groups of four, separated by a dash.- Parameters:
userCode- the code as typed, may benull.- Returns:
- the stored form, or empty when the value cannot be a user code.
-