Package jmri
Interface PermissionManager
-
- All Known Implementing Classes:
DefaultPermissionManager
public interface PermissionManager
A manager for permissions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
PermissionManager.BadPasswordException
static class
PermissionManager.BadUserOrPasswordException
static interface
PermissionManager.LoginListener
Listener for when the JMRI user login and logout.static class
PermissionManager.RoleAlreadyExistsException
static class
PermissionManager.RoleDoesNotExistException
static class
PermissionManager.UserAlreadyExistsException
static class
PermissionManager.UserDoesNotExistException
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addLoginListener(PermissionManager.LoginListener listener)
Add a login listener.Role
addRole(java.lang.String name)
Add a new role.User
addUser(java.lang.String username, java.lang.String password)
Add a new user.void
changePassword(java.lang.String newPassword, java.lang.String oldPassword)
Change an user's password.boolean
ensureAtLeastPermission(Permission permission, PermissionValue minValue)
Checks if the current user has the permission.java.lang.String
getCurrentUserName()
Get the current username.boolean
hasAtLeastPermission(Permission permission, PermissionValue minValue)
Has the current user permission?boolean
hasAtLeastRemotePermission(java.lang.String sessionId, Permission permission, PermissionValue minValue)
Has the current user of this session permission?boolean
isAGuestUser(java.lang.String username)
Is the user 'username' the guest user?boolean
isAGuestUser(User user)
Is the user 'user' the guest user?boolean
isAllowEmptyPasswords()
Get if empty passwords is allowed.boolean
isCurrentUser(java.lang.String username)
Is the user username the current user?boolean
isCurrentUser(User user)
Is the user 'user' the current user?boolean
isCurrentUserPermittedToChangePassword()
Is the current user allowed to change his password?boolean
isEnabled()
Is the permission manager enabled?boolean
isLoggedIn()
Is an user logged in locally?boolean
isRemotelyLoggedIn(java.lang.String sessionId)
Is an user logged in locally?boolean
login(java.lang.String username, java.lang.String password)
Login locally to JMRI.void
logout()
Logout locally from JMRI.void
registerOwner(PermissionOwner owner)
Register a permission owner.void
registerPermission(Permission permission)
Register a permission.boolean
remoteLogin(java.lang.StringBuilder sessionId, java.util.Locale locale, java.lang.String username, java.lang.String password)
Login remotely to JMRI.void
remoteLogout(java.lang.String sessionId)
Logout remotely from JMRI.void
removeRole(java.lang.String name)
Removes a role.void
removeUser(java.lang.String username)
Removes a role.void
setAllowEmptyPasswords(boolean value)
Set if empty passwords should be allowed.void
setEnabled(boolean enabled)
Set if the permission manager should be enabled or not.void
storePermissionSettings()
Store permission settings.
-
-
-
Method Detail
-
addRole
Role addRole(java.lang.String name) throws PermissionManager.RoleAlreadyExistsException
Add a new role.- Parameters:
name
- the name of the role- Returns:
- the new role
- Throws:
PermissionManager.RoleAlreadyExistsException
- if the role already exists
-
removeRole
void removeRole(java.lang.String name) throws PermissionManager.RoleDoesNotExistException
Removes a role.- Parameters:
name
- the name of the role- Throws:
PermissionManager.RoleDoesNotExistException
- if the role doesn't exist
-
addUser
User addUser(java.lang.String username, java.lang.String password) throws PermissionManager.UserAlreadyExistsException
Add a new user.- Parameters:
username
- the usernamepassword
- the password- Returns:
- the new user
- Throws:
PermissionManager.UserAlreadyExistsException
- if the username already exists
-
removeUser
void removeUser(java.lang.String username) throws PermissionManager.UserDoesNotExistException
Removes a role.- Parameters:
username
- the username- Throws:
PermissionManager.UserDoesNotExistException
- if the user doesn't exist
-
changePassword
void changePassword(java.lang.String newPassword, java.lang.String oldPassword)
Change an user's password.- Parameters:
newPassword
- the new passwordoldPassword
- the old password
-
login
boolean login(java.lang.String username, java.lang.String password)
Login locally to JMRI.- Parameters:
username
- the usernamepassword
- the password- Returns:
- true if login was successful, false otherwise
-
remoteLogin
boolean remoteLogin(java.lang.StringBuilder sessionId, java.util.Locale locale, java.lang.String username, java.lang.String password)
Login remotely to JMRI. This is for the web server, WiThrottle server, and other remote connections.- Parameters:
sessionId
- the session ID. If empty string, a new session ID will be created.locale
- the locale to be used for messages.username
- the usernamepassword
- the password- Returns:
- true if successful, false otherwise
-
logout
void logout()
Logout locally from JMRI.
-
remoteLogout
void remoteLogout(java.lang.String sessionId)
Logout remotely from JMRI. This is for the web server, WiThrottle server, and other remote connections.- Parameters:
sessionId
- the session ID
-
isLoggedIn
boolean isLoggedIn()
Is an user logged in locally?- Returns:
- true if any user except guest is logged in, false otherwise.
-
isRemotelyLoggedIn
boolean isRemotelyLoggedIn(java.lang.String sessionId)
Is an user logged in locally?- Parameters:
sessionId
- the session ID- Returns:
- true if any user except guest is logged in to this session, false otherwise.
-
isCurrentUser
boolean isCurrentUser(java.lang.String username)
Is the user username the current user?- Parameters:
username
- the username to check- Returns:
- true if the current user is username, false otherwise.
-
isCurrentUser
boolean isCurrentUser(User user)
Is the user 'user' the current user?- Parameters:
user
- the user to check- Returns:
- true if the current user is 'user', false otherwise.
-
getCurrentUserName
java.lang.String getCurrentUserName()
Get the current username.- Returns:
- the username of the user that's currently logged in or null if no user is logged in.
-
isCurrentUserPermittedToChangePassword
boolean isCurrentUserPermittedToChangePassword()
Is the current user allowed to change his password?- Returns:
- true if a user has logged in and that user is permitted to change his password, false otherwise
-
isAGuestUser
boolean isAGuestUser(java.lang.String username)
Is the user 'username' the guest user?- Parameters:
username
- the username to check- Returns:
- true if 'username' is the guest user
-
isAGuestUser
boolean isAGuestUser(User user)
Is the user 'user' the guest user?- Parameters:
user
- the user to check- Returns:
- true if 'user' is the guest user
-
addLoginListener
void addLoginListener(PermissionManager.LoginListener listener)
Add a login listener.- Parameters:
listener
- the listener
-
isEnabled
boolean isEnabled()
Is the permission manager enabled?- Returns:
- true if it's enabled, false otherwise.
-
setEnabled
void setEnabled(boolean enabled)
Set if the permission manager should be enabled or not.- Parameters:
enabled
- true if it should be enabled, false otherwise.
-
isAllowEmptyPasswords
boolean isAllowEmptyPasswords()
Get if empty passwords is allowed.- Returns:
- true if empty passwords is allowed, false otherwise.
-
setAllowEmptyPasswords
void setAllowEmptyPasswords(boolean value)
Set if empty passwords should be allowed.- Parameters:
value
- true if empty passwords should be allowed, false otherwise.
-
hasAtLeastPermission
boolean hasAtLeastPermission(Permission permission, PermissionValue minValue)
Has the current user permission?- Parameters:
permission
- the permission to checkminValue
- the minimum value- Returns:
- true if the user has the permission, false otherwise
-
hasAtLeastRemotePermission
boolean hasAtLeastRemotePermission(java.lang.String sessionId, Permission permission, PermissionValue minValue)
Has the current user of this session permission?- Parameters:
sessionId
- the session IDpermission
- the permission to checkminValue
- the minimum value- Returns:
- true if the user has the permission, false otherwise
-
ensureAtLeastPermission
boolean ensureAtLeastPermission(Permission permission, PermissionValue minValue)
Checks if the current user has the permission. If not, show a message dialog if not headless. Otherwise log a message.- Parameters:
permission
- the permission to checkminValue
- the minimum value- Returns:
- true if the user has the permission, false otherwise
-
registerOwner
void registerOwner(PermissionOwner owner)
Register a permission owner.- Parameters:
owner
- the owner
-
registerPermission
void registerPermission(Permission permission)
Register a permission.- Parameters:
permission
- the permission
-
storePermissionSettings
void storePermissionSettings()
Store permission settings.
-
-