SentryStore { public CommitContext createSentryRole(String roleName) throws SentryAlreadyExistsException { roleName = trimAndLower(roleName); boolean rollbackTransaction = true; PersistenceManager pm = null; try { pm = openTransaction(); createSentryRoleCore(pm, roleName); CommitContext commit = commitUpdateTransaction(pm); rollbackTransaction = false; return commit; } finally { if (rollbackTransaction) { rollbackTransaction(pm); } } } SentryStore(Configuration conf); synchronized void stop(); synchronized PersistenceManager openTransaction(); synchronized CommitContext commitUpdateTransaction(PersistenceManager pm); void commitTransaction(PersistenceManager pm); void rollbackTransaction(PersistenceManager pm); MSentryRole getMSentryRole(PersistenceManager pm, String roleName); CommitContext createSentryRole(String roleName); Gauge<Long> getRoleCountGauge(); Gauge<Long> getPrivilegeCountGauge(); Gauge<Long> getGroupCountGauge(); CommitContext alterSentryRoleGrantPrivilege(String grantorPrincipal,
      String roleName, TSentryPrivilege privilege); CommitContext alterSentryRoleGrantPrivileges(String grantorPrincipal,
      String roleName, Set<TSentryPrivilege> privileges); CommitContext alterSentryRoleRevokePrivilege(String grantorPrincipal,
      String roleName, TSentryPrivilege tPrivilege); CommitContext alterSentryRoleRevokePrivileges(String grantorPrincipal,
      String roleName, Set<TSentryPrivilege> tPrivileges); CommitContext dropSentryRole(String roleName); CommitContext alterSentryRoleAddGroups( String grantorPrincipal, String roleName,
      Set<TSentryGroup> groupNames); CommitContext alterSentryRoleDeleteGroups(String roleName,
      Set<TSentryGroup> groupNames); TSentryPrivilegeMap listSentryPrivilegesByAuthorizable(
      Set<String> groups, TSentryActiveRoleSet activeRoles,
      TSentryAuthorizable authHierarchy, boolean isAdmin); Set<TSentryPrivilege> getAllTSentryPrivilegesByRoleName(String roleName); Set<TSentryPrivilege> getTSentryPrivileges(Set<String> roleNames, TSentryAuthorizable authHierarchy); Set<TSentryRole> getTSentryRolesByGroupName(Set<String> groupNames,
      boolean checkAllGroups); Set<String> getRoleNamesForGroups(Set<String> groups); Set<MSentryRole> getRolesForGroups(PersistenceManager pm, Set<String> groups); Set<String> listAllSentryPrivilegesForProvider(Set<String> groups, TSentryActiveRoleSet roleSet); Set<String> listSentryPrivilegesForProvider(Set<String> groups,
      TSentryActiveRoleSet roleSet, TSentryAuthorizable authHierarchy); boolean hasAnyServerPrivileges(Set<String> groups, TSentryActiveRoleSet roleSet, String server); String getSentryVersion(); void setSentryVersion(String newVersion, String verComment); void dropPrivilege(TSentryAuthorizable tAuthorizable); void renamePrivilege(TSentryAuthorizable tAuthorizable,
      TSentryAuthorizable newTAuthorizable); static String toNULLCol(String s); static String fromNULLCol(String s); static boolean isNULL(String s); Map<String, HashMap<String, String>> retrieveFullPrivilegeImage(); Map<String, LinkedList<String>> retrieveFullRoleImage(); Map<String, Set<String>> getGroupNameRoleNamesMap(); Map<String, Set<TSentryPrivilege>> getRoleNameTPrivilegesMap(); Set<String> getAllRoleNames(); void importSentryMetaData(TSentryMappingData tSentryMappingData, boolean isOverwriteForRole); static String NULL_COL; }
@Test public void testCreateDuplicateRole() throws Exception { String roleName = "test-dup-role"; sentryStore.createSentryRole(roleName); try { sentryStore.createSentryRole(roleName); fail("Expected SentryAlreadyExistsException"); } catch(SentryAlreadyExistsException e) { } }