forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthorityFilter.sol
46 lines (38 loc) · 1.31 KB
/
AuthorityFilter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pragma solidity ^0.4.4;
import "TransactionFilterBase.sol";
import "Group.sol";
contract AuthorityFilter is TransactionFilterBase {
bool private _enabled = false; //是否启用权限控制
mapping (address => address) private _groups; //用户对应的角色
function AuthorityFilter(){
}
function getInfo()public returns(string,string){
return (name,version);
}
//设置用户的角色
function setUserGroup(address user, address group) public {
_groups[user] = group;
}
//获取用户的角色
function getUserGroup(address user) public constant returns(address) {
return _groups[user];
}
function enable() {
_enabled = true;
}
//检查用户某个操作的权限
function process(address origin, address from, address to, string func, string input) public constant returns(bool) {
if(!_enabled) {
return true;
}
address group=Group(_groups[origin]);
if( 0x0000000000000000000000000000000000000000 == group ){
return false;
}
return Group(group).getPermission(to, func);
}
//新建一个角色
function newGroup() public returns(address) {
return new Group();
}
}