Customizing a Bucket's ACL
You can change the access control applied to a bucket by setting the bucket's ACL.
When a KiiObject inside a bucket is accessed, the KiiObject's ACL will be also checked.
A bucket 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 CREATE_OBJECTS_IN_BUCKET
Create new KiiObjects in the bucket. QUERY_OBJECTS_IN_BUCKET
Query KiiObjects in the bucket. READ_OBJECTS_IN_BUCKET
Read KiiObjects in the bucket. DROP_BUCKET_WITH_ALL_CONTENT
Drop the bucket along with all KiiObjects inside.
* These symbols are defined in the
BucketActionenumeration and can be specified like
Note: The "READ_OBJECTS_IN_BUCKET" action allows the subject to unconditionally read all KiiObjects in the bucket. For more information, 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 bucket's ACL. You can also get a list of ACL entries.
Authorized subjects can add ACL entries to the ACL of buckets not in the application scope to add permissions (e.g., allowing anonymous users to create KiiObjects in the bucket). Only the app administrator can modify the ACL of buckets in the application scope (See the hint below).
You can also set an ACL entry to a non-existent bucket. In this case, the bucket will be auto-generated with the specified ACL entry.
Here is an example of adding two ACL entries to the ACL of a bucket in a user scope. In this example, the
CREATE_OBJECTS_IN_BUCKET actions are permitted to
- Create a
KiiACLinstance of the bucket by calling the
KiiACLEntryinstances and pass them as the argument of the
KiiAnyAuthenticatedUserinstances are specified as the ACL entries' subjects so as to permit the actions to any authenticated users. If you set
KiiAnonymousUserinstances as the subjects instead, you can permit the same actions to anonymous users. If you set specific KiiUser instances, the actions will be permitted to those user instances.
- 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 entries 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 requests to remove the
CREATE_OBJECTS_IN_BUCKET actions from
bucketACL on the client and then execute the
save() method to reflect the requests on the server. If you execute the
removeACLEntry() method, it would remove these requests from the ACL modification list, but not from the ACL on the server.
You can get the ACL set on a bucket. Even if you have not set any ACL entries in a bucket'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 bucket by executing the
- Call the
listACLEntries()method to get the bucket'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 bucket's ACL to learn how to get the list of the existing ACL entries.
The subject is permitted the "QUERY_OBJECTS_IN_BUCKET" action but failed to query KiiObjects in the bucket
QUERY_OBJECTS_IN_BUCKETaction only allows the subject to execute the query. To read the result (i.e., the KiiObjects queried), the subject also needs to have the privilege to read the KiiObjects.
The easiest way to grant the privilege to read the KiiObjects is to permit the
READ_OBJECTS_IN_BUCKETaction to the subject together with the
QUERY_OBJECTS_IN_BUCKETaction. This will allow the subject to read all KiiObjects in the bucket, so they will be able to read the query result.
Alternatively, you can permit the
READ_EXISTING_OBJECTaction on the KiiObjects in the bucket. See KiiObject Access Control for more information about the KiiObject ACL.
You can find the related discussion in ACL Customization Examples.
I cannot delete an ACL entry
You cannot delete default ACL entries applied to scope owners and bucket creators. See Cannot delete default ACL entries of scope owners and creators for more details.
I cannot change the ACL of an application-scope bucket
Changing the ACL of an application-scope bucket requires the app administrator privilege. Follow the procedure described in Admin Features to get an app administrator token and change the ACL with the steps described in Customizing a Bucket's ACL.
For more information about who can change a bucket's ACL, see Bucket Access Control.