TrinityCore
rbac::RBACData Class Reference

#include <RBAC.h>

Public Member Functions

 RBACData (uint32 id, std::string const &name, int32 realmId, uint8 secLevel=255)
 
std::string const & GetName () const
 Gets the Name of the Object. More...
 
uint32 GetId () const
 Gets the Id of the Object. More...
 
HasPermission

Checks if certain action is allowed

Checks if certain action can be performed.

Returns
grant or deny action

Example Usage:

bool Player::CanJoinArena(Battleground* bg)
{
return bg->isArena() && HasPermission(RBAC_PERM_JOIN_ARENA);
}
bool isArena() const
bool HasPermission(uint32 permission) const
Definition: RBAC.h:834
bool HasPermission (uint32 permission) const
 
RBACPermissionContainer const & GetPermissions () const
 Returns all the granted permissions (after computation) More...
 
RBACPermissionContainer const & GetGrantedPermissions () const
 Returns all the granted permissions. More...
 
RBACPermissionContainer const & GetDeniedPermissions () const
 Returns all the denied permissions. More...
 
GrantRole

Grants a permission

Grants a permission to the account. If realm is 0 or the permission can not be added No save to db action will be performed.

Fails if permission Id does not exists or permission already granted or denied

Parameters
permissionIdpermission to be granted
realmIdrealm affected
Returns
Success or failure (with reason) to grant the permission

Example Usage:

// previously defined "RBACData* rbac" with proper initialization
uint32 permissionId = 2;
if (rbac->GrantRole(permissionId) == RBAC_IN_DENIED_LIST)
TC_LOG_DEBUG("entities.player", "Failed to grant permission {}, already denied", permissionId);
uint32_t uint32
Definition: Define.h:142
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
@ RBAC_IN_DENIED_LIST
Definition: RBAC.h:765
RBACCommandResult GrantPermission (uint32 permissionId, int32 realmId=0)
 
DenyPermission

Denies a permission

Denied a permission to the account. If realm is 0 or the permission can not be added No save to db action will be performed.

Fails if permission Id does not exists or permission already granted or denied

Parameters
permissionIdpermission to be denied
realmIdrealm affected
Returns
Success or failure (with reason) to deny the permission

Example Usage:

// previously defined "RBACData* rbac" with proper initialization
uint32 permissionId = 2;
if (rbac->DenyRole(permissionId) == RBAC_ID_DOES_NOT_EXISTS)
TC_LOG_DEBUG("entities.player", "Role Id {} does not exists", permissionId);
@ RBAC_ID_DOES_NOT_EXISTS
Definition: RBAC.h:766
RBACCommandResult DenyPermission (uint32 permissionId, int32 realmId=0)
 

Private Member Functions

CalculateNewPermissions

Calculates new permissions

Calculates new permissions after some change The calculation is done Granted - Denied:

  • Granted permissions: through linked permissions and directly assigned
  • Denied permissions: through linked permissions and directly assigned
void CalculateNewPermissions ()
 
int32 GetRealmId () const
 
bool HasGrantedPermission (uint32 permissionId) const
 Checks if a permission is granted. More...
 
bool HasDeniedPermission (uint32 permissionId) const
 Checks if a permission is denied. More...
 
void AddGrantedPermission (uint32 permissionId)
 Adds a new granted permission. More...
 
void RemoveGrantedPermission (uint32 permissionId)
 Removes a granted permission. More...
 
void AddDeniedPermission (uint32 permissionId)
 Adds a new denied permission. More...
 
void RemoveDeniedPermission (uint32 permissionId)
 Removes a denied permission. More...
 
void AddPermissions (RBACPermissionContainer const &permsFrom, RBACPermissionContainer &permsTo)
 Adds a list of permissions to another list. More...
 
void RemovePermissions (RBACPermissionContainer &permsFrom, RBACPermissionContainer const &permsToRemove)
 Removes a list of permissions from another list. More...
 

ExpandPermissions

Adds the list of linked permissions to the original list

Given a list of permissions, gets all the inherited permissions

Parameters
permissionsThe list of permissions to expand
uint32 _id
 
std::string _name
 

‍Account id

More...
 
int32 _realmId
 

‍Account name

More...
 
uint8 _secLevel
 

‍RealmId Affected

More...
 
RBACPermissionContainer _grantedPerms
 

‍Account SecurityLevel

More...
 
RBACPermissionContainer _deniedPerms
 

‍Granted permissions

More...
 
RBACPermissionContainer _globalPerms
 

‍Denied permissions

More...
 
void ExpandPermissions (RBACPermissionContainer &permissions)
 

RevokePermission

Removes a permission

Removes a permission from the account. If realm is 0 or the permission can not be removed No save to db action will be performed. Any delete operation will always affect "all realms (-1)" in addition to the realm specified

Fails if permission not present

Parameters
permissionIdpermission to be removed
realmIdrealm affected
Returns
Success or failure (with reason) to remove the permission

Example Usage:

// previously defined "RBACData* rbac" with proper initialization
uint32 permissionId = 2;
if (rbac->RevokeRole(permissionId) == RBAC_OK)
TC_LOG_DEBUG("entities.player", "Permission {} succesfully removed", permissionId);
@ RBAC_OK
Definition: RBAC.h:761
RBACCommandResult RevokePermission (uint32 permissionId, int32 realmId=0)
 
void LoadFromDB ()
 Loads all permissions assigned to current account. More...
 
QueryCallback LoadFromDBAsync ()
 
void LoadFromDBCallback (PreparedQueryResult result)
 
void SetSecurityLevel (uint8 id)
 Sets security level. More...
 
uint8 GetSecurityLevel () const
 Returns the security level assigned. More...
 
void SavePermission (uint32 role, bool granted, int32 realm)
 Saves a permission to DB, Granted or Denied. More...
 
void ClearData ()
 Clears roles, groups and permissions - Used for reload. More...
 

Detailed Description

Definition at line 806 of file RBAC.h.

Constructor & Destructor Documentation

◆ RBACData()

rbac::RBACData::RBACData ( uint32  id,
std::string const &  name,
int32  realmId,
uint8  secLevel = 255 
)
inline

Definition at line 809 of file RBAC.h.

Member Function Documentation

◆ AddDeniedPermission()

void rbac::RBACData::AddDeniedPermission ( uint32  permissionId)
inlineprivate

Adds a new denied permission.

Definition at line 981 of file RBAC.h.

+ Here is the caller graph for this function:

◆ AddGrantedPermission()

void rbac::RBACData::AddGrantedPermission ( uint32  permissionId)
inlineprivate

Adds a new granted permission.

Definition at line 969 of file RBAC.h.

+ Here is the caller graph for this function:

◆ AddPermissions()

void rbac::RBACData::AddPermissions ( RBACPermissionContainer const &  permsFrom,
RBACPermissionContainer permsTo 
)
private

Adds a list of permissions to another list.

Definition at line 235 of file RBAC.cpp.

◆ CalculateNewPermissions()

void rbac::RBACData::CalculateNewPermissions ( )
private

Definition at line 223 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ClearData()

void rbac::RBACData::ClearData ( )
private

Clears roles, groups and permissions - Used for reload.

Definition at line 275 of file RBAC.cpp.

+ Here is the caller graph for this function:

◆ DenyPermission()

RBACCommandResult rbac::RBACData::DenyPermission ( uint32  permissionId,
int32  realmId = 0 
)

Definition at line 87 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ExpandPermissions()

void rbac::RBACData::ExpandPermissions ( RBACPermissionContainer permissions)
private

Definition at line 247 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetDeniedPermissions()

RBACPermissionContainer const & rbac::RBACData::GetDeniedPermissions ( ) const
inline

Returns all the denied permissions.

Definition at line 845 of file RBAC.h.

+ Here is the caller graph for this function:

◆ GetGrantedPermissions()

RBACPermissionContainer const & rbac::RBACData::GetGrantedPermissions ( ) const
inline

Returns all the granted permissions.

Definition at line 843 of file RBAC.h.

+ Here is the caller graph for this function:

◆ GetId()

uint32 rbac::RBACData::GetId ( ) const
inline

Gets the Id of the Object.

Definition at line 816 of file RBAC.h.

+ Here is the caller graph for this function:

◆ GetName()

std::string const & rbac::RBACData::GetName ( ) const
inline

Gets the Name of the Object.

Definition at line 814 of file RBAC.h.

+ Here is the caller graph for this function:

◆ GetPermissions()

RBACPermissionContainer const & rbac::RBACData::GetPermissions ( ) const
inline

Returns all the granted permissions (after computation)

Definition at line 841 of file RBAC.h.

◆ GetRealmId()

int32 rbac::RBACData::GetRealmId ( ) const
inlineprivate

Definition at line 951 of file RBAC.h.

+ Here is the caller graph for this function:

◆ GetSecurityLevel()

uint8 rbac::RBACData::GetSecurityLevel ( ) const
inline

Returns the security level assigned.

Definition at line 933 of file RBAC.h.

+ Here is the caller graph for this function:

◆ GrantPermission()

RBACCommandResult rbac::RBACData::GrantPermission ( uint32  permissionId,
int32  realmId = 0 
)

Definition at line 43 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasDeniedPermission()

bool rbac::RBACData::HasDeniedPermission ( uint32  permissionId) const
inlineprivate

Checks if a permission is denied.

Definition at line 963 of file RBAC.h.

+ Here is the caller graph for this function:

◆ HasGrantedPermission()

bool rbac::RBACData::HasGrantedPermission ( uint32  permissionId) const
inlineprivate

Checks if a permission is granted.

Definition at line 957 of file RBAC.h.

+ Here is the caller graph for this function:

◆ HasPermission()

bool rbac::RBACData::HasPermission ( uint32  permission) const
inline

Definition at line 834 of file RBAC.h.

+ Here is the caller graph for this function:

◆ LoadFromDB()

void rbac::RBACData::LoadFromDB ( )

Loads all permissions assigned to current account.

Definition at line 174 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadFromDBAsync()

QueryCallback rbac::RBACData::LoadFromDBAsync ( )

Definition at line 187 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadFromDBCallback()

void rbac::RBACData::LoadFromDBCallback ( PreparedQueryResult  result)

Definition at line 200 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveDeniedPermission()

void rbac::RBACData::RemoveDeniedPermission ( uint32  permissionId)
inlineprivate

Removes a denied permission.

Definition at line 987 of file RBAC.h.

+ Here is the caller graph for this function:

◆ RemoveGrantedPermission()

void rbac::RBACData::RemoveGrantedPermission ( uint32  permissionId)
inlineprivate

Removes a granted permission.

Definition at line 975 of file RBAC.h.

+ Here is the caller graph for this function:

◆ RemovePermissions()

void rbac::RBACData::RemovePermissions ( RBACPermissionContainer permsFrom,
RBACPermissionContainer const &  permsToRemove 
)
private

Removes a list of permissions from another list.

Definition at line 241 of file RBAC.cpp.

+ Here is the caller graph for this function:

◆ RevokePermission()

RBACCommandResult rbac::RBACData::RevokePermission ( uint32  permissionId,
int32  realmId = 0 
)

Definition at line 141 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SavePermission()

void rbac::RBACData::SavePermission ( uint32  role,
bool  granted,
int32  realm 
)
private

Saves a permission to DB, Granted or Denied.

Definition at line 131 of file RBAC.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetSecurityLevel()

void rbac::RBACData::SetSecurityLevel ( uint8  id)
inline

Sets security level.

Definition at line 926 of file RBAC.h.

Member Data Documentation

◆ _deniedPerms

RBACPermissionContainer rbac::RBACData::_deniedPerms
private

‍Granted permissions

Definition at line 1012 of file RBAC.h.

◆ _globalPerms

RBACPermissionContainer rbac::RBACData::_globalPerms
private

‍Denied permissions

Definition at line 1013 of file RBAC.h.

◆ _grantedPerms

RBACPermissionContainer rbac::RBACData::_grantedPerms
private

‍Account SecurityLevel

Definition at line 1011 of file RBAC.h.

◆ _id

uint32 rbac::RBACData::_id
private

Definition at line 1007 of file RBAC.h.

◆ _name

std::string rbac::RBACData::_name
private

‍Account id

Definition at line 1008 of file RBAC.h.

◆ _realmId

int32 rbac::RBACData::_realmId
private

‍Account name

Definition at line 1009 of file RBAC.h.

◆ _secLevel

uint8 rbac::RBACData::_secLevel
private

‍RealmId Affected

Definition at line 1010 of file RBAC.h.


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