Customizing a KiiObject's ACL
You can change the access control applied to a KiiObject by setting its ACL.
A KiiObject ACL entry is composed of an action and a subject:
This item defines "what" the target user/group/thing can execute.
Action Representation in code * What the target user/group/thing can execute READ_EXISTING_OBJECT
Read the KiiObject. WRITE_EXISTING_OBJECT
Update and delete the KiiObject.
* These symbols are defined in the
ObjectActionenumeration and can be specified like
Note: The "READ_OBJECTS_IN_BUCKET" action set to a bucket's ACL allows the subject to unconditionally read all KiiObjects in the bucket, even if they are not permitted the "READ_EXISTING_OBJECT" action on the KiiObjects in the bucket. For understanding how the action works, see ACL Customization Examples.
This item defines "who" can execute.
Subject Who can execute the designated action? KiiUser instance The specified user. KiiGroup instance The members of the specified group. KiiThing instance The specified thing. KiiAnyAuthenticatedUser Any authenticated users. KiiAnonymousUser Anonymous users.
See Subject for the definition of the "Any authenticated users" and "Anonymous users".
You can add and delete an ACL entry in a KiiObject's ACL. You can also get a list of ACL entries.
Here is an example of permitting the
READ_EXISTING_OBJECT action to
- Create a
KiiACLinstance of the KiiObject by calling the
- Create a
KiiACLEntryinstance and pass it as the argument of the
putACLEntry()method. Here, a
KiiAnyAuthenticatedUserinstance is specified as the ACL entry's subject so as to permit the action to any authenticated users. If you set a
KiiAnonymousUserinstance as the subject instead, you can permit the same action to anonymous users. If you set a specific KiiUser instance, the action will be permitted to that user instance.
- Call the
save()method to send the request for updating the ACL to Kii Cloud.
See KiiACLEntry for more information about how you can specify other subjects like users and groups.
When you are adding multiple ACL entries, the entry registration is handled one by one. If an error occurs before all entries are registered, some entries will remain unregistered. In such a situation, you can get a list of ACL entries that were failed to register by executing the
getFailedACLEntries() method of the
To delete an ACL entry, create a
KiiACLEntry instance with its third argument
grant set to false and save it. The ACL entry will be deleted from the server.
The following example deletes the ACL entry created in the previous sample code.
Note that the
removeACLEntry() method of the
KiiACL just deletes an ACL entry from the local modification list. The method does not delete an ACL entry set on the server. In the above sample code, we first register a request to remove the
READ_EXISTING_OBJECT action from
objectAcl on the client and then execute the
save() method to reflect the request on the server. If you execute the
removeACLEntry() method, it would remove the request from the ACL modification list, but not from the ACL on the server.
You can get the ACL set on a KiiObject. Even if you have not set any ACL entries in a KiiObject's ACL, you can get its default ACL.
Here is the sample code for getting a list of ACL entries as a Set.
- Create a
KiiACLinstance of the KiiObject by executing the
- Call the
listACLEntries()method to get the KiiObject's ACL as a Set of the
- Parse through each ACL entry in the Set.
Trying to set an existing ACL entry will give you an error. By checking existing ACL entries beforehand as shown in this sample code, you can find which ACL entries should be set.
I got an error when I run my application multiple times
The ACL entry should be registered just once (e.g., in the initialization) and should not be registered again in the next run.
If you try to save an existing ACL entry, you will get an error. If your application runs the same ACL entry registration flow every time, therefore, you will get an error because the application attempts to re-register an already existing ACL entry.
When you are adding multiple ACL entries, the entry registration is handled one by one. If an error occurs before all entries are registered, some entries will remain unregistered. To recover from such a situation, you will first need to get a list of the existing ACL entries, remove the duplicating ACL entries from the ACL modification list, and then register remaining entries. See Getting a KiiObject's ACL to learn how to get the list of the existing ACL entries.
I cannot delete an ACL entry
You cannot delete default ACL entries applied to scope owners and KiiObject creators. See Cannot delete default ACL entries of scope owners and creators for more details.