-
-
Save 2947721120/6ba119ee2f4cf97b84af0b60f0784097 to your computer and use it in GitHub Desktop.
在火力地堡基于角色的安全性
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
/* | |
这个例子展示了如何使用你的数据结构为基础 | |
你的火力地堡安全规则来实现基于角色的安全性。我们店 | |
每个用户通过他们的Twitter uid和使用以下简单的方法 | |
为用户角色: | |
0 - GUEST客人 | |
10 - USER 用户 | |
20 - MODERATOR 主持人 | |
99 - ADMINISTRATOR 管理员 | |
此文件显示的数据结构,和所述安全规则以下文件 | |
示出了相应的安全规则. | |
*/ | |
{ | |
"users": { | |
"twitter:12345": { | |
"full-name": "Sara Robinson", | |
"username": "SRobTweets", | |
"role-value": 10 | |
}, | |
"twitter:56789": { | |
"full-name": "Michael 'Kato' Wulf", | |
"username": "katowulf", | |
"role-value": 20 | |
} | |
.... | |
}, | |
"rooms": { | |
"public-room-1": { | |
"users": { | |
"twitter:56789": 20, | |
"twitter:12345": 10 | |
} | |
}, | |
"admin-only-room": { | |
"users": { | |
"twitter:56789": 20 | |
} | |
} | |
... | |
}, | |
"messages": { | |
"public-room-1": { | |
-JVwTPcWMIt0J6Gbtrqh: { | |
"user": "twitter:12345", | |
"text": "Hello everyone!" | |
} | |
... | |
}, | |
"admin-only-room": { | |
-JVwU5tLQRPbzXo4s_a1: { | |
"user": "twitter:56789", | |
"text": "This is a top secret message." | |
} | |
... | |
} | |
} | |
} |
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
{ | |
"rules": { | |
".read": true, | |
"users": { | |
"$user": { | |
//如果可以验证的添加消息 | |
".write": "auth.uid === $user" | |
} | |
}, | |
"rooms": { | |
"$room": { | |
"users": { | |
// 可以写入只有管理员用户列表 | |
"$user": { | |
"write":"newData.parent().child(auth.uid).val() === 99" | |
} | |
} | |
} | |
}, | |
"messages": { | |
"$room": { | |
"$message": { | |
//可如果他们是一个成员添加消息MEMBER | |
".write": "(!data.exists() && newData.exists() && root.child('rooms/' + $room + '/users/' + auth.uid).val() >= 10)" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment