Skip to content

Commit

Permalink
[apache#625] improvement: Package sun.security.krb5 is not visible in…
Browse files Browse the repository at this point in the history
… Java 11 and 17. (apache#726)

### What changes were proposed in this pull request?

Try remove `sun.security.krb5.Config.refresh();`

### Why are the changes needed?

`sun.security.krb5` is not visible in Java 11 and 17. We need to compile on JDK11 and JDK17

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Unit test verification.

Co-authored-by: slfan1989 <louj1988@@>
  • Loading branch information
2 people authored and xianjingfeng committed Apr 5, 2023
1 parent dfa3535 commit d2094e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public HadoopSecurityContext(

if (StringUtils.isNotEmpty(krb5ConfPath)) {
System.setProperty(KRB5_CONF_KEY, krb5ConfPath);
sun.security.krb5.Config.refresh();
}

Configuration conf = new Configuration(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public void testSecuredCallable() throws Exception {

@Test
public void testCreateIllegalContext() throws Exception {
System.setProperty("sun.security.krb5.debug", "true");

// case1: lack principal, should throw exception
try (HadoopSecurityContext context = new HadoopSecurityContext(
null,
Expand Down Expand Up @@ -111,20 +113,9 @@ public void testCreateIllegalContext() throws Exception {
assertTrue(e.getMessage().contains("refreshIntervalSec must be not negative"));
}

// case4: lack krb5 conf, should throw exception
// case4: After setting the krb5 conf, it should pass
String krbConfFilePath = System.getProperty("java.security.krb5.conf");
System.clearProperty("java.security.krb5.conf");
try (HadoopSecurityContext context = new HadoopSecurityContext(
null,
kerberizedHdfs.getHdfsKeytab(),
kerberizedHdfs.getHdfsPrincipal(),
100)) {
fail();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Cannot locate KDC"));
}

// case5: After setting the krb5 conf, it should pass
HadoopSecurityContext context = new HadoopSecurityContext(
krbConfFilePath,
kerberizedHdfs.getHdfsKeytab(),
Expand All @@ -136,4 +127,23 @@ public void testCreateIllegalContext() throws Exception {
// recover System property of krb5 conf
System.setProperty("java.security.krb5.conf", krbConfFilePath);
}

@Test
public void testWithOutKrb5Conf() {
// case: lack krb5 conf, should throw exception
String krbConfFilePath = System.getProperty("java.security.krb5.conf");
System.clearProperty("java.security.krb5.conf");
try (HadoopSecurityContext context2 = new HadoopSecurityContext(
null,
kerberizedHdfs.getHdfsKeytab(),
kerberizedHdfs.getHdfsPrincipal(),
100)) {
fail();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Cannot locate KDC"));
}

// recover System property of krb5 conf
System.setProperty("java.security.krb5.conf", krbConfFilePath);
}
}

0 comments on commit d2094e2

Please sign in to comment.