code: public Policy addBucketIamMember(String bucketName, Role role, Identity identity) {
      // [START add_bucket_iam_member]
      // Initialize a Cloud Storage client
      Storage storage = StorageOptions.getDefaultInstance().getService();
  
      // Get IAM Policy for a bucket
      Policy policy = storage.getIamPolicy(bucketName);
  
      // Add identity to Bucket-level IAM role
      Policy updatedPolicy =
          storage.setIamPolicy(bucketName, policy.toBuilder().addIdentity(role, identity).build());
  
      if (updatedPolicy.getBindings().get(role).contains(identity)) {
        System.out.printf("Added %s with role %s to %s\n", identity, role, bucketName);
      }
      // [END add_bucket_iam_member]
      return updatedPolicy;
    }
docs: Example of adding a member to the Bucket-level IAM