I wonder, is it possible to create Access Control List and change user rights by smart-contract in private blockchain? Can I set up the security policy by smart-contract?
Yes of course you can. By using modifiers
and heavily using msg.sender
a strong ACL can be set up. Example is
pragma solidity ^0.4.0;
contract SecondaryContract {
bool public contractStatus = false;
address public adminAddress;
mapping (address => ACL) listOfAccountsWithCustomACL;
struct ACL {
string name;
string somePermissions;
}
function SecondaryContract() {
adminAddress = msg.sender;
contractStatus = true;
}
// Modifier functions to set up first layer of ACL
modifier onlyBy(address _account){
if (msg.sender != _account) throw;
_;
}
modifier onlyIfActive() {
if (contractStatus) throw;
_;
}
modifier onlyByCreator(){
if (msg.sender != adminAddress) throw;
_;
}
modifier onlyAfter(uint _time) {
if (now < _time) throw;
_;
}
modifier onlyBefore(uint _time) {
if (now > _time) throw;
_;
}
function Foo() onlyBy(someTrustAddress){
// Can be called by a list of addresses specified
}
function Bar() onlyByCreator(){
// Can be called ONLY by the person that initialized this contract
}
function Zam() onlyIfActive() {
// Can only be called in the contractStatus is true
}
// Deactivates the contract which prevents Zam from being called
// Only the origin creator of the smart contract can call this
function deactivateContract() onlyByCreator {
contractStatus = false;
}
}
In this msg.sender
can belong to an account of a person holding a public private key pair or even a different smart contract itself that may have own ACL