Record Class SignInPolicy
java.lang.Object
java.lang.Record
com.iizix.user.SignInPolicy
- Record Components:
secondFactor- The second factor: off, optional (asked of a user who enrolled one) or required (of every user).secondFactorAdministrators- Whether the members of the administrators group need a second factor whateversecondFactorsays.methods- The methods that may be enrolled and used, in the order ofALL_METHODS, strongest first; unmodifiable.trustDeviceDays- The days a device may be trusted not to be asked for the second factor again, 0 for never.selfSignUp- Whether a user may create an account.emailVerificationDays- The days after which an account whose e-mail address is not verified must verify it to sign in; 0 is at once,NEVERis never.privacyURL- The link to the privacy statement, empty for none.termsURL- The link to the terms, empty for none.support- The support contact shown to a user who cannot sign in, empty for none.
public record SignInPolicy(SignInPolicy.SecondFactor secondFactor, boolean secondFactorAdministrators, Set<String> methods, int trustDeviceDays, boolean selfSignUp, int emailVerificationDays, String privacyURL, String termsURL, String support) extends Record
The sign-in policy of an application: what the server environment sets, with what the application overrides (SignIn L-6; section 5 of the SignIn flow design, its decisions D-11, D-20 and D-31). The rules the owner asked for - require a second factor, "at least one more method", for every user or for the administrators - are
secondFactor and secondFactorAdministrators.Where the settings are. The server's are properties of the server settings named SERVER_PREFIX and the setting's name, e.g. $signIn.secondFactor, beside $signIn.module and $signIn.selfSignUp. The application's are properties of its moduleApp settings named APP_PREFIX and the setting's name, e.g. signIn.secondFactor; each one inherits the server's unless it is set. A setting that is absent has its default, so a server and an application that know nothing of this policy behave as they did: a second factor is asked of the users who enrolled one.
| Name | Server | Application | Default |
|---|---|---|---|
secondFactor | integer: 0 off, 1 optional, 2 required | integer: -1 inherit, 0, 1, 2 | 1, optional |
secondFactorAdministrators | integer: 0 as every user, 1 required | integer: -1 inherit, 0, 1 | 1, required |
methods | text: names separated by commas | text: empty inherits | empty: every method but email |
trustDeviceDays | integer: 0 to 90, 0 never | integer: -1 inherit, 0 to 90 | 30 |
selfSignUp | boolean | integer: -1 inherit, 0 off, 1 on | off |
emailVerificationDays | integer: -1 never required, 0 or more | integer: -2 inherit, -1 never required, 0 or more | -1, never required |
privacyURL, termsURL, support | text | text: empty inherits, a single dash is none | empty: none |
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhat the policy says of the second factor.Field Summary
FieldsModifier and TypeFieldDescriptionEvery method a policy can name, strongest first.static final StringThe prefix of the settings in the application'smoduleAppsettings: "signIn.".static final SignInPolicyThe policy of a server and an application that set nothing.The methods of a policy that names none: every method but e-mail codes, the weakest, because the mailbox is also where a password reset goes.static final intThe default days a device may be trusted: 30.static final intThe value of an application's integer setting that inherits the server's: -1.static final intThe value of an application'semailVerificationDaysthat inherits the server's: -2.static final intThe most days a device may be trusted: 90.static final StringThe methods of a second factor.static final StringThe methods of a second factor.static final StringThe methods of a second factor.static final StringThe methods of a second factor.static final StringThe methods of a second factor.static final intThe value ofemailVerificationDaysfor "never required": -1.static final StringThe text of an application's link or contact that is none although the server has one.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe names of the settings, without their prefix.static final StringThe prefix of the settings in the server settings: "$signIn.".Constructor Summary
ConstructorsConstructorDescriptionSignInPolicy(SignInPolicy.SecondFactor secondFactor, boolean secondFactorAdministrators, Set<String> methods, int trustDeviceDays, boolean selfSignUp, int emailVerificationDays, String privacyURL, String termsURL, String support) Creates an instance of aSignInPolicyrecord class.Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if a method may be enrolled and used.intReturns the value of theemailVerificationDaysrecord component.enrolmentChoices(boolean webAuthn) Gets the methods a user without a second factor chooses among to enrol one: the choice of the SignIn module, one button each (CC-FIX-SIGNIN-2FA-CHOICE).final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisEmailVerificationRequired(boolean verified, long created, long now) Checks if an account must verify its e-mail address to sign in.methods()Returns the value of themethodsrecord component.Gets the methods a text names.Returns the value of theprivacyURLrecord component.static SignInPolicyResolves the policy of an application: every setting is the application's when it is set there, the server's otherwise, and its default when neither sets it.Returns the value of thesecondFactorrecord component.booleanReturns the value of thesecondFactorAdministratorsrecord component.secondFactorOf(boolean administrator) Gets what the policy says of the second factor of a user.booleanReturns the value of theselfSignUprecord component.support()Returns the value of thesupportrecord component.termsURL()Returns the value of thetermsURLrecord component.final StringtoString()Returns a string representation of this record class.inttrustDays(int asked) Gets the days a device is trusted when a user asks for some.intReturns the value of thetrustDeviceDaysrecord component.withMethods(Set<String> existing) Gets the policy with its methods narrowed to the ones that exist: a policy may name a method the server cannot do yet.
Field Details
SERVER_PREFIX
The prefix of the settings in the server settings: "$signIn.".- See Also:
APP_PREFIX
The prefix of the settings in the application'smoduleAppsettings: "signIn.".- See Also:
PN_SECOND_FACTOR
The names of the settings, without their prefix.- See Also:
PN_SECOND_FACTOR_ADMINISTRATORS
The names of the settings, without their prefix.- See Also:
PN_METHODS
PN_TRUST_DEVICE_DAYS
The names of the settings, without their prefix.- See Also:
PN_SELF_SIGN_UP
PN_EMAIL_VERIFICATION_DAYS
The names of the settings, without their prefix.- See Also:
PN_PRIVACY_URL
PN_TERMS_URL
PN_SUPPORT
METHOD_PASSKEY
METHOD_TOTP
METHOD_SMS
METHOD_EMAIL
METHOD_RECOVERY
ALL_METHODS
DEFAULT_METHODS
INHERIT
public static final int INHERITThe value of an application's integer setting that inherits the server's: -1.- See Also:
NEVER
public static final int NEVERThe value ofemailVerificationDaysfor "never required": -1.- See Also:
INHERIT_DAYS
public static final int INHERIT_DAYSThe value of an application'semailVerificationDaysthat inherits the server's: -2. It is notINHERIT, which is this setting's "never required".- See Also:
NONE
The text of an application's link or contact that is none although the server has one.- See Also:
MAX_TRUST_DEVICE_DAYS
public static final int MAX_TRUST_DEVICE_DAYSThe most days a device may be trusted: 90.- See Also:
DEFAULT_TRUST_DEVICE_DAYS
public static final int DEFAULT_TRUST_DEVICE_DAYSThe default days a device may be trusted: 30.- See Also:
DEFAULT
The policy of a server and an application that set nothing.
Constructor Details
SignInPolicy
public SignInPolicy(SignInPolicy.SecondFactor secondFactor, boolean secondFactorAdministrators, Set<String> methods, int trustDeviceDays, boolean selfSignUp, int emailVerificationDays, String privacyURL, String termsURL, String support) Creates an instance of aSignInPolicyrecord class.- Parameters:
secondFactor- the value for thesecondFactorrecord componentsecondFactorAdministrators- the value for thesecondFactorAdministratorsrecord componentmethods- the value for themethodsrecord componenttrustDeviceDays- the value for thetrustDeviceDaysrecord componentselfSignUp- the value for theselfSignUprecord componentemailVerificationDays- the value for theemailVerificationDaysrecord componentprivacyURL- the value for theprivacyURLrecord componenttermsURL- the value for thetermsURLrecord componentsupport- the value for thesupportrecord component
Method Details
resolve
Resolves the policy of an application: every setting is the application's when it is set there, the server's otherwise, and its default when neither sets it. A value out of its range is brought into it.- Parameters:
server- The server settings, null for none.app- ThemoduleAppsettings of the application, null for none.- Returns:
- The policy.
methodsOf
Gets the methods a text names.- Parameters:
names- The names, separated by commas; the letter case and blanks do not matter, and what is no method is left out.- Returns:
- The methods named, in the order of
ALL_METHODS; unmodifiable, and empty when the text names no method at all.
secondFactorOf
Gets what the policy says of the second factor of a user.- Parameters:
administrator- Whether the user is a member of the administrators group.- Returns:
REQUIREDfor an administrator when the administrators need one, otherwise what the policy says for every user.
allows
Checks if a method may be enrolled and used.- Parameters:
method- The method.- Returns:
- true when the policy has it.
enrolmentChoices
Gets the methods a user without a second factor chooses among to enrol one: the choice of the SignIn module, one button each (CC-FIX-SIGNIN-2FA-CHOICE). They are the methods of the policy a person sets up - a passkey, an authenticator app - in the order of the policy, strongest first. The recovery codes are never a choice: they come with the first second factor. A text message and e-mail codes are none either while nothing sets them up.- Parameters:
webAuthn- Whether the device can create a passkey: the client reported WebAuthn and the application offers passkeys to it.- Returns:
- The methods, unmodifiable; empty when there is none to choose.
withMethods
Gets the policy with its methods narrowed to the ones that exist: a policy may name a method the server cannot do yet.- Parameters:
existing- The methods the server can do.- Returns:
- The policy with the methods that are in both, in their order.
trustDays
public int trustDays(int asked) Gets the days a device is trusted when a user asks for some.- Parameters:
asked- The days the user asked for, zero or less for none.- Returns:
- The days: what was asked for, at most what the policy allows; zero for none.
isEmailVerificationRequired
public boolean isEmailVerificationRequired(boolean verified, long created, long now) Checks if an account must verify its e-mail address to sign in.- Parameters:
verified- Whether the address of the account is verified.created- The time the account was created, milliseconds since the epoch.now- The time now, milliseconds since the epoch.- Returns:
- true when the address is not verified and the days of the policy have passed since the account was created; never when the policy is
NEVER.
toString
hashCode
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes.secondFactor
Returns the value of thesecondFactorrecord component.- Returns:
- the value of the
secondFactorrecord component
secondFactorAdministrators
public boolean secondFactorAdministrators()Returns the value of thesecondFactorAdministratorsrecord component.- Returns:
- the value of the
secondFactorAdministratorsrecord component
methods
trustDeviceDays
public int trustDeviceDays()Returns the value of thetrustDeviceDaysrecord component.- Returns:
- the value of the
trustDeviceDaysrecord component
selfSignUp
public boolean selfSignUp()Returns the value of theselfSignUprecord component.- Returns:
- the value of the
selfSignUprecord component
emailVerificationDays
public int emailVerificationDays()Returns the value of theemailVerificationDaysrecord component.- Returns:
- the value of the
emailVerificationDaysrecord component
privacyURL
Returns the value of theprivacyURLrecord component.- Returns:
- the value of the
privacyURLrecord component
termsURL
support