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.
Bucket ACL entries
A bucket ACL entry is composed of an action and a subject:
Action
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
bucketActionCreateObjects
Create new KiiObjects in the bucket.
QUERY_OBJECTS_IN_BUCKET
bucketActionQueryObjects
Query KiiObjects in the bucket.
READ_OBJECTS_IN_BUCKET
bucketActionReadObjects
Read KiiObjects in the bucket.
DROP_BUCKET_WITH_ALL_CONTENT
bucketActionDropBucket
Drop the bucket along with all KiiObjects inside.
* These symbols are defined in the KiiACLAction enumeration and can be specified like KiiACLAction.bucketActionCreateObjects.
Note: The "bucketActionReadObjects" action allows the subject to unconditionally read all KiiObjects in the bucket. For more information, see ACL Customization Examples.
Subject
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".
Managing a bucket's ACL
You can add and delete an ACL entry in a bucket's ACL. You can also get a list of ACL entries.
Adding a bucket ACL entry
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 bucketActionQueryObjects and bucketActionCreateObjects actions are permitted to KiiAnyAuthenticatedUser.
Swift:
Objective-C:
Create a KiiACL instance of the bucket by calling the bucketACL() method.
Create KiiACLEntry instances and pass them as the argument of the put(_:) method. Here, KiiAnyAuthenticatedUser instances are specified as the ACL entries' subjects so as to permit the actions to any authenticated users. If you set KiiAnonymousUser instances 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 succeeded and failed to register from succeeded and failed in the sample code.
Deleting a bucket ACL entry
To delete an ACL entry, create a KiiACLEntry instance with the grant argument 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.
Swift:
Objective-C:
Note that the remove(_:) method of the KiiACL class 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 bucketActionQueryObjects and bucketActionCreateObjects actions from acl on the client and then execute the save(_:) method to reflect the requests on the server. If you execute the remove(_:) method, it would remove these requests from the ACL modification list, but not from the ACL on the server.
Getting a bucket's ACL
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 an NSAarray.
Swift:
Objective-C:
Create a KiiACL instance of the bucket by executing the bucketACL() method.
Call the listACLEntries(_:) method to get the bucket's ACL as a NSArray of the KiiACLEntry instances.
Parse through each ACL entry in the NSArray.
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.
Troubleshooting
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 "bucketActionQueryObjects" action but failed to query KiiObjects in the bucket
The bucketActionQueryObjects action 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 bucketActionReadObjects action to the subject together with the bucketActionQueryObjects action. 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 objectActionRead action on the KiiObjects in the bucket. See KiiObject Access Control for more information about the KiiObject ACL.
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.