Package org.apache.sentry.provider.db.service.thrift

Examples of org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient


import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;

public class SentryServiceClientFactory {

  public SentryPolicyServiceClient create(Configuration conf) throws Exception {
    SentryPolicyServiceClient client = new SentryPolicyServiceClient(conf);
    return client;
  }
View Full Code Here


    // DB Provider doesn't use policy file path
    this(conf);
  }

  public SimpleDBProviderBackend(Configuration conf) throws IOException {
    this(new SentryPolicyServiceClient(conf));
  }
View Full Code Here

  private void dropSentryPrivileges(
      List<? extends Authorizable> authorizableTable)
      throws SentryUserException, IOException, MetaException {
    String requestorUserName = UserGroupInformation.getCurrentUser()
        .getShortUserName();
    SentryPolicyServiceClient sentryClient = getSentryServiceClient();
    sentryClient.dropPrivileges(requestorUserName, authorizableTable);
  }
View Full Code Here

    newAuthorizableTable.add(new Table(newTabName));

    try {
      String requestorUserName = UserGroupInformation.getCurrentUser()
          .getShortUserName();
      SentryPolicyServiceClient sentryClient = getSentryServiceClient();
      sentryClient.renamePrivileges(requestorUserName, oldAuthorizableTable, newAuthorizableTable);
    } catch (SentryUserException e) {
      throw new MetaException(
          "Failed to remove Sentry policies for rename table " + oldDbName
              + "." + oldTabName + "to " + newDbName + "." + newTabName
              + " Error: " + e.getMessage());
View Full Code Here

  // 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));
          roles.add(roleName);
        }

        Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName);
        if (privileges == null) {
          continue;
        }
        client.grantRoleToGroup(requestorUserName, groupName, roleName);
        System.out.println(String.format("GRANT ROLE %s TO GROUP %s;",
            roleName, groupName));

        for (String permission : privileges) {
          String server = null;
          String database = null;
          String table = null;
          String uri = null;
          String action = AccessConstants.ALL;
          for (String authorizable : PolicyFileConstants.AUTHORIZABLE_SPLITTER.
              trimResults().split(permission)) {
            KeyValue kv = new KeyValue(authorizable);
            DBModelAuthorizable a = DBModelAuthorizables.from(kv);
            if (a == null) {
              action = kv.getValue();
              continue;
            }

            switch (a.getAuthzType()) {
              case Server:
                server = a.getName();
                break;
              case Db:
                database = a.getName();
                break;
              case Table:
              case View:
                table = a.getName();
                break;
              case URI:
                uri = a.getName();
                break;
              default:
                break;
            }
          }

          if (uri != null) {
            System.out.println(String.format(
                "GRANT ALL ON URI %s TO ROLE %s; # server=%s",
                uri, roleName, server));

            client.grantURIPrivilege(requestorUserName, roleName, server, uri);
          } else if (table != null && !AccessConstants.ALL.equals(table)) {
            System.out.println(String.format(
                "GRANT %s ON TABLE %s TO ROLE %s; # server=%s, database=%s",
                "*".equals(action) ? "ALL" : action.toUpperCase(), table,
                roleName, server, database));

            client.grantTablePrivilege(requestorUserName, roleName, server,
                database, table, action);
          } else if (database != null && !AccessConstants.ALL.equals(database)) {
            System.out.println(String.format(
                "GRANT %s ON DATABASE %s TO ROLE %s; # server=%s",
                "*".equals(action) ? "ALL" : action.toUpperCase(),
                database, roleName, server));

            client.grantDatabasePrivilege(requestorUserName, roleName, server,
                database, action);
          } else if (server != null) {
            System.out.println(String.format("GRANT ALL ON SERVER %s TO ROLE %s;",
                server, roleName));

            client.grantServerPrivilege(requestorUserName, roleName, server);
          } else {
            System.out.println(String.format("No grant for permission %s",
                permission));
          }
        }
View Full Code Here

    configTool.setPolicyFile(context.getPolicyFile().getPath());
    configTool.setupConfig();

    configTool.importPolicy();

    SentryPolicyServiceClient client = new SentryPolicyServiceClient(configTool.getAuthzConf());
    verifyRoles(client, "analyst", "analyst_role", "customers_select_role");
    verifyRoles(client, "jranalyst", "junior_analyst_role");
    verifyRoles(client, "manager", "analyst_role", "junior_analyst_role",
        "customers_insert_role", "customers_select_role");
    verifyRoles(client, "customers_admin", "customers_admin_role");
View Full Code Here

TOP

Related Classes of org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.