Tabnine Logo
MSentryRole
Code IndexAdd Tabnine to your IDE (free)

How to use
MSentryRole
in
org.apache.sentry.provider.db.service.model

Best Java code snippets using org.apache.sentry.provider.db.service.model.MSentryRole (Showing top 20 results out of 315)

origin: apache/sentry

private void createRoleIfNotExist(PersistenceManager pm,
  Set<String> existRoleNames, String roleName) throws Exception {
 String lowerRoleName = trimAndLower(roleName);
 // if the rolenName doesn't exist, create it.
 if (!existRoleNames.contains(lowerRoleName)) {
  // update the exist role name set
  existRoleNames.add(lowerRoleName);
  // Create role in the persistent storage
  pm.makePersistent(new MSentryRole(trimAndLower(roleName)));
 }
}
origin: apache/sentry

/**
 * Removes all the privileges associated with
 * a particular role. After this dis-association if the
 * privilege doesn't have any roles associated it will be
 * removed from the underlying persistence layer.
 * @param pm Instance of PersistenceManager
 * @param sentryRole Role for which all the privileges are to be removed.
 */
private void removePrivileges(PersistenceManager pm, MSentryRole sentryRole) {
 List<MSentryPrivilege> privilegesCopy = new ArrayList<>(sentryRole.getPrivileges());
 List<MSentryGMPrivilege> gmPrivilegesCopy = new ArrayList<>(sentryRole.getGmPrivileges());
 sentryRole.removePrivileges();
 // with SENTRY-398 generic model
 sentryRole.removeGMPrivileges();
 removeStaledPrivileges(pm, privilegesCopy);
 removeStaledGMPrivileges(pm, gmPrivilegesCopy);
}
origin: apache/sentry

private TSentryRole convertToTSentryRole(MSentryRole mSentryRole) {
 String roleName = mSentryRole.getRoleName().intern();
 Set<MSentryGroup> groups = mSentryRole.getGroups();
 Set<TSentryGroup> sentryGroups = new HashSet<>(groups.size());
 for(MSentryGroup mSentryGroup: groups) {
  TSentryGroup group = convertToTSentryGroup(mSentryGroup);
  sentryGroups.add(group);
 }
 return new TSentryRole(roleName, sentryGroups, EMPTY_GRANTOR_PRINCIPAL);
}
origin: apache/sentry

private Map<String, Set<String>> getUserRolesMap(Collection<MSentryRole> mSentryRoles) {
 if (mSentryRoles.isEmpty()) {
  return Collections.emptyMap();
 }
 Map<String, Set<String>> userRolesMap = new HashMap<>();
 // change the List<MSentryRole> -> Map<userName, Set<roleName>>
 for (MSentryRole mSentryRole : mSentryRoles) {
  Set<MSentryUser> users = mSentryRole.getUsers();
  for (MSentryUser user : users) {
   String userName = user.getUserName();
   Set<String> rNames = userRolesMap.get(userName);
   if (rNames == null) {
    rNames = new HashSet<>();
   }
   rNames.add(mSentryRole.getRoleName());
   userRolesMap.put(userName, rNames);
  }
 }
 return userRolesMap;
}
origin: apache/incubator-sentry

pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis()));
commitTransaction(pm);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
assertEquals(1, role.getPrivileges().size());
assertEquals(1, role.getGmPrivileges().size());
commitTransaction(pm);
solrPrivilege = (MSentryGMPrivilege)role.getGmPrivileges().toArray()[0];
solrPrivilege.removeRole(role);
pm.makePersistent(solrPrivilege);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
assertEquals(1, role.getPrivileges().size());
assertEquals(0, role.getGmPrivileges().size());
commitTransaction(pm);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
hivePrivilege = (MSentryPrivilege)role.getPrivileges().toArray()[0];
hivePrivilege.removeRole(role);
pm.makePersistent(hivePrivilege);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
assertEquals(0, role.getPrivileges().size());
assertEquals(0, role.getGmPrivileges().size());
origin: apache/sentry

private Set<MSentryPrivilege> getMSentryPrivilegesByRoleName(String roleName)
  throws Exception {
 MSentryRole mSentryRole = getMSentryRoleByName(roleName);
 return mSentryRole.getPrivileges();
}
origin: apache/incubator-sentry

private void dropSentryRoleCore(PersistenceManager pm, String roleName)
  throws SentryNoSuchObjectException {
 String lRoleName = roleName.trim().toLowerCase();
 Query query = pm.newQuery(MSentryRole.class);
 query.setFilter("this.roleName == t");
 query.declareParameters("java.lang.String t");
 query.setUnique(true);
 MSentryRole sentryRole = (MSentryRole) query.execute(lRoleName);
 if (sentryRole == null) {
  throw new SentryNoSuchObjectException("Role: " + lRoleName + " doesn't exist");
 } else {
  pm.retrieve(sentryRole);
  int numPrivs = sentryRole.getPrivileges().size();
  sentryRole.removePrivileges();
  // with SENTRY-398 generic model
  sentryRole.removeGMPrivileges();
  privCleaner.incPrivRemoval(numPrivs);
  pm.deletePersistent(sentryRole);
 }
}
origin: apache/sentry

/**
 * Return set of rolenames from a collection of roles
 * @param roles - collection of roles
 * @return set of role names for each role in collection
 */
public static Set<String> rolesToRoleNames(final Iterable<MSentryRole> roles) {
 Set<String> roleNames = new HashSet<>();
 for (MSentryRole mSentryRole : roles) {
  roleNames.add(mSentryRole.getRoleName());
 }
 return roleNames;
}
origin: apache/incubator-sentry

public Map<String, Set<TSentryPrivilege>> getRoleNameTPrivilegesMap() throws Exception {
 boolean rollbackTransaction = true;
 PersistenceManager pm = null;
 try {
  pm = openTransaction();
  Query query = pm.newQuery(MSentryRole.class);
  List<MSentryRole> mSentryRoles = (List<MSentryRole>) query.execute();
  Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap = Maps.newHashMap();
  if (mSentryRoles != null) {
   // change the List<MSentryRole> -> Map<roleName, Set<TSentryPrivilege>>
   for (MSentryRole mSentryRole : mSentryRoles) {
    Set<TSentryPrivilege> privilegeSet = convertToTSentryPrivileges(mSentryRole
      .getPrivileges());
    if (privilegeSet != null && !privilegeSet.isEmpty()) {
     sentryRolePrivilegesMap.put(mSentryRole.getRoleName(), privilegeSet);
    }
   }
  }
  commitTransaction(pm);
  rollbackTransaction = false;
 return sentryRolePrivilegesMap;
 } finally {
  if (rollbackTransaction) {
   rollbackTransaction(pm);
  }
 }
}
origin: apache/incubator-sentry

} else {
 pm.retrieve(sentryRole);
 sentryRole.removeGMPrivileges();
 sentryRole.removePrivileges();
 pm.deletePersistent(sentryRole);
origin: apache/sentry

@Test
public void testAddDeleteGroups() throws Exception {
 String roleName = "test-groups";
 String grantor = "g1";
 createRole(roleName);
 Set<TSentryGroup> groups = Sets.newHashSet();
 TSentryGroup group = new TSentryGroup();
 group.setGroupName("test-groups-g1");
 groups.add(group);
 group = new TSentryGroup();
 group.setGroupName("test-groups-g2");
 groups.add(group);
 sentryStore.alterSentryRoleAddGroups(grantor, roleName, groups);
 sentryStore.alterSentryRoleDeleteGroups(roleName, groups);
 MSentryRole role = sentryStore.getMSentryRoleByName(roleName);
 assertEquals(Collections.emptySet(), role.getGroups());
}
origin: apache/sentry

 grantPrivilege.setAction(ac.getValue());
 MSentryGMPrivilege existPriv = getPrivilege(grantPrivilege, pm);
 if (existPriv != null && role.getGmPrivileges().contains(existPriv)) {
if (allPrivilege != null && role.getGmPrivileges().contains(allPrivilege)) {
 return;
origin: apache/incubator-sentry

private void revokeRolePartial(PersistenceManager pm, MSentryRole mRole,
  MSentryPrivilege currentPrivilege, MSentryPrivilege persistedPriv, String addAction)
  throws SentryInvalidInputException {
 // If table / URI, remove ALL
 persistedPriv.removeRole(mRole);
 privCleaner.incPrivRemoval();
 pm.makePersistent(persistedPriv);
 currentPrivilege.setAction(AccessConstants.ALL);
 persistedPriv = getMSentryPrivilege(convertToTSentryPrivilege(currentPrivilege), pm);
 if (persistedPriv != null && mRole.getPrivileges().contains(persistedPriv)) {
  persistedPriv.removeRole(mRole);
  privCleaner.incPrivRemoval();
  pm.makePersistent(persistedPriv);
  currentPrivilege.setAction(addAction);
  persistedPriv = getMSentryPrivilege(convertToTSentryPrivilege(currentPrivilege), pm);
  if (persistedPriv == null) {
   persistedPriv = convertToMSentryPrivilege(convertToTSentryPrivilege(currentPrivilege));
   mRole.appendPrivilege(persistedPriv);
  }
  persistedPriv.appendRole(mRole);
  pm.makePersistent(persistedPriv);
 }
}
origin: apache/incubator-sentry

public void appendRole(MSentryRole role) {
 if (roles.add(role)) {
  role.appendGMPrivilege(this);
 }
}
origin: apache/incubator-sentry

public void appendRole(MSentryRole role) {
 if (roles.add(role)) {
  role.appendGroup(this);
 }
}
origin: apache/sentry

@Test
public void testAddDeleteUsers() throws Exception {
 String roleName = "test-users";
 createRole(roleName);
 Set<String> users = Sets.newHashSet("test-user-u1", "test-user-u2");
 sentryStore.alterSentryRoleAddUsers(roleName, users);
 MSentryRole role = sentryStore.getMSentryRoleByName(roleName);
 role.getUsers().size();
 sentryStore.alterSentryRoleDeleteUsers(roleName, users);
 role = sentryStore.getMSentryRoleByName(roleName);
 assertEquals(0, role.getUsers().size());
}
origin: apache/sentry

pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis()));
commitTransaction(pm);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
assertEquals(1, role.getPrivileges().size());
assertEquals(1, role.getGmPrivileges().size());
commitTransaction(pm);
solrPrivilege = (MSentryGMPrivilege)role.getGmPrivileges().toArray()[0];
solrPrivilege.removeRole(role);
pm.makePersistent(solrPrivilege);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
assertEquals(1, role.getPrivileges().size());
assertEquals(0, role.getGmPrivileges().size());
commitTransaction(pm);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
hivePrivilege = (MSentryPrivilege)role.getPrivileges().toArray()[0];
hivePrivilege.removePrincipal(role);
pm.makePersistent(hivePrivilege);
role = getMSentryRole(pm, roleName);
pm.retrieve(role);
assertEquals(0, role.getPrivileges().size());
assertEquals(0, role.getGmPrivileges().size());
origin: apache/incubator-sentry

private Set<MSentryPrivilege> getMSentryPrivilegesByRoleName(String roleName)
  throws SentryNoSuchObjectException {
 MSentryRole mSentryRole = getMSentryRoleByName(roleName);
 return mSentryRole.getPrivileges();
}
origin: apache/sentry

private Set<String> convertToRoleNameSet(Set<MSentryRole> mSentryRoles) {
 if (mSentryRoles.isEmpty()) {
  return Collections.emptySet();
 }
 Set<String> roleNameSet = new HashSet<>(mSentryRoles.size());
 for (MSentryRole role : mSentryRoles) {
  roleNameSet.add(role.getRoleName());
 }
 return roleNameSet;
}
origin: apache/sentry

for (MSentryRole mSentryRole : mSentryRoles) {
 Set<TSentryPrivilege> tPrivileges = convertToTSentryPrivileges(mSentryRole.getPrivileges());
 allRolesPrivileges.put(mSentryRole.getRoleName(), tPrivileges);
org.apache.sentry.provider.db.service.modelMSentryRole

Javadoc

Database backed Sentry Role. Any changes to this object require re-running the maven build so DN an re-enhance.

Most used methods

  • <init>
  • getGmPrivileges
  • getGroups
  • getPrivileges
  • removeGMPrivileges
  • removePrivileges
  • getRoleName
  • appendGMPrivilege
  • appendGroup
  • getUsers
  • removeGMPrivilege
  • removeGroup
  • removeGMPrivilege,
  • removeGroup,
  • appendPrivilege,
  • appendUser,
  • removePrivilege,
  • removeUser

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • putExtra (Intent)
  • getSystemService (Context)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Menu (java.awt)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • Kernel (java.awt.image)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now