简体   繁体   中英

Parse.com set User Role

I am using parse.com as a backend for my android application. I need help to solve the following scenario. I wanna do some access control. The app will consists of the following users say Super Admin, Admin, Moderator and Editors. The Super Admin can create a number of Admins(each admin has its own group), where as the Admin can create Moderator and Editors. Now i wanna set ACL to these users in which one group cannot be able to read or write data of another group. Is there any simple example for this scenario available.

                                      SUPER ADMIN
                        |------------------|--------------------|
                        |                  |                    |
                 ADMIN(Group A)     ADMIN(Group B)       ADMIN(Group C)
                     |                     |                    |
                     |-Moderator           |-Moderator          |-Moderator
                     |                     |                    |
                     |-Editor1             |-Editor1            |-Editor1
                     |                     |                    |
                     |-Editor2             |-Editor2            |-Editor2
                     |                                          |
                     |-Editor3                                  |-Editor3

Yes, you can do this. Roles use ACLs just as other objects to. I think the example in the docs answer most of what you are after:

https://parse.com/docs/android_guide#roles

Try that and check back here with a specific question if you have problems solving your scenario.

Snipped from the docs:

// By specifying no write privileges for the ACL, we can ensure the role cannot be altered.
ParseACL roleACL = new ParseACL();
roleACL.setPublicReadAccess(true);
ParseRole role = new ParseRole("Administrator", roleACL);
role.saveInBackground();

ParseRole role = new ParseRole(roleName, roleACL);
for (ParseUser user : usersToAddToRole) {
  role.getUsers().add(user)
}
for (ParseRole childRole : rolesToAddToRole) {
  role.getRoles().add(childRole);
}
role.saveInBackground();

This is what I use for read and write, but with the ParseACL object you can set everything you need.

 ParseACL defaultACL = new ParseACL();
 defaultACL.setPublicReadAccess(true);
 ParseACL.setDefaultACL(defaultACL, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM