Package tv.phantombot.panel.PanelUser
Class PanelUserHandler
java.lang.Object
tv.phantombot.panel.PanelUser.PanelUserHandler
Panel user
management for the web panel and websocket- Author:
- Sartharon
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Messages for use as responses to the web panelstatic enum
Panel user
web panel and websocket permission -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchangePassword
(String username, String currentPassword, String newPassword) Changes apanel user's
password
Only existing andeditable
panel users
can have their password changedstatic PanelUser
checkAuthTokenAndGetUser
(String authToken) Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket by his authentication tokenstatic boolean
checkLogin
(String username, String password) Checks if thepanel user
is allowed to logon to the web panel and/or use the websocketstatic boolean
checkLogin
(String username, String password, String requestUri) Checks if thepanel user
is allowed to logon to the web panel and/or use the websocketstatic PanelUser
checkLoginAndGetUser
(String username, String password) Checks if thepanel user
is allowed to logon to the web panel and/or use the websocketstatic PanelUser
checkLoginAndGetUser
(String username, String password, String requestUri) Checks if thepanel user
is allowed to logon to the web panel and/or use the websocketstatic PanelUser
checkLoginAndGetUserB64
(String base64Token, String requestUri) Checks if thepanel user
is allowed to logon to the web panel and/or use the websocketstatic boolean
checkLoginB64
(String base64Token, String requestUri) Checks if thepanel user
is allowed to logon to the web panel and/or use the websocketstatic boolean
checkPanelUserCommandAccess
(PanelUser user, String command, String section) Checks if a user is allowed to send a command to the bots modulesstatic boolean
checkPanelUserDatabaseAccess
(PanelUser user, String tableName, String section, boolean isWriteAction) Checks if a user is allowed to access a database tablestatic boolean
checkPanelUserScriptAccess
(PanelUser user, String script, String[] args, String section) Checks if a user is allowed send websocket events to a specific scriptstatic boolean
checkPanelUserSectionAccess
(PanelUser user, String section, boolean isWriteAction) Checks if a user has to access apanel section
createNewUser
(String username, boolean enabled) Creates a newpanel user
with full accesspermissions
to all panel sections if the user does not existcreateNewUser
(String username, Map<String, PanelUserHandler.Permission> permissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) Creates a newpanel user
if the user does not existcreateNewUser
(String username, JSONArray jsoPermissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) Creates a newpanel user
if the user does not existdeleteUser
(String username) editUser
(String currentUsername, String newUsername, Map<String, PanelUserHandler.Permission> permissions, boolean enabled) editUser
(String currentUsername, String newUsername, Map<String, PanelUserHandler.Permission> permissions, boolean enabled, Boolean canManageUsers, Boolean canRestartBot) editUser
(String currentUsername, String newUsername, JSONArray jsoPermissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) static Map<String,
PanelUserHandler.Permission> getAccessPermissions
(boolean full) Gets a permissions map which includes permission to all availablepanel sections
static void
getAllPanelSectionsJSONObject
(JSONStringer jsonObject) Adds the availablepanel sections
as an array to anJSONStringer
instancestatic void
getAllUsersJSONObject
(JSONStringer jsonObject) Adds thepanel users
safe properties (username, isEnabled,permissions
, creationDate, lastLogin) as an array to anJSONStringer
instancestatic Map<String,
PanelUserHandler.Permission> Gets a permissions map which includes full permission to all availablepanel sections
static void
getPermissionsJSONObject
(JSONStringer jsonObject) Adds thepermissions
as an array to anJSONStringer
instancestatic String
getUserAuthToken
(String username) Get the authentication token for apanel user
static void
getUserJSONObject
(String username, JSONStringer jsonObject) Adds thepanel user's
safe properties (username, isEnabled,permissions
, hasSetPassword,userType) as an array to an {@link JSONStringer JSONStringer} instance
resetPassword
(String username) Resets apanel user's
password
Only existing andeditable
panel users
can have their passwords resetstatic String
sectionConvert
(String section) Checks for alternate section names and converts them to standard section names
-
Constructor Details
-
PanelUserHandler
public PanelUserHandler()
-
-
Method Details
-
checkLoginB64
Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket- Parameters:
base64Token
- The user's login token in base64 from the HTTP-HeadersrequestUri
- The requested uri- Returns:
true
if the token is valid, the user is enabled and the user is allowed to access the uri;false
otherwise- See Also:
-
checkLoginAndGetUserB64
Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket- Parameters:
base64Token
- The user's login token in base64 from the HTTP-HeadersrequestUri
- The requested uri- Returns:
- A
PanelUser
if the user exists, is enabled and is allowed to access the uri;null
otherwise - See Also:
-
checkLogin
Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket- Parameters:
username
- The user's usernamepassword
- The user's password- Returns:
true
if the exists and is enabled;false
otherwise- See Also:
-
checkLoginAndGetUser
Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket- Parameters:
username
- The user's usernamepassword
- The user's password- Returns:
- A
PanelUser
if the user exists, is enabled and is allowed to access the uri;null
otherwise - See Also:
-
checkLogin
Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket- Parameters:
username
- The user's usernamepassword
- The user's passwordrequestUri
- The requested uri- Returns:
true
if the user exists, is enabled and is allowed to access the uri;false
otherwise- See Also:
-
checkLoginAndGetUser
Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket- Parameters:
username
- The user's usernamepassword
- The user's passwordrequestUri
- The requested uri- Returns:
- A
PanelUser
if the user exists, is enabled and is allowed to access the uri;null
otherwise - See Also:
-
checkAuthTokenAndGetUser
Checks if thepanel user
is allowed to logon to the web panel and/or use the websocket by his authentication token- Parameters:
authToken
- The user's authentication token- Returns:
- A
PanelUser
if a user with that authentication token exists and is enabled;null
otherwise - See Also:
-
getUserAuthToken
Get the authentication token for apanel user
- Parameters:
username
- The user's username- Returns:
- The user's websocket authentication token if the user exists and is
enabled;
null
otherwise - See Also:
-
token generation
token usage
exists
PanelUser.isEnabled()
-
changePassword
public static PanelUserHandler.PanelMessage changePassword(String username, String currentPassword, String newPassword) Changes apanel user's
password
Only existing andeditable
panel users
can have their password changed- Parameters:
username
-currentPassword
-newPassword
-- Returns:
- The fitting
panel message
- See Also:
-
createNewUser
Creates a newpanel user
with full accesspermissions
to all panel sections if the user does not exist- Parameters:
username
- The user's nameenabled
-true
if the user should be enabled;false
otherwise- Returns:
- The fitting
panel message
- See Also:
-
User Creation
exists
-
createNewUser
public static PanelUserHandler.PanelMessage createNewUser(String username, JSONArray jsoPermissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) Creates a newpanel user
if the user does not exist- Parameters:
username
- The user's namepermission
- The user'spermissions display name
enabled
-true
if the user should be enabled;false
otherwisecanManageUsers
-true
to allow the user to manage other users;false
to prohibit thiscanRestartBot
-true
to allow the user to restart the bot via the panel;false
to prohibit this- Returns:
- The fitting
panel message
- See Also:
-
User Creation
exists
-
createNewUser
public static PanelUserHandler.PanelMessage createNewUser(String username, Map<String, PanelUserHandler.Permission> permissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) Creates a newpanel user
if the user does not exist- Parameters:
username
- The user's namepermission
- The user'spermissions
enabled
-true
if the user should be enabled;false
otherwisecanManageUsers
-true
to allow the user to manage other users;false
to prohibit thiscanRestartBot
-true
to allow the user to restart the bot via the panel;false
to prohibit this- Returns:
- The fitting
panel message
- See Also:
-
User Creation
exists
-
deleteUser
- Parameters:
username
- The user's name which should be deleted- Returns:
- The fitting
panel message
- See Also:
-
User deletion
exists
-
editUser
public static PanelUserHandler.PanelMessage editUser(String currentUsername, String newUsername, JSONArray jsoPermissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) - Parameters:
currentUsername
- The user's name which should be editednewUsername
- The user's new name;null
to not change the usernamepermission
- The user's newpermissions
;null
to not change thepermission
enabled
-true
to enable the user;false
to disable the usercanManageUsers
-true
to allow the user to manage other users;false
to prohibit thiscanRestartBot
-true
to allow the user to restart the bot via the panel;false
to prohibit this- Returns:
- The fitting
panel message
- See Also:
-
editUser
public static PanelUserHandler.PanelMessage editUser(String currentUsername, String newUsername, Map<String, PanelUserHandler.Permission> permissions, boolean enabled, Boolean canManageUsers, Boolean canRestartBot) - Parameters:
currentUsername
- The user's name which should be editednewUsername
- The user's new name;null
to not change the usernamepermission
- The user's newpermission
;null
to not change thepermissions
enabled
-true
to enable the user;false
to disable the usercanManageUsers
-true
to allow the user to manage other users;false
to prohibit thiscanRestartBot
-true
to allow the user to restart the bot via the panel;false
to prohibit this- Returns:
- The fitting
panel message
- See Also:
-
editUser
public static PanelUserHandler.PanelMessage editUser(String currentUsername, String newUsername, Map<String, PanelUserHandler.Permission> permissions, boolean enabled) - Parameters:
currentUsername
- The user's name which should be editednewUsername
- The user's new name;null
to not change the usernamepermission
- The user's newpermission
;null
to not change thepermissions
enabled
-true
to enable the user;false
to disable the user- Returns:
- The fitting
panel message
- See Also:
-
resetPassword
Resets apanel user's
password
Only existing andeditable
panel users
can have their passwords reset- Parameters:
username
- The user's name who's password should be reset- Returns:
- The new random password
- See Also:
-
exists
password generation
-
getAllUsersJSONObject
Adds thepanel users
safe properties (username, isEnabled,permissions
, creationDate, lastLogin) as an array to anJSONStringer
instance- Parameters:
jsonObject
- TheJSONStringer
instance to which the array should be added to- See Also:
-
getPermissionsJSONObject
Adds thepermissions
as an array to anJSONStringer
instance- Parameters:
jsonObject
- TheJSONStringer
instance to which thepermissions
array should be added to
-
getUserJSONObject
Adds thepanel user's
safe properties (username, isEnabled,permissions
, hasSetPassword,userType) as an array to an {@link JSONStringer JSONStringer} instance
- Parameters:
username
- The user's name which properties should be returnedjsonObject
- TheJSONStringer
instance to which the user's properties should be added to- See Also:
-
getAllPanelSectionsJSONObject
Adds the availablepanel sections
as an array to anJSONStringer
instance- Parameters:
jsonObject
- TheJSONStringer
instance to which thepanel sections
should be added to
-
getFullAccessPermissions
Gets a permissions map which includes full permission to all availablepanel sections
-
getAccessPermissions
Gets a permissions map which includes permission to all availablepanel sections
- Parameters:
full
-true
forPanelUserHandler.Permission.READ_WRITE
; otherwisePanelUserHandler.Permission.READ_ONLY
-
checkPanelUserDatabaseAccess
public static boolean checkPanelUserDatabaseAccess(PanelUser user, String tableName, String section, boolean isWriteAction) Checks if a user is allowed to access a database table- Parameters:
user
- Theuser
tablename
- The tableName to be checkedsection
- Thepanel section
on which this request was createdisWriteAction
- Indicates if the action is an action requiringwrite permissions
- Returns:
true
if the user is allowed to access the table under the conditions;false
otherwise
-
sectionConvert
Checks for alternate section names and converts them to standard section names- Parameters:
section
- The section to check- Returns:
- The normalized section name, in lower case
-
checkPanelUserScriptAccess
public static boolean checkPanelUserScriptAccess(PanelUser user, String script, String[] args, String section) Checks if a user is allowed send websocket events to a specific script- Parameters:
user
- Theuser
script
- The script path being accessedsection
- Thepanel section
on which this request was created- Returns:
true
if the user is allowed to access the table under the conditions;false
otherwise
-
checkPanelUserSectionAccess
public static boolean checkPanelUserSectionAccess(PanelUser user, String section, boolean isWriteAction) Checks if a user has to access apanel section
- Parameters:
user
- Theuser
section
- Thepanel section
on which this request was createdisWriteAction
- Indicates if the action is an action requiringwrite permissions
- Returns:
true
if the user is allowed to access the table under the conditions;false
otherwise
-
checkPanelUserCommandAccess
Checks if a user is allowed to send a command to the bots modules- Parameters:
user
- Theuser
command
- The command which has been sent by the user through the panelsection
- Thepanel section
on which this request was created- Returns:
true
if the user is allowed to access the table under the conditions;false
otherwise
-