grantRole()
This operation grants a role to a user.
public void grantRole(GrantRoleReq request)
Request Syntax
grantRole(GrantRoleReq.builder()
.roleName(String roleName)
.userName(String userName)
.build()
)
BUILDER METHODS:
-
roleName(String roleName)
The name of the role to assign.
-
userName(String userName)
The name of an existing user.
RETURNS:
void
EXCEPTIONS:
-
MilvusClientExceptions
This exception will be raised when any error occurs during this operation.
Example
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.rbac.request.GrantRoleReq;
// 1. Set up a client
ConnectConfig connectConfig = ConnectConfig.builder()
.uri("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.build();
MilvusClientV2 client = new MilvusClientV2(connectConfig);
// 2. Grant role to a user
GrantRoleReq grantRoleReq = GrantRoleReq.builder()
.roleName("db_ro")
.userName("test")
.build();
client.grantRole(grantRoleReq);