code: public Policy replaceSubscriptionPolicy(String subscriptionId) throws Exception {
      // [START pubsub_set_subscription_policy]
      try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
        ProjectSubscriptionName subscriptionName =
            ProjectSubscriptionName.of(projectId, subscriptionId);
        Policy policy = subscriptionAdminClient.getIamPolicy(subscriptionName.toString());
        // Create a role => members binding
        Binding binding =
            Binding.newBuilder()
                .setRole(Role.viewer().toString())
                .addMembers(Identity.allAuthenticatedUsers().toString())
                .build();
        // Update policy
        Policy updatedPolicy = policy.toBuilder().addBindings(binding).build();
  
        updatedPolicy =
            subscriptionAdminClient.setIamPolicy(subscriptionName.toString(), updatedPolicy);
        return updatedPolicy;
      }
      // [END pubsub_set_subscription_policy]
    }
docs: Example of replacing a subscription policy.