Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

package org.apache.spark.sql.kafka010

import java.io.{File, IOException}
import java.io.{File, IOException, PrintWriter}
import java.net.{InetAddress, InetSocketAddress}
import java.nio.charset.StandardCharsets
import java.util.{Collections, Properties, UUID}
import java.util.concurrent.TimeUnit
import javax.security.auth.login.Configuration

import scala.collection.JavaConverters._
import scala.io.Source
import scala.util.Random

import com.google.common.io.Files
Expand Down Expand Up @@ -136,6 +137,20 @@ class KafkaTestUtils(
kdcConf.setProperty(MiniKdc.DEBUG, "true")
kdc = new MiniKdc(kdcConf, kdcDir)
kdc.start()
val krb5Conf = Source.fromFile(kdc.getKrb5conf, "UTF-8").getLines()
val rewriteKrb5Conf = krb5Conf.map(s => if (s.contains("libdefaults")) {
s + "\n" +
" default_tkt_enctypes=aes128-cts-hmac-sha1-96\n" +
" default_tgs_enctypes=aes128-cts-hmac-sha1-96 "
} else {
s
})
kdc.getKrb5conf.delete()
val writer = new PrintWriter(kdc.getKrb5conf)
// scalastyle:off
rewriteKrb5Conf.foreach(writer.println)
writer.flush()
writer.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use Files.write(content, file, StandardCharsets.UTF_8) instead of println?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-    val writer = new PrintWriter(kdc.getKrb5conf)
-    // scalastyle:off println
-    writer.println(krb5confStr)
-    // scalastyle:on println
-    writer.close()
+    Files.write(krb5confStr, kdc.getKrb5conf, StandardCharsets.UTF_8)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use Files.write(content, file, StandardCharsets.UTF_8) instead of println?

Done thanks.

kdcReady = true
}

Expand Down Expand Up @@ -171,6 +186,7 @@ class KafkaTestUtils(
| useKeyTab=true
| storeKey=true
| useTicketCache=false
| refreshKrb5Config=true
| keyTab="${zkServerKeytabFile.getAbsolutePath()}"
| principal="$zkServerUser@$realm";
|};
Expand All @@ -180,6 +196,7 @@ class KafkaTestUtils(
| useKeyTab=true
| storeKey=true
| useTicketCache=false
| refreshKrb5Config=true
| keyTab="${zkClientKeytabFile.getAbsolutePath()}"
| principal="$zkClientUser@$realm";
|};
Expand Down