What the security code needs to know about one of your users to log them in: the username, the stored password hash, the authorities and whether the account may log in at all.
Your user store returns it from UserDetailsService.loadUserByUsername,
and after a successful login it becomes the principal of the
Authentication. Most applications build a User instead of
implementing this interface. Implement it on your own account class
when you want the principal to carry more, such as the account id or
the tenant.
// The account entity itself serves as the logged-in principal.
class Account implements UserDetails {
Account(this.id, this.email, this.passwordHash, this.authorities);
final int id;
final String email;
final String passwordHash;
@override
String get username => email;
@override
String? get password => passwordHash;
@override
final List<GrantedAuthority> authorities;
@override
bool get isAccountNonExpired => true;
@override
bool get isAccountNonLocked => true;
@override
bool get isCredentialsNonExpired => true;
@override
bool get isEnabled => true;
}
Spring (Java): UserDetails; Java's getUsername() and
isEnabled() are getters here.
Properties
-
The user's permissions, such as
ROLE_ADMIN; they become the authorities of theAuthentication.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- isAccountNonExpired → bool
-
falserefuses every login with anAccountExpiredException, before the password is checked.no setter - isAccountNonLocked → bool
-
falserefuses every login with aLockedException, before the password is checked.no setter - isCredentialsNonExpired → bool
-
falserefuses the login with aCredentialsExpiredException, after the password matched.no setter - isEnabled → bool
-
falserefuses every login with aDisabledException, before the password is checked.no setter - password → String?
-
The stored password hash, such as
{argon2}$argon2id$...;nullafter the login erased it, and anullpassword never matches.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- username → String
-
The name the user logs in with;
Authentication.namereturns it.no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited