当前位置: 首页>>代码示例>>Java>>正文


Java UserGroupInformation类代码示例

本文整理汇总了Java中org.apache.hadoop.security.UserGroupInformation的典型用法代码示例。如果您正苦于以下问题:Java UserGroupInformation类的具体用法?Java UserGroupInformation怎么用?Java UserGroupInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UserGroupInformation类属于org.apache.hadoop.security包,在下文中一共展示了UserGroupInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: HAServiceProtocolClientSideTranslatorPB

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
public HAServiceProtocolClientSideTranslatorPB(
    InetSocketAddress addr, Configuration conf,
    SocketFactory socketFactory, int timeout) throws IOException {
  RPC.setProtocolEngine(conf, HAServiceProtocolPB.class,
      ProtobufRpcEngine.class);
  rpcProxy = RPC.getProxy(HAServiceProtocolPB.class,
      RPC.getProtocolVersion(HAServiceProtocolPB.class), addr,
      UserGroupInformation.getCurrentUser(), conf, socketFactory, timeout);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:10,代码来源:HAServiceProtocolClientSideTranslatorPB.java

示例2: getProxy

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> ProtocolProxy<T> getProxy(Class<T> protocol, long clientVersion,
    InetSocketAddress addr, UserGroupInformation ticket, Configuration conf,
    SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {

  final Invoker invoker = new Invoker(protocol, addr, ticket, conf, factory,
      rpcTimeout, connectionRetryPolicy, fallbackToSimpleAuth);
  return new ProtocolProxy<T>(protocol, (T) Proxy.newProxyInstance(
      protocol.getClassLoader(), new Class[]{protocol}, invoker), false);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:13,代码来源:ProtobufRpcEngine.java

示例3: publishApplicationAttemptEvent

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
private static void publishApplicationAttemptEvent(
    final TimelineClient timelineClient, String appAttemptId,
    DSEvent appEvent, String domainId, UserGroupInformation ugi) {
  final TimelineEntity entity = new TimelineEntity();
  entity.setEntityId(appAttemptId);
  entity.setEntityType(DSEntity.DS_APP_ATTEMPT.toString());
  entity.setDomainId(domainId);
  entity.addPrimaryFilter("user", ugi.getShortUserName());
  TimelineEvent event = new TimelineEvent();
  event.setEventType(appEvent.toString());
  event.setTimestamp(System.currentTimeMillis());
  entity.addEvent(event);
  try {
    timelineClient.putEntities(entity);
  } catch (YarnException | IOException e) {
    LOG.error("App Attempt "
        + (appEvent.equals(DSEvent.DS_APP_ATTEMPT_START) ? "start" : "end")
        + " event could not be published for "
        + appAttemptId.toString(), e);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:ApplicationMaster.java

示例4: uploadEmptyContainerLogIntoRemoteDir

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
private static void uploadEmptyContainerLogIntoRemoteDir(UserGroupInformation ugi,
    Configuration configuration, List<String> rootLogDirs, NodeId nodeId,
    ContainerId containerId, Path appDir, FileSystem fs) throws Exception {
  Path path =
      new Path(appDir, LogAggregationUtils.getNodeString(nodeId)
          + System.currentTimeMillis());
  AggregatedLogFormat.LogWriter writer =
      new AggregatedLogFormat.LogWriter(configuration, path, ugi);
  writer.writeApplicationOwner(ugi.getUserName());

  Map<ApplicationAccessType, String> appAcls =
      new HashMap<ApplicationAccessType, String>();
  appAcls.put(ApplicationAccessType.VIEW_APP, ugi.getUserName());
  writer.writeApplicationACLs(appAcls);
  DataOutputStream out = writer.getWriter().prepareAppendKey(-1);
  new AggregatedLogFormat.LogKey(containerId).write(out);
  out.close();
  out = writer.getWriter().prepareAppendValue(-1);
  new AggregatedLogFormat.LogValue(rootLogDirs, containerId,
    UserGroupInformation.getCurrentUser().getShortUserName()).write(out,
    new HashSet<File>());
  out.close();
  writer.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TestLogsCLI.java

示例5: doRenewOrCancel

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
private static void doRenewOrCancel(
    final Token<DelegationTokenIdentifier> token, final Configuration conf,
    final TokenTestAction action)
    throws IOException, InterruptedException {
  UserGroupInformation.createRemoteUser("JobTracker").doAs(
      new PrivilegedExceptionAction<Void>() {
        @Override
        public Void run() throws Exception {
          switch (action) {
          case RENEW:
            token.renew(conf);
            break;
          case CANCEL:
            token.cancel(conf);
            break;
          default:
            fail("bad action:" + action);
          }
          return null;
        }
      });
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:TestDelegationTokensWithHA.java

示例6: checkFile

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
static void checkFile(Path p, int expectedsize, final Configuration conf
    ) throws IOException, InterruptedException {
  //open the file with another user account
  final String username = UserGroupInformation.getCurrentUser().getShortUserName()
      + "_" + ++userCount;

  UserGroupInformation ugi = UserGroupInformation.createUserForTesting(username, 
                               new String[] {"supergroup"});
  
  final FileSystem fs = DFSTestUtil.getFileSystemAs(ugi, conf);
  
  final HdfsDataInputStream in = (HdfsDataInputStream)fs.open(p);

  //Check visible length
  Assert.assertTrue(in.getVisibleLength() >= expectedsize);

  //Able to read?
  for(int i = 0; i < expectedsize; i++) {
    Assert.assertEquals((byte)i, (byte)in.read());  
  }

  in.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestReadWhileWriting.java

示例7: checkTokenCancellation

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
private void checkTokenCancellation(ClientRMService rmService,
    UserGroupInformation owner, UserGroupInformation renewer)
    throws IOException, YarnException {
  RMDelegationTokenIdentifier tokenIdentifier =
      new RMDelegationTokenIdentifier(new Text(owner.getUserName()),
        new Text(renewer.getUserName()), null);
  Token<?> token =
      new Token<RMDelegationTokenIdentifier>(tokenIdentifier, dtsm);
  org.apache.hadoop.yarn.api.records.Token dToken =
      BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind()
        .toString(), token.getPassword(), token.getService().toString());
  CancelDelegationTokenRequest request =
      Records.newRecord(CancelDelegationTokenRequest.class);
  request.setDelegationToken(dToken);
  rmService.cancelDelegationToken(request);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestClientRMService.java

示例8: getDelegationToken

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
private Token getDelegationToken(
    final UserGroupInformation loggedInUser,
    final MRClientProtocol hsService, final String renewerString)
    throws IOException, InterruptedException {
  // Get the delegation token directly as it is a little difficult to setup
  // the kerberos based rpc.
  Token token = loggedInUser
      .doAs(new PrivilegedExceptionAction<Token>() {
        @Override
        public Token run() throws IOException {
          GetDelegationTokenRequest request = Records
              .newRecord(GetDelegationTokenRequest.class);
          request.setRenewer(renewerString);
          return hsService.getDelegationToken(request).getDelegationToken();
        }

      });
  return token;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestJHSSecurity.java

示例9: assertPermissionDenied

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
private void assertPermissionDenied(UserGroupInformation user, String path,
    FsAction access) throws IOException {
  try {
    INodesInPath iip = dir.getINodesInPath(path, true);
    dir.getPermissionChecker(SUPERUSER, SUPERGROUP, user).checkPermission(iip,
      false, null, null, access, null, false);
    fail("expected AccessControlException for user + " + user + ", path = " +
      path + ", access = " + access);
  } catch (AccessControlException e) {
    assertTrue("Permission denied messages must carry the username",
            e.getMessage().contains(user.getUserName().toString()));
    assertTrue("Permission denied messages must carry the path parent",
            e.getMessage().contains(
                new Path(path).getParent().toUri().getPath()));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestFSPermissionChecker.java

示例10: run

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
/**
 * Get the groups for the users given and print formatted output to the
 * {@link PrintStream} configured earlier.
 */
@Override
public int run(String[] args) throws Exception {
  if (args.length == 0) {
    args = new String[] { UserGroupInformation.getCurrentUser().getUserName() }; 
  }

  for (String username : args) {
    StringBuilder sb = new StringBuilder();
    sb.append(username + " :");
    for (String group : getUgmProtocol().getGroupsForUser(username)) {
      sb.append(" ");
      sb.append(group);
    }
    out.println(sb);
  }

  return 0;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:GetGroupsBase.java

示例11: getEntity

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
/**
 * Get the single timeline entity that the given user has access to. The
 * meaning of each argument has been documented with
 * {@link TimelineReader#getEntity}.
 * 
 * @see TimelineReader#getEntity
 */
public TimelineEntity getEntity(
    String entityType,
    String entityId,
    EnumSet<Field> fields,
    UserGroupInformation callerUGI) throws YarnException, IOException {
  TimelineEntity entity = null;
  entity =
      store.getEntity(entityId, entityType, fields);
  if (entity != null) {
    addDefaultDomainIdIfAbsent(entity);
    // check ACLs
    if (!timelineACLsManager.checkAccess(
        callerUGI, ApplicationAccessType.VIEW_APP, entity)) {
      entity = null;
    }
  }
  return entity;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TimelineDataManager.java

示例12: createNewApplication

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
/**
 * Generates a new ApplicationId which is then sent to the client
 * 
 * @param hsr
 *          the servlet request
 * @return Response containing the app id and the maximum resource
 *         capabilities
 * @throws AuthorizationException
 * @throws IOException
 * @throws InterruptedException
 */
@POST
@Path("/apps/new-application")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createNewApplication(@Context HttpServletRequest hsr)
    throws AuthorizationException, IOException, InterruptedException {
  init();
  UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true);
  if (callerUGI == null) {
    throw new AuthorizationException("Unable to obtain user name, "
        + "user not authenticated");
  }
  if (UserGroupInformation.isSecurityEnabled() && isStaticUser(callerUGI)) {
    String msg = "The default static user cannot carry out this operation.";
    return Response.status(Status.FORBIDDEN).entity(msg).build();
  }

  NewApplication appId = createNewApplication();
  return Response.status(Status.OK).entity(appId).build();

}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:RMWebServices.java

示例13: testHandleRMHABeforeSubmitApplicationCallWithSavedApplicationState

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
@Test
public void
    testHandleRMHABeforeSubmitApplicationCallWithSavedApplicationState()
        throws Exception {
  // start two RMs, and transit rm1 to active, rm2 to standby
  startRMs();

  // get a new applicationId from rm1
  ApplicationId appId = rm1.getNewAppId().getApplicationId();

  // Do the failover
  explicitFailover();

  // submit the application with previous assigned applicationId
  // to current active rm: rm2
  RMApp app1 =
      rm2.submitApp(200, "", UserGroupInformation
          .getCurrentUser().getShortUserName(), null, false, null,
          configuration.getInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS,
              YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS), null, null,
          false, false, true, appId);

  // verify application submission
  verifySubmitApp(rm2, app1, appId);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestSubmitApplicationWithRMHA.java

示例14: testGetJobCounters

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
/**
 *  Test method 'jobCounters'. Should print message about error or set CountersPage class for rendering
 */
@Test
public void testGetJobCounters() {

  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(false);

  appController.jobCounters();
  verify(appController.response()).setContentType(MimeType.TEXT);
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01",
      appController.getData());
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
      .thenReturn(true);

  appController.getProperty().remove(AMParams.JOB_ID);
  appController.jobCounters();
  assertEquals(
      "Access denied: User user does not have permission to view job job_01_01Bad Request: Missing job ID",
      appController.getData());

  appController.getProperty().put(AMParams.JOB_ID, "job_01_01");
  appController.jobCounters();
  assertEquals(CountersPage.class, appController.getClazz());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestAppController.java

示例15: checkAccess

import org.apache.hadoop.security.UserGroupInformation; //导入依赖的package包/类
public boolean checkAccess(UserGroupInformation callerUGI,
    TimelineDomain domain) throws YarnException, IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Verifying the access of "
        + (callerUGI == null ? null : callerUGI.getShortUserName())
        + " on the timeline domain " + domain);
  }

  if (!adminAclsManager.areACLsEnabled()) {
    return true;
  }

  String owner = domain.getOwner();
  if (owner == null || owner.length() == 0) {
    throw new YarnException("Owner information of the timeline domain "
        + domain.getId() + " is corrupted.");
  }
  if (callerUGI != null
      && (adminAclsManager.isAdmin(callerUGI) ||
          callerUGI.getShortUserName().equals(owner))) {
    return true;
  }
  return false;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TimelineACLsManager.java


注:本文中的org.apache.hadoop.security.UserGroupInformation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。