Package jmri.jmrit.permission
Class DefaultPermissionManager
- java.lang.Object
-
- jmri.jmrit.permission.DefaultPermissionManager
-
- All Implemented Interfaces:
PermissionManager
public class DefaultPermissionManager extends java.lang.Object implements PermissionManager
Default permission manager.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.PermissionManager
PermissionManager.BadPasswordException, PermissionManager.BadUserOrPasswordException, PermissionManager.LoginListener, PermissionManager.RoleAlreadyExistsException, PermissionManager.RoleDoesNotExistException, PermissionManager.UserAlreadyExistsException, PermissionManager.UserDoesNotExistException
-
-
Constructor Summary
Constructors Constructor Description DefaultPermissionManager()
DefaultPermissionManager(DefaultPermissionManager source)
-
Method Summary
All Methods Instance Methods Concrete 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.java.util.Set<PermissionOwner>
getOwners()
java.util.Set<Permission>
getPermissions(PermissionOwner owner)
java.util.Collection<Role>
getRoles()
DefaultPermissionManager
getTemporaryInstance()
Return a copy of this PermissionManager.java.util.Collection<DefaultUser>
getUsers()
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?(package private) DefaultPermissionManager
init()
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.
-
-
-
Constructor Detail
-
DefaultPermissionManager
DefaultPermissionManager()
-
DefaultPermissionManager
DefaultPermissionManager(DefaultPermissionManager source)
-
-
Method Detail
-
getTemporaryInstance
public DefaultPermissionManager getTemporaryInstance()
Return a copy of this PermissionManager.- Returns:
- the copy
-
init
DefaultPermissionManager init()
-
getUsers
public java.util.Collection<DefaultUser> getUsers()
-
getOwners
public java.util.Set<PermissionOwner> getOwners()
-
getPermissions
public java.util.Set<Permission> getPermissions(PermissionOwner owner)
-
storePermissionSettings
public void storePermissionSettings()
Description copied from interface:PermissionManager
Store permission settings.- Specified by:
storePermissionSettings
in interfacePermissionManager
-
addRole
public Role addRole(java.lang.String name) throws PermissionManager.RoleAlreadyExistsException
Description copied from interface:PermissionManager
Add a new role.- Specified by:
addRole
in interfacePermissionManager
- Parameters:
name
- the name of the role- Returns:
- the new role
- Throws:
PermissionManager.RoleAlreadyExistsException
- if the role already exists
-
removeRole
public void removeRole(java.lang.String name) throws PermissionManager.RoleDoesNotExistException
Description copied from interface:PermissionManager
Removes a role.- Specified by:
removeRole
in interfacePermissionManager
- Parameters:
name
- the name of the role- Throws:
PermissionManager.RoleDoesNotExistException
- if the role doesn't exist
-
addUser
public User addUser(java.lang.String username, java.lang.String password) throws PermissionManager.UserAlreadyExistsException
Description copied from interface:PermissionManager
Add a new user.- Specified by:
addUser
in interfacePermissionManager
- Parameters:
username
- the usernamepassword
- the password- Returns:
- the new user
- Throws:
PermissionManager.UserAlreadyExistsException
- if the username already exists
-
removeUser
public void removeUser(java.lang.String username) throws PermissionManager.UserDoesNotExistException
Description copied from interface:PermissionManager
Removes a role.- Specified by:
removeUser
in interfacePermissionManager
- Parameters:
username
- the username- Throws:
PermissionManager.UserDoesNotExistException
- if the user doesn't exist
-
changePassword
public void changePassword(java.lang.String newPassword, java.lang.String oldPassword)
Description copied from interface:PermissionManager
Change an user's password.- Specified by:
changePassword
in interfacePermissionManager
- Parameters:
newPassword
- the new passwordoldPassword
- the old password
-
login
public boolean login(java.lang.String username, java.lang.String password)
Description copied from interface:PermissionManager
Login locally to JMRI.- Specified by:
login
in interfacePermissionManager
- Parameters:
username
- the usernamepassword
- the password- Returns:
- true if login was successful, false otherwise
-
remoteLogin
public boolean remoteLogin(java.lang.StringBuilder sessionId, java.util.Locale locale, java.lang.String username, java.lang.String password)
Description copied from interface:PermissionManager
Login remotely to JMRI. This is for the web server, WiThrottle server, and other remote connections.- Specified by:
remoteLogin
in interfacePermissionManager
- 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
public void logout()
Description copied from interface:PermissionManager
Logout locally from JMRI.- Specified by:
logout
in interfacePermissionManager
-
remoteLogout
public void remoteLogout(java.lang.String sessionId)
Description copied from interface:PermissionManager
Logout remotely from JMRI. This is for the web server, WiThrottle server, and other remote connections.- Specified by:
remoteLogout
in interfacePermissionManager
- Parameters:
sessionId
- the session ID
-
isLoggedIn
public boolean isLoggedIn()
Description copied from interface:PermissionManager
Is an user logged in locally?- Specified by:
isLoggedIn
in interfacePermissionManager
- Returns:
- true if any user except guest is logged in, false otherwise.
-
isRemotelyLoggedIn
public boolean isRemotelyLoggedIn(java.lang.String sessionId)
Description copied from interface:PermissionManager
Is an user logged in locally?- Specified by:
isRemotelyLoggedIn
in interfacePermissionManager
- Parameters:
sessionId
- the session ID- Returns:
- true if any user except guest is logged in to this session, false otherwise.
-
isCurrentUser
public boolean isCurrentUser(java.lang.String username)
Description copied from interface:PermissionManager
Is the user username the current user?- Specified by:
isCurrentUser
in interfacePermissionManager
- Parameters:
username
- the username to check- Returns:
- true if the current user is username, false otherwise.
-
isCurrentUser
public boolean isCurrentUser(User user)
Description copied from interface:PermissionManager
Is the user 'user' the current user?- Specified by:
isCurrentUser
in interfacePermissionManager
- Parameters:
user
- the user to check- Returns:
- true if the current user is 'user', false otherwise.
-
getCurrentUserName
public java.lang.String getCurrentUserName()
Description copied from interface:PermissionManager
Get the current username.- Specified by:
getCurrentUserName
in interfacePermissionManager
- Returns:
- the username of the user that's currently logged in or null if no user is logged in.
-
isAGuestUser
public boolean isAGuestUser(java.lang.String username)
Description copied from interface:PermissionManager
Is the user 'username' the guest user?- Specified by:
isAGuestUser
in interfacePermissionManager
- Parameters:
username
- the username to check- Returns:
- true if 'username' is the guest user
-
isAGuestUser
public boolean isAGuestUser(User user)
Description copied from interface:PermissionManager
Is the user 'user' the guest user?- Specified by:
isAGuestUser
in interfacePermissionManager
- Parameters:
user
- the user to check- Returns:
- true if 'user' is the guest user
-
isCurrentUserPermittedToChangePassword
public boolean isCurrentUserPermittedToChangePassword()
Description copied from interface:PermissionManager
Is the current user allowed to change his password?- Specified by:
isCurrentUserPermittedToChangePassword
in interfacePermissionManager
- Returns:
- true if a user has logged in and that user is permitted to change his password, false otherwise
-
addLoginListener
public void addLoginListener(PermissionManager.LoginListener listener)
Description copied from interface:PermissionManager
Add a login listener.- Specified by:
addLoginListener
in interfacePermissionManager
- Parameters:
listener
- the listener
-
isEnabled
public boolean isEnabled()
Description copied from interface:PermissionManager
Is the permission manager enabled?- Specified by:
isEnabled
in interfacePermissionManager
- Returns:
- true if it's enabled, false otherwise.
-
setEnabled
public void setEnabled(boolean enabled)
Description copied from interface:PermissionManager
Set if the permission manager should be enabled or not.- Specified by:
setEnabled
in interfacePermissionManager
- Parameters:
enabled
- true if it should be enabled, false otherwise.
-
isAllowEmptyPasswords
public boolean isAllowEmptyPasswords()
Description copied from interface:PermissionManager
Get if empty passwords is allowed.- Specified by:
isAllowEmptyPasswords
in interfacePermissionManager
- Returns:
- true if empty passwords is allowed, false otherwise.
-
setAllowEmptyPasswords
public void setAllowEmptyPasswords(boolean value)
Description copied from interface:PermissionManager
Set if empty passwords should be allowed.- Specified by:
setAllowEmptyPasswords
in interfacePermissionManager
- Parameters:
value
- true if empty passwords should be allowed, false otherwise.
-
hasAtLeastPermission
public boolean hasAtLeastPermission(Permission permission, PermissionValue minValue)
Description copied from interface:PermissionManager
Has the current user permission?- Specified by:
hasAtLeastPermission
in interfacePermissionManager
- Parameters:
permission
- the permission to checkminValue
- the minimum value- Returns:
- true if the user has the permission, false otherwise
-
hasAtLeastRemotePermission
public boolean hasAtLeastRemotePermission(java.lang.String sessionId, Permission permission, PermissionValue minValue)
Description copied from interface:PermissionManager
Has the current user of this session permission?- Specified by:
hasAtLeastRemotePermission
in interfacePermissionManager
- Parameters:
sessionId
- the session IDpermission
- the permission to checkminValue
- the minimum value- Returns:
- true if the user has the permission, false otherwise
-
ensureAtLeastPermission
public boolean ensureAtLeastPermission(Permission permission, PermissionValue minValue)
Description copied from interface:PermissionManager
Checks if the current user has the permission. If not, show a message dialog if not headless. Otherwise log a message.- Specified by:
ensureAtLeastPermission
in interfacePermissionManager
- Parameters:
permission
- the permission to checkminValue
- the minimum value- Returns:
- true if the user has the permission, false otherwise
-
registerOwner
public void registerOwner(PermissionOwner owner)
Description copied from interface:PermissionManager
Register a permission owner.- Specified by:
registerOwner
in interfacePermissionManager
- Parameters:
owner
- the owner
-
registerPermission
public void registerPermission(Permission permission)
Description copied from interface:PermissionManager
Register a permission.- Specified by:
registerPermission
in interfacePermissionManager
- Parameters:
permission
- the permission
-
-