Search in sources :

Example 1 with UserParam

use of org.apache.hadoop.hdfs.web.resources.UserParam in project hadoop by apache.

the class TestWebHdfsUrl method testSecureProxyAuthParamsInUrl.

@Test(timeout = 60000)
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.getDelegationToken().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 token
    URL 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 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 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 DelegationParam(tokenString).toString() }, fileStatusUrl);
}
Also used : Path(org.apache.hadoop.fs.Path) UserParam(org.apache.hadoop.hdfs.web.resources.UserParam) Configuration(org.apache.hadoop.conf.Configuration) DoAsParam(org.apache.hadoop.hdfs.web.resources.DoAsParam) TokenArgumentParam(org.apache.hadoop.hdfs.web.resources.TokenArgumentParam) DelegationParam(org.apache.hadoop.hdfs.web.resources.DelegationParam) URL(java.net.URL) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 2 with UserParam

use of org.apache.hadoop.hdfs.web.resources.UserParam in project hadoop by apache.

the class TestWebHdfsUrl method testBatchedListingUrl.

@Test(timeout = 60000)
public void testBatchedListingUrl() throws Exception {
    Configuration conf = new Configuration();
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser("test-user");
    UserGroupInformation.setLoginUser(ugi);
    WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
    Path fsPath = new Path("/p1");
    final StartAfterParam startAfter = new StartAfterParam("last");
    URL url = webhdfs.toUrl(GetOpParam.Op.LISTSTATUS_BATCH, fsPath, startAfter);
    checkQueryParams(new String[] { GetOpParam.Op.LISTSTATUS_BATCH.toQueryString(), new UserParam(ugi.getShortUserName()).toString(), StartAfterParam.NAME + "=" + "last" }, url);
}
Also used : Path(org.apache.hadoop.fs.Path) UserParam(org.apache.hadoop.hdfs.web.resources.UserParam) Configuration(org.apache.hadoop.conf.Configuration) StartAfterParam(org.apache.hadoop.hdfs.web.resources.StartAfterParam) URL(java.net.URL) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 3 with UserParam

use of org.apache.hadoop.hdfs.web.resources.UserParam in project hadoop by apache.

the class TestWebHdfsUrl method testSimpleAuthParamsInUrl.

@Test(timeout = 60000)
public void testSimpleAuthParamsInUrl() throws IOException {
    Configuration conf = new Configuration();
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser("test-user");
    UserGroupInformation.setLoginUser(ugi);
    WebHdfsFileSystem webhdfs = getWebHdfsFileSystem(ugi, conf);
    Path fsPath = new Path("/");
    // send user+token
    URL fileStatusUrl = webhdfs.toUrl(GetOpParam.Op.GETFILESTATUS, fsPath);
    checkQueryParams(new String[] { GetOpParam.Op.GETFILESTATUS.toQueryString(), new UserParam(ugi.getShortUserName()).toString() }, fileStatusUrl);
}
Also used : Path(org.apache.hadoop.fs.Path) UserParam(org.apache.hadoop.hdfs.web.resources.UserParam) Configuration(org.apache.hadoop.conf.Configuration) URL(java.net.URL) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 4 with UserParam

use of org.apache.hadoop.hdfs.web.resources.UserParam in project hadoop by apache.

the class TestDataNodeUGIProvider method testUGICacheInSecure.

@Test
public void testUGICacheInSecure() throws Exception {
    String uri1 = WebHdfsFileSystem.PATH_PREFIX + PATH + "?op=OPEN" + Param.toSortedString("&", new OffsetParam((long) OFFSET), new LengthParam((long) LENGTH), new UserParam("root"));
    String uri2 = WebHdfsFileSystem.PATH_PREFIX + PATH + "?op=OPEN" + Param.toSortedString("&", new OffsetParam((long) OFFSET), new LengthParam((long) LENGTH), new UserParam("hdfs"));
    DataNodeUGIProvider ugiProvider1 = new DataNodeUGIProvider(new ParameterParser(new QueryStringDecoder(URI.create(uri1)), conf));
    UserGroupInformation ugi11 = ugiProvider1.ugi();
    UserGroupInformation ugi12 = ugiProvider1.ugi();
    Assert.assertEquals("With UGI cache, two UGIs for the same user should be same", ugi11, ugi12);
    DataNodeUGIProvider ugiProvider2 = new DataNodeUGIProvider(new ParameterParser(new QueryStringDecoder(URI.create(uri2)), conf));
    UserGroupInformation url21 = ugiProvider2.ugi();
    UserGroupInformation url22 = ugiProvider2.ugi();
    Assert.assertEquals("With UGI cache, two UGIs for the same user should be same", url21, url22);
    Assert.assertNotEquals("With UGI cache, two UGIs for the different user should not be same", ugi11, url22);
    awaitCacheEmptyDueToExpiration();
    ugi12 = ugiProvider1.ugi();
    url22 = ugiProvider2.ugi();
    String msg = "With cache eviction, two UGIs returned by" + " the same user should not be same";
    Assert.assertNotEquals(msg, ugi11, ugi12);
    Assert.assertNotEquals(msg, url21, url22);
    Assert.assertNotEquals("With UGI cache, two UGIs for the different user should not be same", ugi11, url22);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) UserParam(org.apache.hadoop.hdfs.web.resources.UserParam) OffsetParam(org.apache.hadoop.hdfs.web.resources.OffsetParam) LengthParam(org.apache.hadoop.hdfs.web.resources.LengthParam) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 5 with UserParam

use of org.apache.hadoop.hdfs.web.resources.UserParam in project hadoop by apache.

the class TestWebHdfsUrl method testSecureAuthParamsInUrl.

@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 DelegationParam(tokenString).toString() }, fileStatusUrl);
}
Also used : Path(org.apache.hadoop.fs.Path) UserParam(org.apache.hadoop.hdfs.web.resources.UserParam) Configuration(org.apache.hadoop.conf.Configuration) TokenArgumentParam(org.apache.hadoop.hdfs.web.resources.TokenArgumentParam) DelegationParam(org.apache.hadoop.hdfs.web.resources.DelegationParam) URL(java.net.URL) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Aggregations

UserParam (org.apache.hadoop.hdfs.web.resources.UserParam)7 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)7 Test (org.junit.Test)7 URL (java.net.URL)6 Configuration (org.apache.hadoop.conf.Configuration)6 Path (org.apache.hadoop.fs.Path)6 DelegationParam (org.apache.hadoop.hdfs.web.resources.DelegationParam)2 DoAsParam (org.apache.hadoop.hdfs.web.resources.DoAsParam)2 TokenArgumentParam (org.apache.hadoop.hdfs.web.resources.TokenArgumentParam)2 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 FsActionParam (org.apache.hadoop.hdfs.web.resources.FsActionParam)1 LengthParam (org.apache.hadoop.hdfs.web.resources.LengthParam)1 OffsetParam (org.apache.hadoop.hdfs.web.resources.OffsetParam)1 StartAfterParam (org.apache.hadoop.hdfs.web.resources.StartAfterParam)1