Java 类org.apache.hadoop.hdfs.web.resources.TokenArgumentParam 实例源码

项目:hadoop-plus    文件:WebHdfsFileSystem.java   
private synchronized long renewDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hadoop-plus    文件:WebHdfsFileSystem.java   
private synchronized void cancelDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hops    文件:WebHdfsFileSystem.java   
private synchronized long renewDelegationToken(final Token<?> token)
    throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam =
      new TokenArgumentParam(token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hops    文件:WebHdfsFileSystem.java   
private synchronized void cancelDelegationToken(final Token<?> token)
    throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam =
      new TokenArgumentParam(token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hadoop-TCP    文件:WebHdfsFileSystem.java   
private synchronized long renewDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hadoop-TCP    文件:WebHdfsFileSystem.java   
private synchronized void cancelDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hadoop-on-lustre    文件:WebHdfsFileSystem.java   
private synchronized long renewDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hadoop-on-lustre    文件:WebHdfsFileSystem.java   
private synchronized void cancelDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hardfs    文件:WebHdfsFileSystem.java   
private synchronized long renewDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hardfs    文件:WebHdfsFileSystem.java   
private synchronized void cancelDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hadoop-on-lustre2    文件:WebHdfsFileSystem.java   
@Override
public synchronized long renewDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hadoop-on-lustre2    文件:WebHdfsFileSystem.java   
@Override
public synchronized void cancelDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hortonworks-extension    文件:WebHdfsFileSystem.java   
private synchronized long renewDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hortonworks-extension    文件:WebHdfsFileSystem.java   
private synchronized void cancelDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hortonworks-extension    文件:WebHdfsFileSystem.java   
private synchronized long renewDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.RENEWDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  final Map<?, ?> m = run(op, null, dtargParam);
  return (Long) m.get("long");
}
项目:hortonworks-extension    文件:WebHdfsFileSystem.java   
private synchronized void cancelDelegationToken(final Token<?> token
    ) throws IOException {
  final HttpOpParam.Op op = PutOpParam.Op.CANCELDELEGATIONTOKEN;
  TokenArgumentParam dtargParam = new TokenArgumentParam(
      token.encodeToUrlString());
  run(op, null, dtargParam);
}
项目:hadoop    文件:TestWebHdfsUrl.java   
@Test(timeout=60000)
public void testSecureAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getDelegationToken().encodeToUrlString();

  // send user
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      getTokenUrl);

  // send user
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      renewTokenUrl);

  // send token
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new DelegationParam(tokenString).toString()
      },
      fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send user
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send user
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      fileStatusUrl);    
}
项目:aliyun-oss-hadoop-fs    文件:TestWebHdfsUrl.java   
@Test(timeout=60000)
public void testSecureAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getDelegationToken().encodeToUrlString();

  // send user
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      getTokenUrl);

  // send user
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      renewTokenUrl);

  // send token
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new DelegationParam(tokenString).toString()
      },
      fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send user
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send user
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      fileStatusUrl);    
}
项目:big-c    文件:TestWebHdfsUrl.java   
@Test(timeout=60000)
public void testSecureAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getDelegationToken().encodeToUrlString();

  // send user
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      getTokenUrl);

  // send user
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      renewTokenUrl);

  // send token
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new DelegationParam(tokenString).toString()
      },
      fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send user
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send user
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      fileStatusUrl);    
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestWebHdfsUrl.java   
@Test(timeout=60000)
public void testSecureAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getDelegationToken().encodeToUrlString();

  // send user
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      getTokenUrl);

  // send user
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      renewTokenUrl);

  // send token
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new DelegationParam(tokenString).toString()
      },
      fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send user
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send user
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      fileStatusUrl);    
}
项目:hadoop-plus    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request for the root. */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication,
      blockSize, modificationTime, accessTime, renameOptions, createParent,
      delegationTokenArgument);
}
项目:hadoop-plus    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request. */
@PUT
@Path("{" + UriFsPathParam.NAME + ":.*}")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response put(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {

  init(ugi, delegation, username, doAsUser, path, op, destination, owner,
      group, permission, overwrite, bufferSize, replication, blockSize,
      modificationTime, accessTime, renameOptions, delegationTokenArgument);

  return ugi.doAs(new PrivilegedExceptionAction<Response>() {
    @Override
    public Response run() throws IOException, URISyntaxException {
      REMOTE_ADDRESS.set(request.getRemoteAddr());
      try {
        return put(ugi, delegation, username, doAsUser,
            path.getAbsolutePath(), op, destination, owner, group,
            permission, overwrite, bufferSize, replication, blockSize,
            modificationTime, accessTime, renameOptions, createParent,
            delegationTokenArgument);
      } finally {
        REMOTE_ADDRESS.set(null);
      }
    }
  });
}
项目:FlexMap    文件:TestWebHdfsUrl.java   
@Test(timeout=60000)
public void testSecureAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getDelegationToken().encodeToUrlString();

  // send user
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      getTokenUrl);

  // send user
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      renewTokenUrl);

  // send token
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new DelegationParam(tokenString).toString()
      },
      fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send user
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send user
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      fileStatusUrl);    
}
项目:hops    文件:NamenodeWebHdfsMethods.java   
/**
 * Handle HTTP PUT request for the root.
 */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context
    final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME)
    @DefaultValue(DelegationParam.DEFAULT)
    final DelegationParam delegation,
    @QueryParam(UserParam.NAME)
    @DefaultValue(UserParam.DEFAULT)
    final UserParam username,
    @QueryParam(DoAsParam.NAME)
    @DefaultValue(DoAsParam.DEFAULT)
    final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME)
    @DefaultValue(PutOpParam.DEFAULT)
    final PutOpParam op,
    @QueryParam(DestinationParam.NAME)
    @DefaultValue(DestinationParam.DEFAULT)
    final DestinationParam destination,
    @QueryParam(OwnerParam.NAME)
    @DefaultValue(OwnerParam.DEFAULT)
    final OwnerParam owner,
    @QueryParam(GroupParam.NAME)
    @DefaultValue(GroupParam.DEFAULT)
    final GroupParam group,
    @QueryParam(PermissionParam.NAME)
    @DefaultValue(PermissionParam.DEFAULT)
    final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME)
    @DefaultValue(OverwriteParam.DEFAULT)
    final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME)
    @DefaultValue(BufferSizeParam.DEFAULT)
    final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME)
    @DefaultValue(ReplicationParam.DEFAULT)
    final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME)
    @DefaultValue(BlockSizeParam.DEFAULT)
    final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME)
    @DefaultValue(ModificationTimeParam.DEFAULT)
    final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME)
    @DefaultValue(AccessTimeParam.DEFAULT)
    final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME)
    @DefaultValue(RenameOptionSetParam.DEFAULT)
    final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME)
    @DefaultValue(CreateParentParam.DEFAULT)
    final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME)
    @DefaultValue(TokenArgumentParam.DEFAULT)
    final TokenArgumentParam delegationTokenArgument)
    throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication, blockSize,
      modificationTime, accessTime, renameOptions, createParent,
      delegationTokenArgument);
}
项目:hops    文件:TestWebHdfsUrl.java   
@Test(timeout = 4000)
public void testSecureAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getRenewToken().encodeToUrlString();

  // send user
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()}, getTokenUrl);

  // send user
  URL renewTokenUrl = webhdfs
      .toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN, fsPath,
          new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),}, renewTokenUrl);

  // send user+token
  URL cancelTokenUrl = webhdfs
      .toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN, fsPath,
          new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
          new DelegationParam(tokenString).toString()}, cancelTokenUrl);

  // send user+token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(new String[]{GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new DelegationParam(tokenString).toString()}, fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send user
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN, fsPath,
      new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),}, cancelTokenUrl);

  // send user
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(new String[]{GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()}, fileStatusUrl);
}
项目:hops    文件:TestWebHdfsUrl.java   
@Test(timeout = 4000)
public void testSecureProxyAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  ugi = UserGroupInformation.createProxyUser("test-proxy-user", ugi);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getRenewToken().encodeToUrlString();

  // send real+effective
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getRealUser().getShortUserName()).toString(),
          new DoAsParam(ugi.getShortUserName()).toString()}, getTokenUrl);

  // send real+effective
  URL renewTokenUrl = webhdfs
      .toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN, fsPath,
          new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getRealUser().getShortUserName()).toString(),
          new DoAsParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),}, renewTokenUrl);

  // send effective+token
  URL cancelTokenUrl = webhdfs
      .toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN, fsPath,
          new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
          new DelegationParam(tokenString).toString()}, cancelTokenUrl);

  // send effective+token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(new String[]{GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new DelegationParam(tokenString).toString()}, fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send real+effective
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN, fsPath,
      new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getRealUser().getShortUserName()).toString(),
          new DoAsParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString()}, cancelTokenUrl);

  // send real+effective
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(new String[]{GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getRealUser().getShortUserName()).toString(),
          new DoAsParam(ugi.getShortUserName()).toString()}, fileStatusUrl);
}
项目:hadoop-TCP    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request for the root. */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication,
      blockSize, modificationTime, accessTime, renameOptions, createParent,
      delegationTokenArgument);
}
项目:hadoop-TCP    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request. */
@PUT
@Path("{" + UriFsPathParam.NAME + ":.*}")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response put(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {

  init(ugi, delegation, username, doAsUser, path, op, destination, owner,
      group, permission, overwrite, bufferSize, replication, blockSize,
      modificationTime, accessTime, renameOptions, delegationTokenArgument);

  return ugi.doAs(new PrivilegedExceptionAction<Response>() {
    @Override
    public Response run() throws IOException, URISyntaxException {
      REMOTE_ADDRESS.set(request.getRemoteAddr());
      try {
        return put(ugi, delegation, username, doAsUser,
            path.getAbsolutePath(), op, destination, owner, group,
            permission, overwrite, bufferSize, replication, blockSize,
            modificationTime, accessTime, renameOptions, createParent,
            delegationTokenArgument);
      } finally {
        REMOTE_ADDRESS.set(null);
      }
    }
  });
}
项目:hadoop-on-lustre    文件:TestWebHdfsUrl.java   
@Test
public void testDelegationTokenInUrl() throws IOException {
  Configuration conf = new Configuration();
  final String uri = WebHdfsFileSystem.SCHEME + "://" + "127.0.0.1:9071";
  // Turn on security
  conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(conf);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(new Text(
      ugi.getUserName()), null, null);
  FSNamesystem namesystem = mock(FSNamesystem.class);
  DelegationTokenSecretManager dtSecretManager = new DelegationTokenSecretManager(
      86400000, 86400000, 86400000, 86400000, namesystem);
  dtSecretManager.startThreads();
  Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(
      dtId, dtSecretManager);
  token.setService(new Text("127.0.0.1:9071"));
  token.setKind(WebHdfsFileSystem.TOKEN_KIND);
  ugi.addToken(token);
  final WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) FileSystem.get(
      URI.create(uri), conf);
  String tokenString = token.encodeToUrlString();
  Path fsPath = new Path("/");
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  Assert.assertEquals(
      generateUrlQueryPrefix(PutOpParam.Op.RENEWDELEGATIONTOKEN,
          ugi.getUserName())
          + "&token=" + tokenString, renewTokenUrl.getQuery());
  Token<DelegationTokenIdentifier> delegationToken = new Token<DelegationTokenIdentifier>(
      token);
  delegationToken.setKind(WebHdfsFileSystem.TOKEN_KIND);
  Assert.assertEquals(
      generateUrlQueryPrefix(PutOpParam.Op.CANCELDELEGATIONTOKEN,
          ugi.getUserName())
          + "&token="
          + tokenString
          + "&"
          + DelegationParam.NAME
          + "="
          + delegationToken.encodeToUrlString(), cancelTokenUrl.getQuery());
}
项目:hadoop-on-lustre    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request for the root. */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication,
      blockSize, modificationTime, accessTime, delegationTokenArgument);
}
项目:hardfs    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request for the root. */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication,
      blockSize, modificationTime, accessTime, renameOptions, createParent,
      delegationTokenArgument);
}
项目:hardfs    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request. */
@PUT
@Path("{" + UriFsPathParam.NAME + ":.*}")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response put(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {

  init(ugi, delegation, username, doAsUser, path, op, destination, owner,
      group, permission, overwrite, bufferSize, replication, blockSize,
      modificationTime, accessTime, renameOptions, delegationTokenArgument);

  return ugi.doAs(new PrivilegedExceptionAction<Response>() {
    @Override
    public Response run() throws IOException, URISyntaxException {
      REMOTE_ADDRESS.set(request.getRemoteAddr());
      try {
        return put(ugi, delegation, username, doAsUser,
            path.getAbsolutePath(), op, destination, owner, group,
            permission, overwrite, bufferSize, replication, blockSize,
            modificationTime, accessTime, renameOptions, createParent,
            delegationTokenArgument);
      } finally {
        REMOTE_ADDRESS.set(null);
      }
    }
  });
}
项目:hadoop-on-lustre2    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request for the root. */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument,
    @QueryParam(AclPermissionParam.NAME) @DefaultValue(AclPermissionParam.DEFAULT) 
        final AclPermissionParam aclPermission
        )throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication,
      blockSize, modificationTime, accessTime, renameOptions, createParent,
      delegationTokenArgument,aclPermission);
}
项目:hadoop-on-lustre2    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request. */
@PUT
@Path("{" + UriFsPathParam.NAME + ":.*}")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response put(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(RenameOptionSetParam.NAME) @DefaultValue(RenameOptionSetParam.DEFAULT)
        final RenameOptionSetParam renameOptions,
    @QueryParam(CreateParentParam.NAME) @DefaultValue(CreateParentParam.DEFAULT)
        final CreateParentParam createParent,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument,
    @QueryParam(AclPermissionParam.NAME) @DefaultValue(AclPermissionParam.DEFAULT) 
        final AclPermissionParam aclPermission
    ) throws IOException, InterruptedException {

  init(ugi, delegation, username, doAsUser, path, op, destination, owner,
      group, permission, overwrite, bufferSize, replication, blockSize,
      modificationTime, accessTime, renameOptions, delegationTokenArgument,aclPermission);

  return ugi.doAs(new PrivilegedExceptionAction<Response>() {
    @Override
    public Response run() throws IOException, URISyntaxException {
      REMOTE_ADDRESS.set(request.getRemoteAddr());
      try {
        return put(ugi, delegation, username, doAsUser,
            path.getAbsolutePath(), op, destination, owner, group,
            permission, overwrite, bufferSize, replication, blockSize,
            modificationTime, accessTime, renameOptions, createParent,
            delegationTokenArgument,aclPermission);
      } finally {
        REMOTE_ADDRESS.set(null);
      }
    }
  });
}
项目:hadoop-on-lustre2    文件:TestWebHdfsUrl.java   
@Test(timeout=60000)
public void testSecureAuthParamsInUrl() throws IOException {
  Configuration conf = new Configuration();
  // fake turning on security so api thinks it should use tokens
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);

  UserGroupInformation ugi =
      UserGroupInformation.createRemoteUser("test-user");
  ugi.setAuthenticationMethod(KERBEROS);
  UserGroupInformation.setLoginUser(ugi);

  WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
  Path fsPath = new Path("/");
  String tokenString = webhdfs.getDelegationToken().encodeToUrlString();

  // send user
  URL getTokenUrl = webhdfs.toUrl(GetOpParam.Op.GETDELEGATIONTOKEN, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      getTokenUrl);

  // send user
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.RENEWDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      renewTokenUrl);

  // send token
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send token
  URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new DelegationParam(tokenString).toString()
      },
      fileStatusUrl);

  // wipe out internal token to simulate auth always required
  webhdfs.setDelegationToken(null);

  // send user
  cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  checkQueryParams(
      new String[]{
          PutOpParam.Op.CANCELDELEGATIONTOKEN.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString(),
          new TokenArgumentParam(tokenString).toString(),
      },
      cancelTokenUrl);

  // send user
  fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
  checkQueryParams(
      new String[]{
          GetOpParam.Op.GETFILESTATUS.toQueryString(),
          new UserParam(ugi.getShortUserName()).toString()
      },
      fileStatusUrl);    
}
项目:hortonworks-extension    文件:TestWebHdfsUrl.java   
@Test
public void testDelegationTokenInUrl() throws IOException {
  Configuration conf = new Configuration();
  final String uri = WebHdfsFileSystem.SCHEME + "://" + "127.0.0.1:9071";
  // Turn on security
  conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(conf);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(new Text(
      ugi.getUserName()), null, null);
  FSNamesystem namesystem = mock(FSNamesystem.class);
  DelegationTokenSecretManager dtSecretManager = new DelegationTokenSecretManager(
      86400000, 86400000, 86400000, 86400000, namesystem);
  dtSecretManager.startThreads();
  Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(
      dtId, dtSecretManager);
  token.setService(new Text("127.0.0.1:9071"));
  token.setKind(WebHdfsFileSystem.TOKEN_KIND);
  ugi.addToken(token);
  final WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) FileSystem.get(
      URI.create(uri), conf);
  String tokenString = token.encodeToUrlString();
  Path fsPath = new Path("/");
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  Assert.assertEquals(
      generateUrlQueryPrefix(PutOpParam.Op.RENEWDELEGATIONTOKEN,
          ugi.getUserName())
          + "&token=" + tokenString, renewTokenUrl.getQuery());
  Token<DelegationTokenIdentifier> delegationToken = new Token<DelegationTokenIdentifier>(
      token);
  delegationToken.setKind(WebHdfsFileSystem.TOKEN_KIND);
  Assert.assertEquals(
      generateUrlQueryPrefix(PutOpParam.Op.CANCELDELEGATIONTOKEN,
          ugi.getUserName())
          + "&token="
          + tokenString
          + "&"
          + DelegationParam.NAME
          + "="
          + delegationToken.encodeToUrlString(), cancelTokenUrl.getQuery());
}
项目:hortonworks-extension    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request for the root. */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication,
      blockSize, modificationTime, accessTime, delegationTokenArgument);
}
项目:hortonworks-extension    文件:TestWebHdfsUrl.java   
@Test
public void testDelegationTokenInUrl() throws IOException {
  Configuration conf = new Configuration();
  final String uri = WebHdfsFileSystem.SCHEME + "://" + "127.0.0.1:9071";
  // Turn on security
  conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(conf);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(new Text(
      ugi.getUserName()), null, null);
  FSNamesystem namesystem = mock(FSNamesystem.class);
  DelegationTokenSecretManager dtSecretManager = new DelegationTokenSecretManager(
      86400000, 86400000, 86400000, 86400000, namesystem);
  dtSecretManager.startThreads();
  Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(
      dtId, dtSecretManager);
  token.setService(new Text("127.0.0.1:9071"));
  token.setKind(WebHdfsFileSystem.TOKEN_KIND);
  ugi.addToken(token);
  final WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) FileSystem.get(
      URI.create(uri), conf);
  String tokenString = token.encodeToUrlString();
  Path fsPath = new Path("/");
  URL renewTokenUrl = webhdfs.toUrl(PutOpParam.Op.RENEWDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  URL cancelTokenUrl = webhdfs.toUrl(PutOpParam.Op.CANCELDELEGATIONTOKEN,
      fsPath, new TokenArgumentParam(tokenString));
  Assert.assertEquals(
      generateUrlQueryPrefix(PutOpParam.Op.RENEWDELEGATIONTOKEN,
          ugi.getUserName())
          + "&token=" + tokenString, renewTokenUrl.getQuery());
  Token<DelegationTokenIdentifier> delegationToken = new Token<DelegationTokenIdentifier>(
      token);
  delegationToken.setKind(WebHdfsFileSystem.TOKEN_KIND);
  Assert.assertEquals(
      generateUrlQueryPrefix(PutOpParam.Op.CANCELDELEGATIONTOKEN,
          ugi.getUserName())
          + "&token="
          + tokenString
          + "&"
          + DelegationParam.NAME
          + "="
          + delegationToken.encodeToUrlString(), cancelTokenUrl.getQuery());
}
项目:hortonworks-extension    文件:NamenodeWebHdfsMethods.java   
/** Handle HTTP PUT request for the root. */
@PUT
@Path("/")
@Consumes({"*/*"})
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public Response putRoot(
    @Context final UserGroupInformation ugi,
    @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
        final DelegationParam delegation,
    @QueryParam(UserParam.NAME) @DefaultValue(UserParam.DEFAULT)
        final UserParam username,
    @QueryParam(DoAsParam.NAME) @DefaultValue(DoAsParam.DEFAULT)
        final DoAsParam doAsUser,
    @QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
        final PutOpParam op,
    @QueryParam(DestinationParam.NAME) @DefaultValue(DestinationParam.DEFAULT)
        final DestinationParam destination,
    @QueryParam(OwnerParam.NAME) @DefaultValue(OwnerParam.DEFAULT)
        final OwnerParam owner,
    @QueryParam(GroupParam.NAME) @DefaultValue(GroupParam.DEFAULT)
        final GroupParam group,
    @QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
        final PermissionParam permission,
    @QueryParam(OverwriteParam.NAME) @DefaultValue(OverwriteParam.DEFAULT)
        final OverwriteParam overwrite,
    @QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
        final BufferSizeParam bufferSize,
    @QueryParam(ReplicationParam.NAME) @DefaultValue(ReplicationParam.DEFAULT)
        final ReplicationParam replication,
    @QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
        final BlockSizeParam blockSize,
    @QueryParam(ModificationTimeParam.NAME) @DefaultValue(ModificationTimeParam.DEFAULT)
        final ModificationTimeParam modificationTime,
    @QueryParam(AccessTimeParam.NAME) @DefaultValue(AccessTimeParam.DEFAULT)
        final AccessTimeParam accessTime,
    @QueryParam(TokenArgumentParam.NAME) @DefaultValue(TokenArgumentParam.DEFAULT)
        final TokenArgumentParam delegationTokenArgument
    ) throws IOException, InterruptedException {
  return put(ugi, delegation, username, doAsUser, ROOT, op, destination,
      owner, group, permission, overwrite, bufferSize, replication,
      blockSize, modificationTime, accessTime, delegationTokenArgument);
}