The examples below use the Java API to manage users, roles, and permissions. There's two styles of Kinetica API calls featured: using the specific request object and the passing of values in the parameter list. All of our API functions support both styles.
Authenticating endpoint calls to Kinetica requires setting the username and
password in the creation of the Kinetica instance. First, you will use the URL
for the Kinetica proxy, e.g., http://<kinetica.server>:8082/gpudb-0
. Then,
you must create a GPUdbBase.Options
instance, in which you will set the
username and password. This gets passed to GPUdb constructor. All subsequent
API calls will use the username and password set in the Kinetica instance.
Note
API authentication is only required if you've setup HTTPD for Kinetica.
GPUdbBase.Options options = new GPUdbBase.Options();
options.setUsername(USERNAME);
options.setPassword(PASSWORD);
this.gpudb = new GPUdb(GPUDB_PROXY_URL,options);
//Create a system admin role
gpudb.createRole("sample_system_admin_role",null);
//Assign permissions to role
GrantPermissionSystemRequest grantSystemRequest = new GrantPermissionSystemRequest();
grantSystemRequest.setName("sample_system_admin_role");
grantSystemRequest.setPermission(GrantPermissionSystemRequest.Permission.SYSTEM_ADMIN);
gpudb.grantPermissionSystem(grantSystemRequest);
//Create a new user and give it the new sample_system_admin_role
gpudb.createUserInternal("testadmin", "testadmin", null);
gpudb.grantRole("sample_system_admin_role", "testadmin",null);
//revoke testadmin's membership in sample_system_admin_role
gpudb.revokeRole("sample_system_admin_role", "testadmin", null);
//grant limiteduser read permission for securityTestTable
GrantPermissionTableRequest request = new GrantPermissionTableRequest();
request.setName("limiteduser");
request.setPermission(GrantPermissionTableRequest.Permission.TABLE_READ);
request.setTableName("securityTestTable");
gpudb.grantPermissionTable(request);
Note
If request.setTableName was not called, the user would be granted read permissions on all tables at the root level.
gpudb.revokePermissionTable("limiteduser", RevokePermissionTableRequest.Permission.TABLE_READ, "securityTestTable", null);
Note
If the table name was not set when granting the permission, revoking permissions on a specific table will have no effect. This is because the user would have been granted permissions to all tables at the root level. Revoking access to an individual table still leaves the user with access to all tables. Revokation must be done on "" or using the request object and not setting the table name.
ShowSecurityResponse response = gpudb.showSecurity(Arrays.asList("sample_system_admin_role"),null);
System.out.printf("Show security for sample_system_admin_role: %s\n",response.toString());
Produces the output:
Show security for sample_system_admin_role: {"types": {"sample_system_admin_role": "role"}, "roles": {}, "permissions": {"sample_system_admin_role": [{"permission": "system_admin"}]}}
response = gpudb.showSecurity(Arrays.asList("limiteduser"),null);
System.out.printf("Show security for limitedUser: %s\n",response.toString());
Produces the output:
Show security for limitedUser: {"types": {"limiteduser": "internal_user"}, "roles": {"limiteduser": ["authenticated", "public"]}, "permissions": {"limiteduser": [{"table_name": "securityTestTable", "filter_expression": "", "permission": "table_read"}]}}
Differences between using an external user instead of an internal user:
@
symbol followed by the LDAP
username.Note
Kinetica LDAP integration only uses the username, not LDAP groups. Therefore, all role management of users, regardless of internal or external, must be done within Kinetica.
Below is an example using the external jdoe
account that gets added to LDAP
by a LDAP initialization script.
try {
//Create a system admin role
gpudb.createRole("sample_system_admin_role",null);
//Assign permissions to role
GrantPermissionSystemRequest grantSystemRequest = new GrantPermissionSystemRequest();
grantSystemRequest.setName("sample_system_admin_role");
grantSystemRequest.setPermission(GrantPermissionSystemRequest.Permission.SYSTEM_ADMIN);
gpudb.grantPermissionSystem(grantSystemRequest);
//Create a new external user and give it the new sample_system_admin_role
gpudb.createUserExternal("@jdoe",null);
gpudb.grantRole("sample_system_admin_role", "@jdoe",null);
//Connect as the external user and create a table
GPUdb testGPUdb = new GPUdb(PROXY_URL,new GPUdbBase.Options().setUsername("jdoe").setPassword("jdoe"));
try{
System.out.printf("Creating table as @jdoe\n");
String typeId = RecordObject.createType(WeatherRecord.class, testGPUdb);
testGPUdb.addKnownType(typeId, WeatherRecord.class);
testGPUdb.createTable(TABLE_NAME, typeId, null);
System.out.printf("created table\n");
}
catch(GPUdbException ex){
System.out.printf("failed to create table:%s\n", ex.getMessage());
}
System.out.println("Was the table created? " + tableExists(gpudb,TABLE_NAME));
} catch (GPUdbException ex) {
Logger.getLogger(SecuritySamples.class.getName()).log(Level.SEVERE, null, ex);
}