Examples of MSentryPrivilege


Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

        // If Grant is for ALL and Either INSERT/SELECT already exists..
        // need to remove it and GRANT ALL..
        if (privilege.getAction().equalsIgnoreCase("*")) {
          TSentryPrivilege tNotAll = new TSentryPrivilege(privilege);
          tNotAll.setAction(AccessConstants.SELECT);
          MSentryPrivilege mSelect = getMSentryPrivilege(
              constructPrivilegeName(tNotAll), pm);
          tNotAll.setAction(AccessConstants.INSERT);
          MSentryPrivilege mInsert = getMSentryPrivilege(
              constructPrivilegeName(tNotAll), pm);
          if ((mSelect != null) && (mRole.getPrivileges().contains(mSelect))) {
            mSelect.removeRole(mRole);
            pm.makePersistent(mSelect);
          }
          if ((mInsert != null) && (mRole.getPrivileges().contains(mInsert))) {
            mInsert.removeRole(mRole);
            pm.makePersistent(mInsert);
          }
        } else {
          // If Grant is for Either INSERT/SELECT and ALL already exists..
          // do nothing..
          TSentryPrivilege tAll = new TSentryPrivilege(privilege);
          tAll.setAction(AccessConstants.ALL);
          MSentryPrivilege mAll = getMSentryPrivilege(
              constructPrivilegeName(tAll), pm);
          if ((mAll != null) && (mRole.getPrivileges().contains(mAll))) {
            return;
          }
        }
      }

      MSentryPrivilege mPrivilege = getMSentryPrivilege(
          constructPrivilegeName(privilege), pm);
      if (mPrivilege == null) {
        mPrivilege = convertToMSentryPrivilege(privilege);
      }
      mPrivilege.appendRole(mRole);
      pm.makePersistent(mRole);
      pm.makePersistent(mPrivilege);
    }
    return;
  }
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

    MSentryRole mRole = (MSentryRole) query.execute(roleName);
    if (mRole == null) {
      throw new SentryNoSuchObjectException("Role: " + roleName);
    } else {
      query = pm.newQuery(MSentryPrivilege.class);
      MSentryPrivilege mPrivilege = getMSentryPrivilege(
          constructPrivilegeName(tPrivilege), pm);
      if (mPrivilege == null) {
        mPrivilege = convertToMSentryPrivilege(tPrivilege);
      } else {
        mPrivilege = (MSentryPrivilege) pm.detachCopy(mPrivilege);
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

   * privilege and add SELECT (INSERT was revoked) or INSERT (SELECT was revoked).
   */
  private void revokePartial(PersistenceManager pm,
      TSentryPrivilege requestedPrivToRevoke, MSentryRole mRole,
      MSentryPrivilege currentPrivilege) throws SentryInvalidInputException {
    MSentryPrivilege persistedPriv = getMSentryPrivilege(constructPrivilegeName(convertToTSentryPrivilege(currentPrivilege)), pm);
    if (persistedPriv == null) {
      persistedPriv = convertToMSentryPrivilege(convertToTSentryPrivilege(currentPrivilege));
    }

    if (requestedPrivToRevoke.getAction().equalsIgnoreCase("ALL") || requestedPrivToRevoke.getAction().equalsIgnoreCase("*")) {
      persistedPriv.removeRole(mRole);
      pm.makePersistent(persistedPriv);
    } else if (requestedPrivToRevoke.getAction().equalsIgnoreCase(AccessConstants.SELECT)
        && (!currentPrivilege.getAction().equalsIgnoreCase(AccessConstants.INSERT))) {
      revokeRolePartial(pm, mRole, currentPrivilege, persistedPriv, AccessConstants.INSERT);
    } else if (requestedPrivToRevoke.getAction().equalsIgnoreCase(AccessConstants.INSERT)
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

      query.setFilter(filters.toString());
      query
          .setResult("privilegeScope, serverName, dbName, tableName, URI, action, grantorPrincipal");
      Set<MSentryPrivilege> privileges = new HashSet<MSentryPrivilege>();
      for (Object[] privObj : (List<Object[]>) query.execute()) {
        MSentryPrivilege priv = new MSentryPrivilege();
        priv.setPrivilegeScope((String) privObj[0]);
        priv.setServerName((String) privObj[1]);
        priv.setDbName((String) privObj[2]);
        priv.setTableName((String) privObj[3]);
        priv.setURI((String) privObj[4]);
        priv.setAction((String) privObj[5]);
        priv.setGrantorPrincipal((String) privObj[6]);
        priv.setPrivilegeName(constructPrivilegeName(convertToTSentryPrivilege(priv)));
        privileges.add(priv);
      }
      rollbackTransaction = false;
      commitTransaction(pm);
      return privileges;
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

   * such as trimming whitespace and setting appropriate case.
   * @throws SentryInvalidInputException
   */
  private MSentryPrivilege convertToMSentryPrivilege(TSentryPrivilege privilege)
      throws SentryInvalidInputException {
    MSentryPrivilege mSentryPrivilege = new MSentryPrivilege();
    mSentryPrivilege.setServerName(safeTrimLower(privilege.getServerName()));
    mSentryPrivilege.setDbName(safeTrimLower(privilege.getDbName()));
    mSentryPrivilege.setTableName(safeTrimLower(privilege.getTableName()));
    mSentryPrivilege.setPrivilegeScope(safeTrim(privilege.getPrivilegeScope()));
    mSentryPrivilege.setAction(safeTrim(privilege.getAction()));
    mSentryPrivilege.setCreateTime(System.currentTimeMillis());
    mSentryPrivilege.setGrantorPrincipal(safeTrim(privilege.getGrantorPrincipal()));
    mSentryPrivilege.setURI(safeTrim(privilege.getURI()));
    mSentryPrivilege.setPrivilegeName(constructPrivilegeName(privilege));
    return mSentryPrivilege;
  }
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

      TSentryPrivilege newTPrivilege) throws SentryNoSuchObjectException,
      SentryInvalidInputException {
    HashSet<MSentryRole> roleSet = Sets.newHashSet();
    tPrivilege.setPrivilegeName(constructPrivilegeName(tPrivilege));

    MSentryPrivilege mPrivilege = getMSentryPrivilege(
        tPrivilege.getPrivilegeName(), pm);
    if (mPrivilege != null) {
      roleSet.addAll(ImmutableSet.copyOf((mPrivilege.getRoles())));
    }
    for (MSentryRole role : roleSet) {
      alterSentryRoleRevokePrivilegeCore(pm, role.getRoleName(), tPrivilege);
      if (newTPrivilege != null) {
        alterSentryRoleGrantPrivilegeCore(pm, role.getRoleName(), newTPrivilege);
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

  private MSentryPrivilege privilege;

  @Test
  public void testServer() {
    privilege = new MSentryPrivilege(null, null, "server1", null, null, null, null);
    assertEquals("server=server1",
        SentryStore.toAuthorizable(privilege));
    privilege = new MSentryPrivilege(null, null, "server1", null, null, null,
        AccessConstants.ALL);
    assertEquals("server=server1",
        SentryStore.toAuthorizable(privilege));
  }
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

        SentryStore.toAuthorizable(privilege));
  }

  @Test
  public void testTable() {
    privilege = new MSentryPrivilege(null, null, "server1", "db1", "tbl1", null, null);
    assertEquals("server=server1->db=db1->table=tbl1",
        SentryStore.toAuthorizable(privilege));
    privilege = new MSentryPrivilege(null, null, "server1", "db1", "tbl1", null,
        AccessConstants.INSERT);
    assertEquals("server=server1->db=db1->table=tbl1->action=insert",
        SentryStore.toAuthorizable(privilege));
    privilege = new MSentryPrivilege(null, null, "server1", "db1", "tbl1", null,
        AccessConstants.SELECT);
    assertEquals("server=server1->db=db1->table=tbl1->action=select",
        SentryStore.toAuthorizable(privilege));
    privilege = new MSentryPrivilege(null, null, "server1", "db1", "tbl1", null,
        AccessConstants.ALL);
    assertEquals("server=server1->db=db1->table=tbl1",
        SentryStore.toAuthorizable(privilege));
  }
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

        SentryStore.toAuthorizable(privilege));
  }

  @Test
  public void testDb() {
    privilege = new MSentryPrivilege(null, null, "server1", "db1", null, null, null);
    assertEquals("server=server1->db=db1",
        SentryStore.toAuthorizable(privilege));
    privilege = new MSentryPrivilege(null, null, "server1", "db1", null, null,
        AccessConstants.ALL);
    assertEquals("server=server1->db=db1",
        SentryStore.toAuthorizable(privilege));
  }
View Full Code Here

Examples of org.apache.sentry.provider.db.service.model.MSentryPrivilege

        SentryStore.toAuthorizable(privilege));
  }

  @Test
  public void testUri() {
    privilege = new MSentryPrivilege(null, null, "server1", null, null, "file:///", null);
    assertEquals("server=server1->uri=file:///",
        SentryStore.toAuthorizable(privilege));
    privilege = new MSentryPrivilege(null, null, "server1", null, null, "file:///",
        AccessConstants.SELECT);
    assertEquals("server=server1->uri=file:///->action=select",
        SentryStore.toAuthorizable(privilege));
    privilege = new MSentryPrivilege(null, null, "server1", null, null, "file:///",
        AccessConstants.ALL);
    assertEquals("server=server1->uri=file:///",
        SentryStore.toAuthorizable(privilege));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.