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 enumMessages for use as responses to the web panelstatic enumPanel userweb panel and websocket permission -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchangePassword(String username, String currentPassword, String newPassword) Changes apanel user'spassword
Only existing andeditablepanel userscan have their password changedstatic PanelUsercheckAuthTokenAndGetUser(String authToken) Checks if thepanel useris allowed to logon to the web panel and/or use the websocket by his authentication tokenstatic booleancheckLogin(String username, String password) Checks if thepanel useris allowed to logon to the web panel and/or use the websocketstatic booleancheckLogin(String username, String password, String requestUri) Checks if thepanel useris allowed to logon to the web panel and/or use the websocketstatic PanelUsercheckLoginAndGetUser(String username, String password) Checks if thepanel useris allowed to logon to the web panel and/or use the websocketstatic PanelUsercheckLoginAndGetUser(String username, String password, String requestUri) Checks if thepanel useris allowed to logon to the web panel and/or use the websocketstatic PanelUsercheckLoginAndGetUserB64(String base64Token, String requestUri) Checks if thepanel useris allowed to logon to the web panel and/or use the websocketstatic booleancheckLoginB64(String base64Token, String requestUri) Checks if thepanel useris allowed to logon to the web panel and/or use the websocketstatic booleancheckPanelUserCommandAccess(PanelUser user, String command, String section) Checks if a user is allowed to send a command to the bots modulesstatic booleancheckPanelUserDatabaseAccess(PanelUser user, String tableName, String section, boolean isWriteAction) Checks if a user is allowed to access a database tablestatic booleancheckPanelUserScriptAccess(PanelUser user, String script, String[] args, String section) Checks if a user is allowed send websocket events to a specific scriptstatic booleancheckPanelUserSectionAccess(PanelUser user, String section, boolean isWriteAction) Checks if a user has to access apanel sectioncreateNewUser(String username, boolean enabled) Creates a newpanel userwith full accesspermissionsto 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 userif the user does not existcreateNewUser(String username, JSONArray jsoPermissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) Creates a newpanel userif 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 sectionsstatic voidgetAllPanelSectionsJSONObject(JSONStringer jsonObject) Adds the availablepanel sectionsas an array to anJSONStringerinstancestatic voidgetAllUsersJSONObject(JSONStringer jsonObject) Adds thepanel userssafe properties (username, isEnabled,permissions, creationDate, lastLogin) as an array to anJSONStringerinstancestatic Map<String,PanelUserHandler.Permission> Gets a permissions map which includes full permission to all availablepanel sectionsstatic voidgetPermissionsJSONObject(JSONStringer jsonObject) Adds thepermissionsas an array to anJSONStringerinstancestatic StringgetUserAuthToken(String username) Get the authentication token for apanel userstatic voidgetUserJSONObject(String username, JSONStringer jsonObject) Adds thepanel user'ssafe properties (username, isEnabled,permissions, hasSetPassword,userType) as an array to an {@link JSONStringer JSONStringer} instanceresetPassword(String username) Resets apanel user'spassword
Only existing andeditablepanel userscan have their passwords resetstatic StringsectionConvert(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 useris 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:
trueif the token is valid, the user is enabled and the user is allowed to access the uri;falseotherwise- See Also:
-
checkLoginAndGetUserB64
Checks if thepanel useris 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
PanelUserif the user exists, is enabled and is allowed to access the uri;nullotherwise - See Also:
-
checkLogin
Checks if thepanel useris allowed to logon to the web panel and/or use the websocket- Parameters:
username- The user's usernamepassword- The user's password- Returns:
trueif the exists and is enabled;falseotherwise- See Also:
-
checkLoginAndGetUser
Checks if thepanel useris allowed to logon to the web panel and/or use the websocket- Parameters:
username- The user's usernamepassword- The user's password- Returns:
- A
PanelUserif the user exists, is enabled and is allowed to access the uri;nullotherwise - See Also:
-
checkLogin
Checks if thepanel useris 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:
trueif the user exists, is enabled and is allowed to access the uri;falseotherwise- See Also:
-
checkLoginAndGetUser
Checks if thepanel useris 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
PanelUserif the user exists, is enabled and is allowed to access the uri;nullotherwise - See Also:
-
checkAuthTokenAndGetUser
Checks if thepanel useris 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
PanelUserif a user with that authentication token exists and is enabled;nullotherwise - 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;
nullotherwise - See Also:
-
token generationtoken usageexistsPanelUser.isEnabled()
-
changePassword
public static PanelUserHandler.PanelMessage changePassword(String username, String currentPassword, String newPassword) Changes apanel user'spassword
Only existing andeditablepanel userscan have their password changed- Parameters:
username-currentPassword-newPassword-- Returns:
- The fitting
panel message - See Also:
-
createNewUser
Creates a newpanel userwith full accesspermissionsto all panel sections if the user does not exist- Parameters:
username- The user's nameenabled-trueif the user should be enabled;falseotherwise- Returns:
- The fitting
panel message - See Also:
-
User Creationexists
-
createNewUser
public static PanelUserHandler.PanelMessage createNewUser(String username, JSONArray jsoPermissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) Creates a newpanel userif the user does not exist- Parameters:
username- The user's namepermission- The user'spermissions display nameenabled-trueif the user should be enabled;falseotherwisecanManageUsers-trueto allow the user to manage other users;falseto prohibit thiscanRestartBot-trueto allow the user to restart the bot via the panel;falseto prohibit this- Returns:
- The fitting
panel message - See Also:
-
User Creationexists
-
createNewUser
public static PanelUserHandler.PanelMessage createNewUser(String username, Map<String, PanelUserHandler.Permission> permissions, boolean enabled, boolean canManageUsers, boolean canRestartBot) Creates a newpanel userif the user does not exist- Parameters:
username- The user's namepermission- The user'spermissionsenabled-trueif the user should be enabled;falseotherwisecanManageUsers-trueto allow the user to manage other users;falseto prohibit thiscanRestartBot-trueto allow the user to restart the bot via the panel;falseto prohibit this- Returns:
- The fitting
panel message - See Also:
-
User Creationexists
-
deleteUser
- Parameters:
username- The user's name which should be deleted- Returns:
- The fitting
panel message - See Also:
-
User deletionexists
-
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;nullto not change the usernamepermission- The user's newpermissions;nullto not change thepermissionenabled-trueto enable the user;falseto disable the usercanManageUsers-trueto allow the user to manage other users;falseto prohibit thiscanRestartBot-trueto allow the user to restart the bot via the panel;falseto 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;nullto not change the usernamepermission- The user's newpermission;nullto not change thepermissionsenabled-trueto enable the user;falseto disable the usercanManageUsers-trueto allow the user to manage other users;falseto prohibit thiscanRestartBot-trueto allow the user to restart the bot via the panel;falseto 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;nullto not change the usernamepermission- The user's newpermission;nullto not change thepermissionsenabled-trueto enable the user;falseto disable the user- Returns:
- The fitting
panel message - See Also:
-
resetPassword
Resets apanel user'spassword
Only existing andeditablepanel userscan have their passwords reset- Parameters:
username- The user's name who's password should be reset- Returns:
- The new random password
- See Also:
-
existspassword generation
-
getAllUsersJSONObject
Adds thepanel userssafe properties (username, isEnabled,permissions, creationDate, lastLogin) as an array to anJSONStringerinstance- Parameters:
jsonObject- TheJSONStringerinstance to which the array should be added to- See Also:
-
getPermissionsJSONObject
Adds thepermissionsas an array to anJSONStringerinstance- Parameters:
jsonObject- TheJSONStringerinstance to which thepermissionsarray should be added to
-
getUserJSONObject
Adds thepanel user'ssafe 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- TheJSONStringerinstance to which the user's properties should be added to- See Also:
-
getAllPanelSectionsJSONObject
Adds the availablepanel sectionsas an array to anJSONStringerinstance- Parameters:
jsonObject- TheJSONStringerinstance to which thepanel sectionsshould 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-trueforPanelUserHandler.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- Theusertablename- The tableName to be checkedsection- Thepanel sectionon which this request was createdisWriteAction- Indicates if the action is an action requiringwrite permissions- Returns:
trueif the user is allowed to access the table under the conditions;falseotherwise
-
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- Theuserscript- The script path being accessedsection- Thepanel sectionon which this request was created- Returns:
trueif the user is allowed to access the table under the conditions;falseotherwise
-
checkPanelUserSectionAccess
public static boolean checkPanelUserSectionAccess(PanelUser user, String section, boolean isWriteAction) Checks if a user has to access apanel section- Parameters:
user- Theusersection- Thepanel sectionon which this request was createdisWriteAction- Indicates if the action is an action requiringwrite permissions- Returns:
trueif the user is allowed to access the table under the conditions;falseotherwise
-
checkPanelUserCommandAccess
Checks if a user is allowed to send a command to the bots modules- Parameters:
user- Theusercommand- The command which has been sent by the user through the panelsection- Thepanel sectionon which this request was created- Returns:
trueif the user is allowed to access the table under the conditions;falseotherwise
-