Package com.jgcomptech.tools.authc
Class AuthManager
- java.lang.Object
-
- com.jgcomptech.tools.authc.AuthManager
-
public final class AuthManager extends java.lang.Object
Manages all tasks related to a user account including sessions and user roles.- Since:
- 1.5.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExistingRole(UserRole role)
Adds an existing role to the list.boolean
checkPasswordMatches(java.lang.String username, java.lang.String password)
Checks to see if the specified password matches the stored password in the database.java.lang.Object
clone()
UserRole
createRole(java.lang.String name)
Creates a new role and adds it to the list.boolean
createUser(java.lang.String username, java.lang.String password, UserRoleManager.SystemUserRoles userRole)
Creates a new user in the database using BCrypt password hashing.boolean
createUser(java.lang.String username, java.lang.String password, java.lang.String userRole)
Creates a new user in the database using BCrypt password hashing.boolean
deleteUser(java.lang.String username)
Deletes the specified user.void
diableDebugLogging()
Disables basic event handlers with System.Out logging for all session and permission events.boolean
disablePasswordExpiration(java.lang.String username)
Sets the specified user's password to never expire.void
enableDebugLogging()
Enables basic event handlers with System.Out logging for all session and permission events.boolean
equals(java.lang.Object o)
boolean
getAdminOverride(boolean retryLoginOnFailure)
Requests an admin user to authenticate to override permissions using the single session context.java.lang.String
getAppIconPath()
Returns the path to the icon to use for all login dialogs.SessionManager.EventListeners
getEventListeners()
Returns a new instance of the EventListeners class that contains methods for all session related event handlers.static AuthManager
getInstance()
Retrieves the current instance of the AuthManager.@Nullable java.lang.String
getLoggedInUsername()
Returns the username of the currently logged in user under the single session context.@Nullable UserRole
getLoggedInUserRole()
Returns the user role of the currently logged in user under the single user context.LoginErrorMessages
getLoginErrorMessages()
Returns the text to use for the error message when errors occur during login.int
getMaxSessions()
Returns the maximum number of allowed sessions, under the multi session context, before login is disabled.static AuthManager
getNewInstance(Database db)
Creates and retrieves a new instance of the AuthManager with the specified database.static AuthManager
getNewInstance(Database db, java.lang.String appIconPath)
Creates and retrieves a new instance of the AuthManager with the specified parameters.static AuthManager
getNewInstance(Database db, java.lang.String appIconPath, java.lang.String programName)
Creates and retrieves a new instance of the AuthManager with the specified parameters.java.time.LocalDateTime
getPasswordExpirationDate(java.lang.String username)
Returns the specified user's password expiration date as a LocalDateTime object.java.lang.String
getPasswordExpirationDate(java.lang.String username, java.lang.String format)
Returns the specified user's password expiration date as a formatted string.java.lang.String
getProgramName()
Returns the name of the program to use in all login dialogs for the window title.UserRole
getRole(java.lang.String name)
Returns the specified role.java.util.Map<java.lang.String,UserRole>
getRoles()
Returns a list of the current existing roles.Session
getSession()
Returns the current session for the currently logged in username under the single session context.Session
getSession(java.lang.String username)
Returns the current session for the specified username under the single session context.Session
getSession(java.lang.String username, boolean multiSession)
Returns the current session for the specified username, under the specified context.SessionManager
getSessionManager()
Returns the instance of the Session Manager.java.util.Map<java.lang.String,Session>
getSessions()
Returns the current logged in sessions under the multi session context.int
getSessionsCount()
Returns the current number of logged in sessions under the multi session context.Subject
getSubject()
Returns the current instance of the Subject object for user session/roles/permissions management.UserAccount
getUser(java.lang.String username)
Returns a UserAccount object representing the specified username.java.time.LocalDateTime
getUserCreationDate(java.lang.String username)
Returns the date and time the user was initially created.java.lang.String
getUserCreationDate(java.lang.String username, java.lang.String format)
Returns the date and time the user was initially created as a formatted string.UserManager
getUserManager()
Returns the instance of the User Manager.java.util.HashSet<java.lang.String>
getUsernameList()
Returns a list of the usernames in the database.UserRole
getUserRole(java.lang.String username)
Returns user role for the specified username.UserRoleManager
getUserRoleManager()
Returns the instance of the User Role Manager.java.util.HashSet<UserAccount>
getUsersList()
Returns a list of user accounts.boolean
getUserVerification(boolean retryLoginOnFailure)
Requests that the currently logged in username to re-login using the single session context.int
hashCode()
boolean
isAdminLoggedIn()
Returns true if an admin user is currently logged in under the single user context.boolean
isPasswordExpired(java.lang.String username)
Returnstrue
if the specified user's password is expired and thus cannot be used to login.boolean
isPasswordSetToExpire(java.lang.String username)
Returnstrue
if the specified user's password has a set expiration date.boolean
isUserLocked(java.lang.String username)
Returnstrue
if the specified user is locked and thus cannot be used to login.boolean
isUserLoggedIn()
Returns true if a username is logged in under the single session context.boolean
isUserLoggedIn(java.lang.String username)
Returns true if the specified username is logged in under the single session context.boolean
isUserLoggedIn(java.lang.String username, boolean multiSession)
Returns true if the specified username is logged in under the specified context.boolean
lockUser(java.lang.String username)
Locks the specified user preventing use in login.boolean
loginUser(java.lang.String username)
Logs in a user under the single session context with the specified username, no password checking is used.boolean
loginUser(java.lang.String username, boolean multiSession)
Logs in a user, under the specified context, with the specified username, no password checking is used.boolean
logoutUser()
Logs out the currently logged in user from the single session context and clears any set permissions.boolean
logoutUser(java.lang.String username)
Logs out the specified user from the single session context and clears any set permissions.boolean
logoutUser(java.lang.String username, boolean multiSession)
Logs out the specified user, under the specified context, and, if in single session context, clears any set permissions.boolean
requireAdmin()
Checks that the logged in user, under the single session context, is an admin and if false, requests an admin override.boolean
requireAndVerifyAdmin()
Checks that the logged in user, under the single session context, is an admin, if true, prompts the admin to re-login and if false, requests an admin override.void
setAppIconPath(java.lang.String appIconPath)
Sets the path to the icon to use for all login dialogs.void
setLoginErrorMessages(LoginErrorMessages loginErrorMessages)
Sets the text to use for the error message when when errors occur during login.void
setMaxSessions(int maxSessions)
Sets the maximum number of allowed sessions, under the multi session context, before login is disabled.boolean
setPassword(java.lang.String username, java.lang.String password)
Sets a new password for an existing user using BCrypt password hashing.boolean
setPasswordExpirationDate(java.lang.String username, java.time.LocalDateTime dateTime)
Sets the specified user's password to expire preventing login after the specified date and time.void
setProgramName(java.lang.String programName)
Sets the name of the program to use in all login dialogs for the window title.boolean
setUserRole(java.lang.String username, UserRoleManager.SystemUserRoles userRole)
Sets the user role of the specified user.boolean
setUserRole(java.lang.String username, java.lang.String userRole)
Sets the user role of the specified user.boolean
showLoginWindow(boolean retryLoginOnFailure)
Shows the login dialog window to log a user into the single session context.java.lang.String
toString()
boolean
unlockUser(java.lang.String username)
Unlocks the specified user allowing use in login.boolean
userExists(java.lang.String username)
Checks if the specified username exists in the database.boolean
userHasPermission(java.lang.String username, java.lang.String permissionName)
Checks if the specified username has the specified permission.boolean
userHasPermissions(java.lang.String username, java.lang.String... permissionNames)
Checks if the specified username has ALL the specified permissions.boolean
userHasPermissions(java.lang.String username, java.util.HashSet<java.lang.String> permissionNames)
Checks if the specified username has ALL the specified permissions.
-
-
-
Method Detail
-
getInstance
public static AuthManager getInstance()
Retrieves the current instance of the AuthManager.- Returns:
- the current instance of the AuthManager
- Throws:
java.lang.IllegalStateException
- if the getNewInstance method has not been called. This is required to initialize the database.
-
getNewInstance
public static AuthManager getNewInstance(Database db)
Creates and retrieves a new instance of the AuthManager with the specified database.- Parameters:
db
- the database for storing all user account information- Returns:
- a new instance of the AuthManager
-
getNewInstance
public static AuthManager getNewInstance(Database db, java.lang.String appIconPath)
Creates and retrieves a new instance of the AuthManager with the specified parameters.- Parameters:
db
- the database for storing all user account informationappIconPath
- the path to the icon to use in all login dialogs- Returns:
- a new instance of the AuthManager
-
getNewInstance
public static AuthManager getNewInstance(Database db, java.lang.String appIconPath, java.lang.String programName)
Creates and retrieves a new instance of the AuthManager with the specified parameters.- Parameters:
db
- the database for storing all user account informationappIconPath
- the path to the icon to use in all login dialogsprogramName
- the name of the program to use in the title bar on all login dialogs- Returns:
- a new instance of the AuthManager
- Throws:
UserManagerException
- if an error occurs while creating the users table
-
getSubject
public Subject getSubject()
Returns the current instance of the Subject object for user session/roles/permissions management.- Returns:
- the current instance of the Subject object
-
createUser
public boolean createUser(java.lang.String username, java.lang.String password, UserRoleManager.SystemUserRoles userRole)
Creates a new user in the database using BCrypt password hashing.- Parameters:
username
- the username to addpassword
- the password for the new useruserRole
- the system user role for the new user- Returns:
- true if user creation is successful
- Throws:
java.lang.IllegalArgumentException
- if values are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs while creating the userPasswordHashingFailedException
- if an error occurs while hashing the password
-
createUser
public boolean createUser(java.lang.String username, java.lang.String password, java.lang.String userRole)
Creates a new user in the database using BCrypt password hashing.- Parameters:
username
- the username to addpassword
- the password for the new useruserRole
- the name of the user role for the new user- Returns:
- true if user creation is successful
- Throws:
java.lang.IllegalArgumentException
- if values are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs while creating the userPasswordHashingFailedException
- if an error occurs while hashing the password
-
deleteUser
public boolean deleteUser(java.lang.String username)
Deletes the specified user.- Parameters:
username
- the username of the user to delete- Returns:
- true if no errors occur
- Throws:
java.lang.IllegalArgumentException
- if username is null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs while deleting user
-
getUser
public UserAccount getUser(java.lang.String username)
Returns a UserAccount object representing the specified username.- Parameters:
username
- the username to lookup- Returns:
- a UserAccount object representing the specified username
- Throws:
java.lang.IllegalArgumentException
- if username is null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
getUserCreationDate
public java.time.LocalDateTime getUserCreationDate(java.lang.String username)
Returns the date and time the user was initially created.- Parameters:
username
- the username to lookup- Returns:
- the date and time the user was initially created as a LocalDateTime object
- Throws:
java.lang.IllegalArgumentException
- if username is null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
getUserCreationDate
public java.lang.String getUserCreationDate(java.lang.String username, java.lang.String format)
Returns the date and time the user was initially created as a formatted string.- Parameters:
username
- the username to lookupformat
- the pattern to use to format the timestamp- Returns:
- the date and time the user was initially created as a formatted string
- Throws:
java.lang.IllegalArgumentException
- if parameters are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
isUserLocked
public boolean isUserLocked(java.lang.String username)
Returnstrue
if the specified user is locked and thus cannot be used to login.- Parameters:
username
- the username to lookup- Returns:
true
if the specified user is locked and thus cannot be used to login- Throws:
java.lang.IllegalArgumentException
- if the username is null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
lockUser
public boolean lockUser(java.lang.String username)
Locks the specified user preventing use in login.- Parameters:
username
- the username to lookup- Returns:
- true if no errors occur
- Throws:
java.lang.IllegalArgumentException
- if the username is null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
unlockUser
public boolean unlockUser(java.lang.String username)
Unlocks the specified user allowing use in login.- Parameters:
username
- the username to lookup- Returns:
- true if no errors occur
- Throws:
java.lang.IllegalArgumentException
- if the username is null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
isPasswordExpired
public boolean isPasswordExpired(java.lang.String username)
Returnstrue
if the specified user's password is expired and thus cannot be used to login.- Parameters:
username
- the username to lookup- Returns:
true
if the specified user's password is expired and thus cannot be used to login- Throws:
java.lang.IllegalArgumentException
- if parameters are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
isPasswordSetToExpire
public boolean isPasswordSetToExpire(java.lang.String username)
Returnstrue
if the specified user's password has a set expiration date.- Parameters:
username
- the username to lookup- Returns:
true
if the specified user's password has a set expiration date- Throws:
java.lang.IllegalArgumentException
- if parameters are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
getPasswordExpirationDate
public java.time.LocalDateTime getPasswordExpirationDate(java.lang.String username)
Returns the specified user's password expiration date as a LocalDateTime object.- Parameters:
username
- the username to lookup- Returns:
- the specified user's password expiration date as a LocalDateTime object
- Throws:
java.lang.IllegalArgumentException
- if parameters are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
getPasswordExpirationDate
public java.lang.String getPasswordExpirationDate(java.lang.String username, java.lang.String format)
Returns the specified user's password expiration date as a formatted string.- Parameters:
username
- the username to lookupformat
- the pattern to use to format the timestamp- Returns:
- the specified user's password expiration date as a formatted string
- Throws:
java.lang.IllegalArgumentException
- if parameters are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
setPasswordExpirationDate
public boolean setPasswordExpirationDate(java.lang.String username, java.time.LocalDateTime dateTime)
Sets the specified user's password to expire preventing login after the specified date and time.- Parameters:
username
- the username to lookupdateTime
- the expiration date and time to set- Returns:
- true if no errors occur
- Throws:
java.lang.IllegalArgumentException
- if parameters are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
disablePasswordExpiration
public boolean disablePasswordExpiration(java.lang.String username)
Sets the specified user's password to never expire.- Parameters:
username
- the username to lookup- Returns:
- true if no errors occur
- Throws:
java.lang.IllegalArgumentException
- if parameters are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
userExists
public boolean userExists(java.lang.String username)
Checks if the specified username exists in the database.- Parameters:
username
- the username to check- Returns:
- true if the user exists
- Throws:
java.lang.IllegalArgumentException
- if username is null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
getUserRole
public UserRole getUserRole(java.lang.String username)
Returns user role for the specified username.- Parameters:
username
- the username to lookup- Returns:
- the user role
- Throws:
java.lang.IllegalArgumentException
- if username is null or empty or if username does not existTableNotFoundException
- if users table is missingUserManagerException
- if error occurs during lookup
-
setUserRole
public boolean setUserRole(java.lang.String username, UserRoleManager.SystemUserRoles userRole)
Sets the user role of the specified user.- Parameters:
username
- the username of the user to updateuserRole
- the system user role to change to- Returns:
- true if no errors occurred
- Throws:
java.lang.IllegalArgumentException
- if values are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs while changing user role
-
setUserRole
public boolean setUserRole(java.lang.String username, java.lang.String userRole)
Sets the user role of the specified user.- Parameters:
username
- the username of the user to updateuserRole
- the name of the user role to change to- Returns:
- true if no errors occurred
- Throws:
java.lang.IllegalArgumentException
- if values are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs while changing user role
-
setPassword
public boolean setPassword(java.lang.String username, java.lang.String password)
Sets a new password for an existing user using BCrypt password hashing.- Parameters:
username
- the username to changepassword
- the new password- Returns:
- true if password is changed successfully
- Throws:
java.lang.IllegalArgumentException
- if values are null or emptyTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs while changing passwordPasswordHashingFailedException
- if an error occurs while hashing the password
-
checkPasswordMatches
public boolean checkPasswordMatches(java.lang.String username, java.lang.String password)
Checks to see if the specified password matches the stored password in the database.- Parameters:
username
- the username to check againstpassword
- the password to check against- Returns:
- true if the passwords match
- Throws:
java.lang.IllegalArgumentException
- if values are null or empty or if username does not existTableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookupPasswordHashingFailedException
- if an error occurs while hashing the password
-
getUsersList
public java.util.HashSet<UserAccount> getUsersList()
Returns a list of user accounts.- Returns:
- a HashSet of UserAccount objects representing the users in the users table
- Throws:
TableNotFoundException
- if users table is missingUserManagerException
- if an error occurs during lookup
-
getUsernameList
public java.util.HashSet<java.lang.String> getUsernameList()
Returns a list of the usernames in the database.- Returns:
- a list of the usernames in the database
- Throws:
TableNotFoundException
- if users table is missing
-
getUserManager
public UserManager getUserManager()
Returns the instance of the User Manager. Most application programmers won't need to interact with the User Manager directly as all it's methods are included in the Auth Manager.- Returns:
- the instance of the User Manager
-
enableDebugLogging
public void enableDebugLogging()
Enables basic event handlers with System.Out logging for all session and permission events.
-
diableDebugLogging
public void diableDebugLogging()
Disables basic event handlers with System.Out logging for all session and permission events.
-
getAppIconPath
public java.lang.String getAppIconPath()
Returns the path to the icon to use for all login dialogs.- Returns:
- the path to the icon to use for all login dialogs
-
setAppIconPath
public void setAppIconPath(java.lang.String appIconPath)
Sets the path to the icon to use for all login dialogs.- Parameters:
appIconPath
- the icon path to set
-
getProgramName
public java.lang.String getProgramName()
Returns the name of the program to use in all login dialogs for the window title.- Returns:
- the name of the program to use in all login dialogs for the window title
-
setProgramName
public void setProgramName(java.lang.String programName)
Sets the name of the program to use in all login dialogs for the window title.- Parameters:
programName
- the name of the program to set
-
getLoginErrorMessages
public LoginErrorMessages getLoginErrorMessages()
Returns the text to use for the error message when errors occur during login.- Returns:
- the text to use for the error message when errors occur during login
-
setLoginErrorMessages
public void setLoginErrorMessages(LoginErrorMessages loginErrorMessages)
Sets the text to use for the error message when when errors occur during login.- Parameters:
loginErrorMessages
- the error text to set
-
getEventListeners
public SessionManager.EventListeners getEventListeners()
Returns a new instance of the EventListeners class that contains methods for all session related event handlers.- Returns:
- a new instance of the EventListeners class
-
setMaxSessions
public void setMaxSessions(int maxSessions)
Sets the maximum number of allowed sessions, under the multi session context, before login is disabled. The default of -1 removes limit and 0 blocks all new sessions.- Parameters:
maxSessions
- the maximum number of allowed sessions
-
getMaxSessions
public int getMaxSessions()
Returns the maximum number of allowed sessions, under the multi session context, before login is disabled.- Returns:
- the maximum number of allowed sessions
-
getSessionsCount
public int getSessionsCount()
Returns the current number of logged in sessions under the multi session context.- Returns:
- the current number of logged in sessions under the multi session context
-
getSessions
public java.util.Map<java.lang.String,Session> getSessions()
Returns the current logged in sessions under the multi session context.- Returns:
- the current logged in sessions under the multi session context
-
getLoggedInUsername
@Nullable public @Nullable java.lang.String getLoggedInUsername()
Returns the username of the currently logged in user under the single session context.- Returns:
- the username of the currently logged in user under the single session context
-
isUserLoggedIn
public boolean isUserLoggedIn()
Returns true if a username is logged in under the single session context.- Returns:
- true if a username is logged in under the single session context
-
isUserLoggedIn
public boolean isUserLoggedIn(java.lang.String username)
Returns true if the specified username is logged in under the single session context.- Parameters:
username
- the username to lookup- Returns:
- true if the specified username is logged in
-
isUserLoggedIn
public boolean isUserLoggedIn(java.lang.String username, boolean multiSession)
Returns true if the specified username is logged in under the specified context.- Parameters:
username
- the username to lookupmultiSession
- if true uses the multi session context, otherwise the single session context- Returns:
- true if the specified username is logged in
- Since:
- 1.5.0
-
getSession
public Session getSession()
Returns the current session for the currently logged in username under the single session context.- Returns:
- the current session for the currently logged in username
-
getSession
public Session getSession(java.lang.String username)
Returns the current session for the specified username under the single session context.- Parameters:
username
- the username to lookup- Returns:
- the current session for the specified username
-
getSession
public Session getSession(java.lang.String username, boolean multiSession)
Returns the current session for the specified username, under the specified context.- Parameters:
username
- the username to lookupmultiSession
- if true uses the multi session context, otherwise the single session context- Returns:
- the current session for the specified username
- Since:
- 1.5.0
-
loginUser
public boolean loginUser(java.lang.String username)
Logs in a user under the single session context with the specified username, no password checking is used.- Parameters:
username
- the username of the user- Returns:
- false if username does not exist or if session already exists
-
loginUser
public boolean loginUser(java.lang.String username, boolean multiSession)
Logs in a user, under the specified context, with the specified username, no password checking is used.- Parameters:
username
- the username of the usermultiSession
- if true uses the multi session context, otherwise the single session context- Returns:
- false if username does not exist or if session already exists or if multi user and if max sessions is reached or equals 0
- Throws:
java.lang.IllegalStateException
- if the user role is disabledExpiredCredentialsException
- if the user credentials are expiredLockedAccountException
- if the user account is locked- Since:
- 1.5.0
-
logoutUser
public boolean logoutUser()
Logs out the currently logged in user from the single session context and clears any set permissions. NOTE: if user was deleted from the database while logged in, the getUser event method will return null.- Returns:
- false if a session does not exist
-
logoutUser
public boolean logoutUser(java.lang.String username)
Logs out the specified user from the single session context and clears any set permissions. NOTE: if user was deleted from the database while logged in, the getUser event method will return null.- Parameters:
username
- the username of the user- Returns:
- false if the username does not exist or if a session does not exist for the username
-
logoutUser
public boolean logoutUser(java.lang.String username, boolean multiSession)
Logs out the specified user, under the specified context, and, if in single session context, clears any set permissions. NOTE: if user was deleted from the database while logged in, the getUser event method will return null.- Parameters:
username
- the username of the usermultiSession
- if true uses the multi session context, otherwise the single session context- Returns:
- false if the username does not exist or if a session does not exist for the username
- Since:
- 1.5.0
-
showLoginWindow
public boolean showLoginWindow(boolean retryLoginOnFailure)
Shows the login dialog window to log a user into the single session context. Fires either the sessionLoginSuccess or the sessionLoginFailure event allowing the getUser method to be called by the assigned EventHandler. If the user does not exist, getUser will return null.- Parameters:
retryLoginOnFailure
- if true the login dialog will be shown again on failure- Returns:
- true if user logged in successfully and false if cancel button was pressed or login failed
- Since:
- 1.4.1
-
getLoggedInUserRole
@Nullable public @Nullable UserRole getLoggedInUserRole()
Returns the user role of the currently logged in user under the single user context.- Returns:
- the user role of the currently logged in user under the single user context
-
isAdminLoggedIn
public boolean isAdminLoggedIn()
Returns true if an admin user is currently logged in under the single user context.- Returns:
- true if an admin user is currently logged in under the single user context
-
getAdminOverride
public boolean getAdminOverride(boolean retryLoginOnFailure)
Requests an admin user to authenticate to override permissions using the single session context. Fires either the sessionLoginSuccess or the sessionLoginFailure event allowing the getUser method to be called by the assigned EventHandler. If the user does not exist, getUser will return null.- Parameters:
retryLoginOnFailure
- if true the login dialog will be shown again on failure- Returns:
- true if admin override succeeded and false if cancel button was pressed or override failed
- Since:
- 1.4.1
-
getUserVerification
public boolean getUserVerification(boolean retryLoginOnFailure)
Requests that the currently logged in username to re-login using the single session context. Fires either the sessionLoginSuccess or the sessionLoginFailure event allowing the getUser method to be called by the assigned EventHandler. If the user does not exist, getUser will return null.- Parameters:
retryLoginOnFailure
- if true the login dialog will be shown again on failure- Returns:
- true if user verified successfully and false if cancel button was pressed or verification failed
- Since:
- 1.4.1
-
requireAdmin
public boolean requireAdmin()
Checks that the logged in user, under the single session context, is an admin and if false, requests an admin override.- Returns:
- true if admin permissions retrieved successfully
- Since:
- 1.4.1
-
requireAndVerifyAdmin
public boolean requireAndVerifyAdmin()
Checks that the logged in user, under the single session context, is an admin, if true, prompts the admin to re-login and if false, requests an admin override.- Returns:
- true if admin permissions retrieved successfully and admin verification succeeded
- Since:
- 1.4.1
-
getSessionManager
public SessionManager getSessionManager()
Returns the instance of the Session Manager. Most application programmers won't need to interact with the Session Manager directly as all it's methods are included in the Auth Manager.- Returns:
- the instance of the Session Manager
-
createRole
public UserRole createRole(java.lang.String name)
Creates a new role and adds it to the list.- Parameters:
name
- the name of the new role- Returns:
- the new role as a UserRole object
-
addExistingRole
public void addExistingRole(UserRole role)
Adds an existing role to the list.- Parameters:
role
- the role to be added
-
getRoles
public java.util.Map<java.lang.String,UserRole> getRoles()
Returns a list of the current existing roles.- Returns:
- a list of the current existing roles
-
getRole
public UserRole getRole(java.lang.String name)
Returns the specified role.- Parameters:
name
- the name of the user role to return- Returns:
- the specified user role
-
getUserRoleManager
public UserRoleManager getUserRoleManager()
Returns the instance of the User Role Manager. Most application programmers won't need to interact with the User Role Manager directly as all it's methods are included in the Auth Manager.- Returns:
- the instance of the User Role Manager
-
userHasPermission
public boolean userHasPermission(java.lang.String username, java.lang.String permissionName)
Checks if the specified username has the specified permission.- Parameters:
username
- the username to checkpermissionName
- the name of the permission to check- Returns:
- true if the currently assigned username has the specified permission
-
userHasPermissions
public boolean userHasPermissions(java.lang.String username, java.lang.String... permissionNames)
Checks if the specified username has ALL the specified permissions.- Parameters:
username
- the username to checkpermissionNames
- a list of all the names of the permissions to check- Returns:
- true if the currently assigned username has ALL the specified permissions
- Since:
- 1.5.1 new overload
-
userHasPermissions
public boolean userHasPermissions(java.lang.String username, java.util.HashSet<java.lang.String> permissionNames)
Checks if the specified username has ALL the specified permissions.- Parameters:
username
- the username to checkpermissionNames
- a list of all the names of the permissions to check- Returns:
- true if the currently assigned username has ALL the specified permissions
-
clone
@Contract(" -> fail") public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-