Skip to main content

OzAccessControl

Git Source

OzAccessControl

A middleware extension that implements role-based access control

Implements AccessManager with role-based access control functionality

Methods

__OzAccessControl_init

function __OzAccessControl_init(
address defaultAdmin
) internal onlyInitializing

Initializes the contract with a default admin

Parameters

NameTypeDescription
defaultAdminaddressThe address to set as the default admin

hasRole

function hasRole(bytes32 role, address account) public view virtual returns (bool) 

Returns true if account has been granted role

Parameters

NameTypeDescription
rolebytes32The role to check
accountaddressThe account to check

Returns

NameTypeDescription
boolbool True if account has role

getRoleAdmin

function getRoleAdmin(
bytes32 role
) public view virtual returns (bytes32)

Returns the admin role that controls the specified role

Parameters

NameTypeDescription
rolebytes32The role to get the admin for

Returns

NameTypeDescription
bytes32bytes32 The admin role

getRole

function getRole(
bytes4 selector
) public view virtual returns (bytes32)

Returns the role required for a function selector

Parameters

NameTypeDescription
selectorbytes4The function selector

Returns

NameTypeDescription
bytes32bytes32 The required role

grantRole

function grantRole(bytes32 role, address account) public virtual 

Grants role to account if caller has admin role

Parameters

NameTypeDescription
rolebytes32The role to grant
accountaddressThe account to grant the role to

revokeRole

function revokeRole(bytes32 role, address account) public virtual 

Revokes role from account if caller has admin role

Parameters

NameTypeDescription
rolebytes32The role to revoke
accountaddressThe account to revoke the role from

renounceRole

function renounceRole(bytes32 role, address callerConfirmation) public virtual 

Allows an account to renounce a role they have

Parameters

NameTypeDescription
rolebytes32The role to renounce
callerConfirmationaddressAddress of the caller for confirmation

_setSelectorRole

function _setSelectorRole(bytes4 selector, bytes32 role) internal virtual 

Sets the role required for a function selector

Parameters

NameTypeDescription
selectorbytes4The function selector
rolebytes32The required role

_setRoleAdmin

function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual 

Sets the admin role for a role

Parameters

NameTypeDescription
rolebytes32The role to set admin for
adminRolebytes32The new admin role

_grantRole

function _grantRole(bytes32 role, address account) internal virtual returns (bool) 

Grants a role

Parameters

NameTypeDescription
rolebytes32The role to grant
accountaddressThe account to grant the role to

Returns

NameTypeDescription
boolbool True if role was granted

_revokeRole

function _revokeRole(bytes32 role, address account) internal virtual returns (bool) 

Revokes a role

Parameters

NameTypeDescription
rolebytes32The role to revoke
accountaddressThe account to revoke the role from

Returns

NameTypeDescription
boolbool True if role was revoked

_checkAccess

function _checkAccess() internal view virtual override 

Checks access based on role required for the function selector

Implements BaseMiddleware's _checkAccess function