VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
DtUserStore Class Reference

DtUserStore — process-wide singleton for loading and querying the user database.

Users are defined in a JSON file with the following format:

{
"users": [
{
"username": "admin",
"passwordHash": "pbkdf2-sha256:600000:<base64-salt>:<base64-hash>",
"permissions": ["scenario.write", "entities.read", ...]
},
{ "username": "viewer", "permissions": ["entities.read", "scenario.read"] }
]
}

The "passwordHash" field is optional. An absent or empty value means the account requires no password. Hashes are produced by DtPasswordHasher::hash().

After initialize() returns the store may be mutated at runtime via addUser(), removeUser(), setPasswordHash(), and setPermissions(). Each mutation is persisted back to the JSON file immediately. All public methods are thread-safe.

If the file does not exist, a default file with an admin and a viewer user is created and a warning is logged.

Classes

struct  DtUserEntry
 

Public Member Functions

void initialize (const std::string &usersFilePath)
 
bool userExists (const std::string &username) const
 
std::vector< std::string > getUserPermissions (const std::string &username) const
 
std::string getPasswordHash (const std::string &username) const
 
std::vector< std::string > usernames () const
 
bool addUser (const std::string &username, const std::vector< std::string > &permissions, const std::string &passwordHash)
 
bool addUserWithPreset (const std::string &username, const std::string &preset, const std::vector< std::string > &extraPerms, const std::string &passwordHash)
 
std::string getUserPreset (const std::string &username) const
 
std::map< std::string,
std::vector< std::string > > 
getPresets () const
 
bool removeUser (const std::string &username)
 
bool setPasswordHash (const std::string &username, const std::string &passwordHash)
 
bool setPermissions (const std::string &username, const std::vector< std::string > &permissions)
 
bool setPreset (const std::string &username, const std::string &preset)
 

Static Public Member Functions

static DtUserStore & getInstance ()
 

Private Member Functions

 DtUserStore ()
 
bool persistToFile () const
 

Private Attributes

std::map< std::string,
DtUserEntry > 
myUsers
 
std::map< std::string,
std::vector< std::string > > 
myPresets
 
std::string myUsersFilePath
 
std::mutex myMutex
 

Constructor & Destructor Documentation

DtUserStore::DtUserStore ( )
private

Member Function Documentation

static DtUserStore& DtUserStore::getInstance ( )
static

Returns the process-wide singleton instance.

void DtUserStore::initialize ( const std::string &  usersFilePath)

Load users from the given JSON file path. Creates a default file with admin/viewer users if the path does not exist. Must be called exactly once from main() before any background threads start.

bool DtUserStore::userExists ( const std::string &  username) const

Returns true if a user with the given username exists in the store.

std::vector<std::string> DtUserStore::getUserPermissions ( const std::string &  username) const

Returns the permission strings for the given user. The returned list is the union of the user's preset permissions (if any) and their individual extra permissions. Duplicates are removed. Returns an empty vector if the user does not exist.

std::string DtUserStore::getPasswordHash ( const std::string &  username) const

Returns the stored password hash for the given user. Returns an empty string if the user does not exist or has no password set.

std::vector<std::string> DtUserStore::usernames ( ) const

Returns a list of all known usernames.

bool DtUserStore::addUser ( const std::string &  username,
const std::vector< std::string > &  permissions,
const std::string &  passwordHash 
)

Adds a new user with the given permissions and optional password hash.

Parameters
passwordHashPass DtPasswordHasher::hash(password) or empty for no password.
Returns
false if a user with that name already exists.
bool DtUserStore::addUserWithPreset ( const std::string &  username,
const std::string &  preset,
const std::vector< std::string > &  extraPerms,
const std::string &  passwordHash 
)

Adds a new user whose permissions are derived from a named preset, with an optional list of additional (extra) permissions on top.

Parameters
presetName of a preset defined in presets; empty string for none.
extraPermsAdditional permissions beyond the preset (may be empty).
passwordHashPass DtPasswordHasher::hash(password) or empty for no password.
Returns
false if a user with that name already exists.
std::string DtUserStore::getUserPreset ( const std::string &  username) const

Returns the preset name assigned to the given user. Returns an empty string if the user does not exist or has no preset.

std::map<std::string, std::vector<std::string> > DtUserStore::getPresets ( ) const

Returns all defined presets as a map of preset-name → permission list.

bool DtUserStore::removeUser ( const std::string &  username)

Removes the user with the given username.

Returns
false if the user does not exist.
bool DtUserStore::setPasswordHash ( const std::string &  username,
const std::string &  passwordHash 
)

Replaces the password hash for an existing user. Pass an empty string to remove the password requirement.

Returns
false if the user does not exist.
bool DtUserStore::setPermissions ( const std::string &  username,
const std::vector< std::string > &  permissions 
)

Replaces the full permission list for an existing user. Replaces only the user's extra permissions; the preset field is preserved.

Returns
false if the user does not exist.
bool DtUserStore::setPreset ( const std::string &  username,
const std::string &  preset 
)

Sets the preset for an existing user. Pass an empty string to remove the preset assignment. The user's extra permissions are not modified.

Returns
false if the user does not exist.
bool DtUserStore::persistToFile ( ) const
private

Serializes myUsers and myPresets back to myUsersFilePath. Must be called while myMutex is held.

Member Data Documentation

std::map<std::string, DtUserEntry> DtUserStore::myUsers
private
std::map<std::string, std::vector<std::string> > DtUserStore::myPresets
private
std::string DtUserStore::myUsersFilePath
private
std::mutex DtUserStore::myMutex
mutableprivate

The documentation for this class was generated from the following file:

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)