Java Code Examples for org.apache.hadoop.security.UserGroupInformation#getCurrentUGI()

The following examples show how to use org.apache.hadoop.security.UserGroupInformation#getCurrentUGI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDFSShell.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public void testLsr() throws Exception {
  Configuration conf = new Configuration();
  MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);
  DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem();

  try {
    final String root = createTree(dfs, "lsr");
    dfs.mkdirs(new Path(root, "zzz"));

    runLsr(new FsShell(conf), root, 0);

    final Path sub = new Path(root, "sub");
    dfs.setPermission(sub, new FsPermission((short)0));

    final UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
    final String tmpusername = ugi.getUserName() + "1";
    UnixUserGroupInformation tmpUGI = new UnixUserGroupInformation(
        tmpusername, new String[] {tmpusername});
    UnixUserGroupInformation.saveToConf(conf,
          UnixUserGroupInformation.UGI_PROPERTY_NAME, tmpUGI);
    String results = runLsr(new FsShell(conf), root, -1);
    assertTrue(results.contains("zzz"));
  } finally {
    cluster.shutdown();
  }
}
 
Example 2
Source File: PermissionChecker.java    From RDFS with Apache License 2.0 6 votes vote down vote up
PermissionChecker(String fsOwner, String supergroup
    ) throws AccessControlException{
  UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
  if (LOG.isDebugEnabled()) {
    LOG.debug("ugi=" + ugi);
  }

  if (ugi != null) {
    user = ugi.getUserName();
    groups.addAll(Arrays.asList(ugi.getGroupNames()));
    isSuper = user.equals(fsOwner) || groups.contains(supergroup);
  }
  else {
    throw new AccessControlException("ugi = null");
  }
}
 
Example 3
Source File: TestDFSShell.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
public void testLsr() throws Exception {
  Configuration conf = new Configuration();
  MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);
  DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem();

  try {
    final String root = createTree(dfs, "lsr");
    dfs.mkdirs(new Path(root, "zzz"));
    
    runLsr(new FsShell(conf), root, 0);
    
    final Path sub = new Path(root, "sub");
    dfs.setPermission(sub, new FsPermission((short)0));

    final UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
    final String tmpusername = ugi.getUserName() + "1";
    UnixUserGroupInformation tmpUGI = new UnixUserGroupInformation(
        tmpusername, new String[] {tmpusername});
    UnixUserGroupInformation.saveToConf(conf,
          UnixUserGroupInformation.UGI_PROPERTY_NAME, tmpUGI);
    String results = runLsr(new FsShell(conf), root, -1);
    assertTrue(results.contains("zzz"));
  } finally {
    cluster.shutdown();
  }
}
 
Example 4
Source File: PermissionChecker.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
PermissionChecker(String fsOwner, String supergroup
    ) throws AccessControlException{
  UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
  if (LOG.isDebugEnabled()) {
    LOG.debug("ugi=" + ugi);
  }

  if (ugi != null) {
    user = ugi.getUserName();
    groups.addAll(Arrays.asList(ugi.getGroupNames()));
    isSuper = user.equals(fsOwner) || groups.contains(supergroup);
  }
  else {
    throw new AccessControlException("ugi = null");
  }
}
 
Example 5
Source File: JobTracker.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Allocates a new JobId string.
 */
public JobID getNewJobId() throws IOException {
  JobID id = new JobID(getTrackerIdentifier(), nextJobId.getAndIncrement());

  // get the user group info
  UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();

  // mark the user for this id
  jobToUserMap.put(id, ugi.getUserName());

  LOG.info("Job id " + id + " assigned to user " + ugi.getUserName());

  return id;
}
 
Example 6
Source File: JobTracker.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private void checkAccess(JobInProgress job,
                              QueueManager.QueueOperation oper)
                                throws IOException {
  // get the user group info
  UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
  checkAccess(job, oper, ugi);
}
 
Example 7
Source File: FairSchedulerShell.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private void initialize() throws IOException {
  if (client != null) {
    return;
  }
  InetSocketAddress address = FairScheduler.getAddress(getConf());
  UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
  client = createClient(address, getConf(), ugi);
}
 
Example 8
Source File: HourGlass.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Create a FariScheduler RPC client
 * @param target The host:port of the RPC server
 * @param conf The configuration
 * @return The FairScheduler client
 * @throws IOException
 */
private static FairSchedulerProtocol createClient(
    String target, Configuration conf) throws IOException {
  InetSocketAddress addr = NetUtils.createSocketAddr(target);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
  LOG.info("Connecting to " + addr);
  return (FairSchedulerProtocol) RPC.getProxy(FairSchedulerProtocol.class,
      FairSchedulerProtocol.versionID, addr, ugi, conf,
      NetUtils.getSocketFactory(conf, FairSchedulerProtocol.class));
}
 
Example 9
Source File: JobTracker.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private void checkAccess(JobInProgress job, 
                              QueueManager.QueueOperation oper) 
                                throws IOException {
  // get the user group info
  UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
  checkAccess(job, oper, ugi);
}