Skip to content

Commit

Permalink
Rebase with master and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
venki09 committed Jun 7, 2019
1 parent 06603c5 commit 8e53d8f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@

package org.apache.hadoop.hbase.security.token;

import java.io.IOException;
import static org.apache.hadoop.hdfs.protocol.HdfsConstants.HDFS_URI_SCHEME;
import static org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier.HDFS_DELEGATION_KIND;
import static org.apache.hadoop.hdfs.web.WebHdfsConstants.SWEBHDFS_SCHEME;
import static org.apache.hadoop.hdfs.web.WebHdfsConstants.SWEBHDFS_TOKEN_KIND;
import static org.apache.hadoop.hdfs.web.WebHdfsConstants.WEBHDFS_SCHEME;
import static org.apache.hadoop.hdfs.web.WebHdfsConstants.WEBHDFS_TOKEN_KIND;

import java.io.IOException;
import java.util.Objects;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
import org.apache.hadoop.hdfs.web.SWebHdfsFileSystem;
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.security.token.Token;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.security.token.Token;

/**
* Helper class to obtain a filesystem delegation token.
Expand Down Expand Up @@ -70,16 +72,16 @@ public void acquireDelegationToken(final FileSystem fs)
throws IOException {
String tokenKind;
String scheme = fs.getUri().getScheme();
if (SWebHdfsFileSystem.SCHEME.equalsIgnoreCase(scheme)) {
tokenKind = SWebHdfsFileSystem.TOKEN_KIND.toString();
} else if (WebHdfsFileSystem.SCHEME.equalsIgnoreCase(scheme)) {
tokenKind = WebHdfsFileSystem.TOKEN_KIND.toString();
} else if (HdfsConstants.HDFS_URI_SCHEME.equalsIgnoreCase(scheme)) {
tokenKind = DelegationTokenIdentifier.HDFS_DELEGATION_KIND.toString();
if (SWEBHDFS_SCHEME.equalsIgnoreCase(scheme)) {
tokenKind = SWEBHDFS_TOKEN_KIND.toString();
} else if (WEBHDFS_SCHEME.equalsIgnoreCase(scheme)) {
tokenKind = WEBHDFS_TOKEN_KIND.toString();
} else if (HDFS_URI_SCHEME.equalsIgnoreCase(scheme)) {
tokenKind = HDFS_DELEGATION_KIND.toString();
} else {
LOG.warn("Unknown FS URI scheme: " + scheme);
// Preserve default behavior
tokenKind = DelegationTokenIdentifier.HDFS_DELEGATION_KIND.toString();
tokenKind = HDFS_DELEGATION_KIND.toString();
}

acquireDelegationToken(tokenKind, fs);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.apache.hadoop.hbase.security.token;

import static org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier.HDFS_DELEGATION_KIND;
import static org.apache.hadoop.hdfs.web.WebHdfsConstants.SWEBHDFS_TOKEN_KIND;
import static org.apache.hadoop.hdfs.web.WebHdfsConstants.WEBHDFS_TOKEN_KIND;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

Expand All @@ -12,7 +15,6 @@
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
import org.apache.hadoop.hdfs.web.SWebHdfsFileSystem;
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
import org.apache.hadoop.io.Text;
Expand All @@ -23,7 +25,7 @@
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

@Category({ SecurityTests.class, SmallTests.class })
@Category({SecurityTests.class, SmallTests.class})
public class TestFsDelegationToken {
private UserProvider userProvider = Mockito.mock(UserProvider.class);
private User user = Mockito.mock(User.class);
Expand All @@ -49,39 +51,40 @@ public void setup() throws IOException, URISyntaxException {
when(webHdfsFileSystem.getUri()).thenReturn(new URI("webhdfs://someUri"));
when(swebHdfsFileSystem.getCanonicalServiceName()).thenReturn("swebhdfs://");
when(swebHdfsFileSystem.getUri()).thenReturn(new URI("swebhdfs://someUri"));
when(user.getToken(DelegationTokenIdentifier.HDFS_DELEGATION_KIND.toString(),
when(user.getToken(
HDFS_DELEGATION_KIND.toString(),
fileSystem.getCanonicalServiceName()))
.thenReturn(hdfsToken);
when(user.getToken(
WebHdfsFileSystem.TOKEN_KIND.toString(),
WEBHDFS_TOKEN_KIND.toString(),
webHdfsFileSystem.getCanonicalServiceName())).thenReturn(webhdfsToken);
when(user.getToken(
SWebHdfsFileSystem.TOKEN_KIND.toString(),
SWEBHDFS_TOKEN_KIND.toString(),
swebHdfsFileSystem.getCanonicalServiceName())).thenReturn(swebhdfsToken);
when(hdfsToken.getKind()).thenReturn(new Text("HDFS_DELEGATION_TOKEN"));
when(webhdfsToken.getKind()).thenReturn(WebHdfsFileSystem.TOKEN_KIND);
when(swebhdfsToken.getKind()).thenReturn(SWebHdfsFileSystem.TOKEN_KIND);
when(webhdfsToken.getKind()).thenReturn(WEBHDFS_TOKEN_KIND);
when(swebhdfsToken.getKind()).thenReturn(SWEBHDFS_TOKEN_KIND);
}

@Test
public void acquireDelegationToken_defaults_to_hdfsFileSystem() throws IOException {
fsDelegationToken.acquireDelegationToken(fileSystem);
assertEquals(
fsDelegationToken.getUserToken().getKind(), DelegationTokenIdentifier.HDFS_DELEGATION_KIND);
fsDelegationToken.getUserToken().getKind(), HDFS_DELEGATION_KIND);
}

@Test
public void acquireDelegationToken_webhdfsFileSystem() throws IOException {
fsDelegationToken.acquireDelegationToken(webHdfsFileSystem);
assertEquals(
fsDelegationToken.getUserToken().getKind(), WebHdfsFileSystem.TOKEN_KIND);
fsDelegationToken.getUserToken().getKind(), WEBHDFS_TOKEN_KIND);
}

@Test
public void acquireDelegationToken_swebhdfsFileSystem() throws IOException {
fsDelegationToken.acquireDelegationToken(swebHdfsFileSystem);
assertEquals(
fsDelegationToken.getUserToken().getKind(), SWebHdfsFileSystem.TOKEN_KIND);
fsDelegationToken.getUserToken().getKind(), SWEBHDFS_TOKEN_KIND);
}

@Test(expected = NullPointerException.class)
Expand All @@ -92,14 +95,15 @@ public void acquireDelegationTokenByTokenKind_rejects_null_token_kind() throws I
@Test
public void acquireDelegationTokenByTokenKind_webhdfsFileSystem() throws IOException {
fsDelegationToken
.acquireDelegationToken(WebHdfsFileSystem.TOKEN_KIND.toString(), webHdfsFileSystem);
assertEquals(fsDelegationToken.getUserToken().getKind(), WebHdfsFileSystem.TOKEN_KIND);
.acquireDelegationToken(WEBHDFS_TOKEN_KIND.toString(), webHdfsFileSystem);
assertEquals(fsDelegationToken.getUserToken().getKind(), WEBHDFS_TOKEN_KIND);
}

@Test
public void acquireDelegationTokenByTokenKind_swebhdfsFileSystem() throws IOException {
fsDelegationToken
.acquireDelegationToken(SWebHdfsFileSystem.TOKEN_KIND.toString(), swebHdfsFileSystem);
assertEquals(fsDelegationToken.getUserToken().getKind(), SWebHdfsFileSystem.TOKEN_KIND);
.acquireDelegationToken(
SWEBHDFS_TOKEN_KIND.toString(), swebHdfsFileSystem);
assertEquals(fsDelegationToken.getUserToken().getKind(), SWEBHDFS_TOKEN_KIND);
}
}

0 comments on commit 8e53d8f

Please sign in to comment.