}
// import policy files
public void importPolicy() throws Exception {
final String requestorUserName = "hive";
SimpleFileProviderBackend policyFileBackend;
SentryPolicyServiceClient client;
policyFileBackend = new SimpleFileProviderBackend(getAuthzConf(),
getAuthzConf().get(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar()));
ProviderBackendContext context = new ProviderBackendContext();
context.setAllowPerDatabase(true);
policyFileBackend.initialize(context);
client = new SentryPolicyServiceClient(getAuthzConf());
Set<String> roles = new HashSet<String>();
for (TSentryRole sentryRole : client.listRoles(requestorUserName)) {
roles.add(sentryRole.getRoleName());
}
Table<String, String, Set<String>> groupRolePrivilegeTable =
policyFileBackend.getGroupRolePrivilegeTable();
for(String groupName : groupRolePrivilegeTable.rowKeySet()) {
for(String roleName : groupRolePrivilegeTable.columnKeySet()) {
if (!roles.contains(roleName)) {
client.createRole(requestorUserName, roleName);
System.out.println(String.format("CREATE ROLE %s;", roleName));