Package com.example.demo.appuser
Class AppUser
java.lang.Object
com.example.demo.appuser.AppUser
- All Implemented Interfaces:
Serializable,org.springframework.security.core.userdetails.UserDetails
@Entity
public class AppUser
extends Object
implements org.springframework.security.core.userdetails.UserDetails
Represents a user entity in the application, implementing Spring Security's
UserDetails interface.
This class maps to the 'app_user' table in the database and provides the core user information required for authentication and authorization.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCollection<? extends org.springframework.security.core.GrantedAuthority> Retrieves the authorities (roles) granted to the user.Retrieves the password used to authenticate the user.Retrieves the username used to authenticate the user.booleanIndicates whether the user's account has expired.booleanIndicates whether the user is locked or unlocked.booleanIndicates whether the user's credentials (password) have expired.booleanIndicates whether the user is enabled or disabled.
-
Constructor Details
-
AppUser
public AppUser(String firstName, String lastName, String email, String password, AppUserRole appUserRole) Constructs a new AppUser with essential details. Thelockedandenabledflags default tofalse.- Parameters:
firstName- the user's first namelastName- the user's last nameemail- the user's email, which serves as the usernamepassword- the user's encoded passwordappUserRole- the role of the user
-
-
Method Details
-
getAuthorities
Retrieves the authorities (roles) granted to the user.By convention in Spring Security, roles are prefixed with "ROLE_".
- Specified by:
getAuthoritiesin interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
- a collection containing the user's role as a
GrantedAuthority.
-
getPassword
Retrieves the password used to authenticate the user.- Specified by:
getPasswordin interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
- the user's encoded password.
-
getUsername
Retrieves the username used to authenticate the user.In this application, the username is the user's email address.
- Specified by:
getUsernamein interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
- the user's email address.
-
isAccountNonExpired
public boolean isAccountNonExpired()Indicates whether the user's account has expired.This implementation always returns
true, meaning the account never expires.- Specified by:
isAccountNonExpiredin interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
trueif the user's account is valid (i.e., not expired),falseotherwise.
-
isAccountNonLocked
public boolean isAccountNonLocked()Indicates whether the user is locked or unlocked.- Specified by:
isAccountNonLockedin interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
trueif the user is not locked,falseotherwise.
-
isCredentialsNonExpired
public boolean isCredentialsNonExpired()Indicates whether the user's credentials (password) have expired.This implementation always returns
true, meaning credentials never expire.- Specified by:
isCredentialsNonExpiredin interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
trueif the user's credentials are valid (i.e., not expired),falseotherwise.
-
isEnabled
public boolean isEnabled()Indicates whether the user is enabled or disabled.- Specified by:
isEnabledin interfaceorg.springframework.security.core.userdetails.UserDetails- Returns:
trueif the user is enabled,falseotherwise.
-