|
pianod2
multisource multiuser scriptable networked music player
|
Container and manager class for users. More...
#include <users.h>


Public Types | |
| enum class | WhichSources { User , Listed , Restorable } |
| using | UserSelectionPredicate = std::function< bool(const User *user)> |
| using | StoredSourcePair = std::pair< User *, UserData::DataStore * > |
| using | StoredSourceList = std::vector< StoredSourcePair > |
Public Types inherited from PianodInterpreter | |
| using | HelpList = PianodDispatcher::HelpList |
Public Member Functions | |
| virtual const Parsnip::Parser::Definitions & | getParserDefinitions () override |
| Retrieve the parser definitions handled by the interpreter. More... | |
| virtual | ~UserManager () |
| const std::string & | shadowUserName () const |
| Get the name of the user used as a template for shadow users. More... | |
| void | shadowUserName (const std::string &who) |
| Get a user as a template for shadow users. More... | |
| User * | addUser (User &user) |
| Add a user to the list of known users. More... | |
| User * | tryget (const std::string &who) |
| Retrieve a user's record. More... | |
| User * | get (const std::string &who) |
| Retrieve a user's record. More... | |
| User * | authenticate (const std::string &who, const std::string &password) |
| Verify a user's credentials. More... | |
| void | clearPrivilege (Privilege priv) |
| Disable a privilege for all users. More... | |
| bool | validUserList (Football::Connection *event, char *const *username) |
| std::vector< PianodConnection * > | getUserConnections (PianodService &service, const User *user) const |
| Retrieve a list of a user's connections. More... | |
| UserList | getUsers (UserSelectionPredicate predicate=[](const User *) { return true;}) const |
| Retrieve a list of users matching some predicate. More... | |
| UserList | getUsersPresent (PianodService &service, bool use_attribute=false) const |
| Retrieve a list of a users connected. More... | |
| UserList | allUsers (void) const |
| StoredSourceList | getStoredSources (WhichSources selection, const User *visibleBy=nullptr) const |
| Return a list of persisted datasource parameters. More... | |
| RESPONSE_CODE | findStoredSource (const std::string &type, const std::string &name, User *forWho, UserData::JSONData **found, User **owner) |
| Find stored source parameters for use. More... | |
| void | createDefaultUser () |
| Add the default 'admin' user to the users list. More... | |
| void | deleteUser (User *user) |
| Remove a user from the registered list of users. More... | |
| bool | persist () |
| Persist user data to a file. More... | |
| void | restore () |
| Resubstantiate a user from the XML userdata file. More... | |
| float | periodic (void) |
| Execute periodic tasks: More... | |
Public Member Functions inherited from PianodInterpreter | |
| virtual void | registerInterpreter (PianodDispatcher &dispatcher) |
| Register the interpreter with a dispatcher. More... | |
| const HelpList | getHelp (const std::vector< std::string > &search, std::set< std::string > *option_parsers) |
| Search the interpreter's definitions for any definitions matching search criteria. More... | |
Static Public Member Functions | |
| static const Parsnip::Parser::Definitions & | parser_definitions () |
| static const PianodSchema::CommandIds & | json_request_names (PianodSchema &schema) |
| Retrieve names for our JSON requests, and make schema revisions. More... | |
| static time_t | writeTime (void) |
| static bool | needWrite (void) |
Static Public Member Functions inherited from PianodInterpreter | |
| static bool | optionIs (const Parsnip::Data &options, const char *name, const char *expected) |
| Check if a string value exists and is case-blind equal to a particular value. More... | |
| template<typename ValueType , typename LookupType > | |
| static ValueType | optionalValue (const Parsnip::Data &options, const char *name, const LookupType &lookup, const ValueType default_value) |
| Retrieve the ID of a string value. More... | |
Private Member Functions | |
| virtual bool | authorizedCommand (Parsnip::Parser::CommandId, PianodConnection &conn) override |
| Check whether a command is authorized. More... | |
| virtual ResponseCollector | handleCommand (Parsnip::Parser::CommandId, const Parsnip::Data &options, PianodConnection &conn) override |
| Command handler. More... | |
Private Attributes | |
| std::string | shadow_user_name |
Additional Inherited Members | |
Protected Types inherited from PianodInterpreter | |
| using | StringVector = std::vector< std::string > |
Static Protected Attributes inherited from PianodInterpreter | |
| static const Parsnip::Data | EmptyDictionary {Parsnip::Data::Dictionary} |
| An empty dictionary, often used as a default with Parsnip::Data::getOr. More... | |
| static const StringVector | EmptyStringVector |
| An empty string vector, often used as a default with Parsnip::Data::getOr. More... | |
Container and manager class for users.
| using UserManager::StoredSourceList = std::vector<StoredSourcePair> |
| using UserManager::StoredSourcePair = std::pair<User *, UserData::DataStore *> |
| using UserManager::UserSelectionPredicate = std::function<bool (const User *user)> |
|
strong |
|
virtual |
Add a user to the list of known users.
| user | A profile for the user to register. |


|
inline |


| User * UserManager::authenticate | ( | const std::string & | who, |
| const std::string & | password | ||
| ) |
Verify a user's credentials.
If password shadowing is enabled and the user is not known to pianod, checks for a known, eligible system user with the name and adds them if found.
| who | The username to retrieve. Case insensitive. |
| password | The password to try. |


|
overrideprivatevirtual |
Check whether a command is authorized.
| command_id | The command requesting execution. |
| context | Connection details, including authentication state and privileges. |
Implements PianodInterpreter.

| void UserManager::clearPrivilege | ( | Privilege | priv | ) |
Disable a privilege for all users.
| priv | The privilege to clear. |

| void UserManager::createDefaultUser | ( | ) |
Add the default 'admin' user to the users list.


| void UserManager::deleteUser | ( | User * | user | ) |
Remove a user from the registered list of users.
| user | The user to remove. The passed pointer is invalidated by this call. |


| RESPONSE_CODE UserManager::findStoredSource | ( | const std::string & | type, |
| const std::string & | name, | ||
| User * | forWho, | ||
| UserData::JSONData ** | found, | ||
| User ** | owner | ||
| ) |
Find stored source parameters for use.
Success requires the stored source exists and is eligible for use by the requester.
| type | The type of source. | |
| name | The name of the source. | |
| forWho | The user that wants to use the source. | |
| [out] | found | The source parameters retrieved. |
| [out] | owner | The owner of the retrieved source. |


| User * UserManager::get | ( | const std::string & | who | ) |
Retrieve a user's record.
| who | The username to retrieve. Case insensitive. |
| CommandError | if the specified user is not found. |


|
overridevirtual |
Retrieve the parser definitions handled by the interpreter.
Implements PianodInterpreter.

| UserManager::StoredSourceList UserManager::getStoredSources | ( | UserManager::WhichSources | selection, |
| const User * | requester = nullptr |
||
| ) | const |
Return a list of persisted datasource parameters.
| selection | Which selection criteria to apply in creating list. |
| requester | If specified, return only the requester's sources. |


| std::vector< PianodConnection * > UserManager::getUserConnections | ( | PianodService & | service, |
| const User * | user | ||
| ) | const |
Retrieve a list of a user's connections.
| service | The football service to search. |
| user | The user to find. |
| UserList UserManager::getUsers | ( | UserSelectionPredicate | predicate = [] (const User *) { return true; } | ) | const |
Retrieve a list of users matching some predicate.

| UserList UserManager::getUsersPresent | ( | PianodService & | service, |
| bool | use_attribute = false |
||
| ) | const |
Retrieve a list of a users connected.
| service | The football service to search. |
| use_attribute | If true, then the Present attribute is considered in determining presence. If false, active sessions indicate presence. |

|
overrideprivatevirtual |
Command handler.
| command_id | Command to execute. |
| parameters | Command parameters. |
| context | Connection details, including authentication state and privileges. |
| CommandError | or other exception if an error occurs. |
Implements PianodInterpreter.

|
static |
Retrieve names for our JSON requests, and make schema revisions.
| schema | The schemaset containing our requests. |


|
inlinestatic |
|
static |

| float UserManager::periodic | ( | void | ) |
Execute periodic tasks:


| bool UserManager::persist | ( | void | ) |
Persist user data to a file.
Write to a new file, then carefully move the old one out/new one in in such a way as to minimize risk.


| void UserManager::restore | ( | ) |
Resubstantiate a user from the XML userdata file.
| bad_alloc,which | will leave class in indeterminate state. |


| const std::string & UserManager::shadowUserName | ( | ) | const |
Get the name of the user used as a template for shadow users.

| void UserManager::shadowUserName | ( | const std::string & | who | ) |
Get a user as a template for shadow users.

| User * UserManager::tryget | ( | const std::string & | who | ) |
Retrieve a user's record.
| who | The username to retrieve. Case insensitive. |


| bool UserManager::validUserList | ( | Football::Connection * | event, |
| char *const * | username | ||
| ) |
|
inlinestatic |
|
private |