DataSyncGrant
Fluent DataSync PAM v3 resource grant, passed to grantToken(...).authorizedUserId(...).grants(...).
Every DataSync resource is granted here, on an exact resource id or on a regex pattern:
- entity / entityPattern →
datasync:entitiesbucket; - relationship / relationshipPattern →
datasync:relationshipsbucket; - membership / membershipPattern →
datasync:membershipsbucket; - channel / channelPattern → the plain
channelsbucket; - user / userPattern → the plain
usersbucket.
It extends PNDataSyncResource rather than PNResource, so only the four DataSync-relevant permission flags (get/create/update/delete) are exposed — the PubSub-only bits (read/write/manage/join) are not part of the DataSync permission model.
Shared channels bucket: DataSync channels share the channels bucket with pub/sub and App Context v2, so channel(id).update() also authorizes App Context v2 setChannelMetadata for the same id (and get/delete likewise). Grants on the same id are OR-merged, so combining a ChannelGrant and a channel(...) grant on one id is safe: the token carries the union of both.
entity, relationship, channel and user grants (and their pattern variants) can also carry an optional projection: when this client uses the token to access this resource, they see it through this projection. A projection is a named, filtered view of a resource's fields, defined in the class schema under projections. When set, the SDK emits the matching pn-projections entry into the token meta automatically. Leave it unset to use the implicit __default__ projection. Don't write pn-projections into the token meta yourself: grantToken rejects a caller meta that contains it.
Which projections a resource has depends on its class:
- entities and relationships: the projections declared by their custom class;
- channels and users: only
__default__for the built-inChannel/Userclasses. A named projection only has an effect for a custom Channel / User subclass that declares it; - memberships: always
__default__(the built-inMembershipclass has no named projections), soprojection(...)on a membership grant throws.
These grants authorize DataSync REST CRUD (get/create/update/delete) on the resource record only. They do not authorize subscribing to realtime events: a realtime subscribe is a plain PubSub read of the resource's ref-channel. Use subscribe / subscribePattern for that. They resolve the ref-channel names for you. See the subscription(...) methods on the DataSync handles (com.pubnub.api.java.v2.entities.DataSyncEntity, com.pubnub.api.java.v2.entities.DataSyncChannel, com.pubnub.api.java.v2.entities.DataSyncUser).
pubnub.grantToken(60)
.authorizedUserId(new UserId("my-authorized-user"))
.grants(Arrays.asList(
// entities
DataSyncGrant.entity("capy-001").get().update().projection("admin"),
DataSyncGrant.entityPattern("capy-.*").get(),
// relationships
DataSyncGrant.relationship("user.A:channel.X").get().projection("admin"),
DataSyncGrant.relationshipPattern("user\\.A:.*").get(),
// memberships
DataSyncGrant.membership("user-123:channel-X").get().delete(),
DataSyncGrant.membershipPattern("user-123:.*").get(),
// channels (plain `channels` bucket)
DataSyncGrant.channel("chat-1").get().update().projection("admin"),
DataSyncGrant.channelPattern("chat-.*").get(),
// users (plain `users` bucket)
DataSyncGrant.user("user-123").get().update(),
DataSyncGrant.userPattern("user-.*").get().create(),
// realtime subscribe (pub/sub `read` on the resolved ref-channel)
DataSyncGrant.subscribe("capy-001"), // read on "capy-001"
DataSyncGrant.subscribe("chat-1", "admin"), // read on "__admin__chat-1"
// default projection publishes on the bare id, so no prefix; `^` keeps it off the `__admin__capy-…` mirrors
DataSyncGrant.subscribePattern("capy-.*"), // read on "^(?:capy-.*)"
DataSyncGrant.subscribePattern("chat-.*", "admin") // read on "^__admin__(?:chat-.*)"
))
.sync();
Properties
Functions
pattern, as seen through projection.id) of a DataSync entity, user or channel.read on refChannel (id for the default projection, __{projection}__{id} otherwise).