Class SecureUserService
java.lang.Object
de.bytestore.hostinger.security.service.SecureUserService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a role to a user.voidSends a broadcast notification to multiple users.count()Returns the count of User objects in the database.voidcreateUser(String nameIO, String passwordIO) Creates a new user with the given name and password.booleandoUserExists(String nameIO) Checks if a user with the given name exists.voidexecuteCreateWebhook(io.jmix.core.event.EntitySavingEvent<User> event) Executes the create webhook for a given User entity saving event.voidexecuteUpdateWebhook(io.jmix.core.event.EntityChangedEvent<User> event) Executes the update webhook for a given User entity changed event.Retrieves a list of new users created within the current month.getSettingsOrEmpty(User userIO, String keyIO) Retrieves the value of a specific setting for a givengetUserById(UUID idIO) Retrieves a user by their unique identifier.getUsernames(List<User> stuffsIO) getUsersByMail(String emailIO) Retrieves a list of users filtered by their email addresses.getUsersByName(String nameIO) Retrieves a list of users by name.getUsersByRole(String roleName) Retrieves a list of users who have the specified role.booleanChecks if a user with the given username has a specific role with the given role code and role type.booleanChecks if the given usernameIO is a valid email address based on the predefined EMAIL_REGEX pattern.voidkillSessions(String nameIO) Kills all active sessions for the given username.voidonApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) voidPurges old user registrations that have not been verified within the allowed time frame.voidregisterUser(String emailIO, String passwordIO) Registers a new user with the provided email and password, sets the user as inactive, saves the user to the data store, and sends a verification email to the user's email address.voidremoveSettings(User userIO, String keyIO) This method removes the settings for a specific key belonging to a user.voidsendVerification(User userIO) Sends a verification email to the specified user.voidsetSettingsOrCreate(User userIO, String keyIO, String valueIO) Sets the value of a specific setting for a given User.booleanverifyUser(UUID parameter) Verifies the user associated with the given parameter.voidwebhooks()
-
Constructor Details
-
SecureUserService
public SecureUserService()
-
-
Method Details
-
onApplicationStarted
@EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) -
registerUser
Registers a new user with the provided email and password, sets the user as inactive, saves the user to the data store, and sends a verification email to the user's email address.- Parameters:
emailIO- The email address of the new user.passwordIO- The password for the new user.
-
purgeOldRegistrations
public void purgeOldRegistrations()Purges old user registrations that have not been verified within the allowed time frame. This method identifies and deletes user entries from the system that are: 1. Marked as not verified. 2. Created earlier than the expiration time based on the maximum allowed verification time. The expiration time is calculated using the current time minus the configuration value specified inregisterSettings.getMaxRegisterVerifyTime(). Logs the number of users deleted and the verification time limit for reference. The deletion process is performed for each user meeting the criteria. -
getUsersByRole
Retrieves a list of users who have the specified role.- Parameters:
roleName- the name of the role to filter users by- Returns:
- a list of users who are associated with the specified role
-
getUserById
Retrieves a user by their unique identifier.- Parameters:
idIO- the unique identifier of the user to be retrieved- Returns:
- an Optional containing the User if found, otherwise an empty Optional
-
verifyUser
Verifies the user associated with the given parameter. If the user is not already verified, the method activates the user and sets their verified status to true.- Parameters:
parameter- the identifier of the user to be verified- Returns:
- true if the user was successfully verified, false if the user does not exist or is already verified
-
getNewUsersByMonth
Retrieves a list of new users created within the current month.- Returns:
- A list of new users.
-
getSettingsOrEmpty
Retrieves the value of a specific setting for a given -
setSettingsOrCreate
Sets the value of a specific setting for a given User. If the UserSettings object does not exist, it creates a new one and saves it to the database.- Parameters:
userIO- the User object for which the setting is being setkeyIO- the key of the settingvalueIO- the value of the setting
-
removeSettings
This method removes the settings for a specific key belonging to a user.- Parameters:
userIO- the User object for which the settings are being removedkeyIO- the key of the setting to be removed
-
getStuffs
-
getUsernames
-
broadcast
Sends a broadcast notification to multiple users.- Parameters:
usersIO- the list of users to send the notification tosubjectIO- the subject of the notificationmessageIO- the message content of the notification
-
doUserExists
Checks if a user with the given name exists.- Parameters:
nameIO- the name of the user to check- Returns:
- true if a user with the given name exists, false otherwise
-
getUsersByName
Retrieves a list of users by name.- Parameters:
nameIO- the name of the users to retrieve- Returns:
- a list of users with the given name
-
createUser
Creates a new user with the given name and password.- Parameters:
nameIO- the name of the userpasswordIO- the password of the user
-
killSessions
Kills all active sessions for the given username.- Parameters:
nameIO- the username for which the sessions should be killed
-
addRole
Adds a role to a user.- Parameters:
usernameIO- the username of the userroleIO- the role code to assigntypeIO- the role type to assign
-
hasRole
Checks if a user with the given username has a specific role with the given role code and role type.- Parameters:
usernameIO- the username of the userroleIO- the role code to checktypeIO- the role type to check- Returns:
- true if the user has the specified role, false otherwise
-
count
Returns the count of User objects in the database.- Returns:
- the count of User objects
-
executeCreateWebhook
Executes the create webhook for a given User entity saving event.- Parameters:
event- the EntitySavingEvent representing the save event for the User entity
-
executeUpdateWebhook
Executes the update webhook for a given User entity changed event.- Parameters:
event- the EntityChangedEvent representing the change in the User entity
-
webhooks
public void webhooks() -
sendVerification
Sends a verification email to the specified user.- Parameters:
userIO- the user object containing user details, including ID and email.
-
isEMail
Checks if the given usernameIO is a valid email address based on the predefined EMAIL_REGEX pattern.- Parameters:
usernameIO- The string input to be validated as an email address.- Returns:
- true if the input string matches the email pattern; false otherwise.
-
getUsersByMail
Retrieves a list of users filtered by their email addresses.- Parameters:
emailIO- the email address to filter users.- Returns:
- a list of users with the specified email address.
-