Last active
March 10, 2020 03:27
-
-
Save hiddentao/06a3eee75fb433192563890a5d605240 to your computer and use it in GitHub Desktop.
Ethereum solidity contract for role-based access control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.10; | |
contract RoleBasedAcl { | |
address creator; | |
mapping(address => mapping(string => bool)) roles; | |
function RoleBasedAcl () { | |
creator = msg.sender; | |
} | |
function assignRole (address entity, string role) hasRole('superadmin') { | |
roles[entity][role] = true; | |
} | |
function unassignRole (address entity, string role) hasRole('superadmin') { | |
roles[entity][role] = false; | |
} | |
function isAssignedRole (address entity, string role) returns (bool) { | |
return roles[entity][role]; | |
} | |
modifier hasRole (string role) { | |
if (!roles[msg.sender][role] && msg.sender != creator) { | |
throw; | |
} | |
_; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much for this great implementation! 👍