@Test
public void connectIt() throws Exception {
System.setProperty("hadoop.home.dir", "your hdp dir");
String keyTabPath = "your keytab file";
String krb5ConfPath = "your krb5.conf file";
System.setProperty("java.security.krb5.conf", krb5ConfPath);
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab("your principal in keytab and also the one you want to login", keyTabPath);
conf.set(ServiceConstants.ClientConfig.SERVER_RPC_ADDRESS, "sentry thrift server rpc address");
conf.set(ServiceConstants.ClientConfig.SERVER_RPC_PORT, "sentry thrift server rpc pirt");
conf.set(ServiceConstants.ServerConfig.PRINCIPAL, "this is the kerberos pricipal that started you sentry thrift server!!!");
SentryPolicyServiceClient client = SentryServiceClientFactory.create(conf);
Set<TSentryPrivilege> set = client.listAllPrivilegesByRoleName("admin", "some_rolename");
if(CollectionUtils.isNotEmpty(set))
System.out.println(set.size());
for(TSentryPrivilege privilege : set){
System.out.println(privilege.getPrivilegeScope() + ":" + privilege.getServerName() + "." + privilege.getDbName() + "." + privilege.getTableName() + "." + privilege.getColumnName());
}
}
here is the maven libs:version is 1.5.1-cdh5.14.0<dependency>
<groupId>org.apache.sentry</groupId>
<artifactId>sentry-provider-db</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sentry</groupId>
<artifactId>sentry-binding-hive</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sentry</groupId>
<artifactId>sentry-binding-hive-conf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sentry</groupId>
<artifactId>sentry-core-common</artifactId>
</dependency>