OmniaGM commented on code in PR #15277:
URL: https://github.com/apache/kafka/pull/15277#discussion_r1471541316
##########
core/src/test/scala/kafka/security/minikdc/MiniKdc.scala:
##########
@@ -118,123 +96,37 @@ class MiniKdc(config: Properties, workDir: File) extends
Logging {
throw new RuntimeException("KDC already started")
if (closed)
throw new RuntimeException("KDC is closed")
- initDirectoryService()
initKdcServer()
initJvmKerberosConfig()
}
- private def initDirectoryService(): Unit = {
- ds = new DefaultDirectoryService
- ds.setInstanceLayout(new InstanceLayout(workDir))
- ds.setCacheService(new CacheService)
-
- // first load the schema
- val instanceLayout = ds.getInstanceLayout
- val schemaPartitionDirectory = new
File(instanceLayout.getPartitionsDirectory, "schema")
- val extractor = new
DefaultSchemaLdifExtractor(instanceLayout.getPartitionsDirectory)
- extractor.extractOrCopy
-
- val loader = new LdifSchemaLoader(schemaPartitionDirectory)
- val schemaManager = new DefaultSchemaManager(loader)
- schemaManager.loadAllEnabled()
- ds.setSchemaManager(schemaManager)
- // Init the LdifPartition with schema
- val schemaLdifPartition = new LdifPartition(schemaManager, ds.getDnFactory)
- schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI)
-
- // The schema partition
- val schemaPartition = new SchemaPartition(schemaManager)
- schemaPartition.setWrappedPartition(schemaLdifPartition)
- ds.setSchemaPartition(schemaPartition)
-
- val systemPartition = new JdbmPartition(ds.getSchemaManager,
ds.getDnFactory)
- systemPartition.setId("system")
- systemPartition.setPartitionPath(new
File(ds.getInstanceLayout.getPartitionsDirectory, systemPartition.getId).toURI)
- systemPartition.setSuffixDn(new Dn(ServerDNConstants.SYSTEM_DN))
- systemPartition.setSchemaManager(ds.getSchemaManager)
- ds.setSystemPartition(systemPartition)
-
- ds.getChangeLog.setEnabled(false)
- ds.setDenormalizeOpAttrsEnabled(true)
- ds.addLast(new KeyDerivationInterceptor)
-
- // create one partition
- val orgName =
config.getProperty(MiniKdc.OrgName).toLowerCase(Locale.ENGLISH)
- val orgDomain =
config.getProperty(MiniKdc.OrgDomain).toLowerCase(Locale.ENGLISH)
- val partition = new JdbmPartition(ds.getSchemaManager, ds.getDnFactory)
- partition.setId(orgName)
- partition.setPartitionPath(new
File(ds.getInstanceLayout.getPartitionsDirectory, orgName).toURI)
- val dn = new Dn(s"dc=$orgName,dc=$orgDomain")
- partition.setSuffixDn(dn)
- ds.addPartition(partition)
-
- // indexes
- val indexedAttributes = Set[Index[_, String]](
- new JdbmIndex[Entry]("objectClass", false),
- new JdbmIndex[Entry]("dc", false),
- new JdbmIndex[Entry]("ou", false)
- ).asJava
- partition.setIndexedAttributes(indexedAttributes)
-
- // And start the ds
- ds.setInstanceId(config.getProperty(MiniKdc.Instance))
- ds.setShutdownHookEnabled(false)
- ds.startup()
-
- // context entry, after ds.startup()
- val entry = ds.newEntry(dn)
- entry.add("objectClass", "top", "domain")
- entry.add("dc", orgName)
- ds.getAdminSession.add(entry)
- }
-
private def initKdcServer(): Unit = {
-
- def addInitialEntriesToDirectoryService(bindAddress: String): Unit = {
- val map = Map (
- "0" -> orgName.toLowerCase(Locale.ENGLISH),
- "1" -> orgDomain.toLowerCase(Locale.ENGLISH),
- "2" -> orgName.toUpperCase(Locale.ENGLISH),
- "3" -> orgDomain.toUpperCase(Locale.ENGLISH),
- "4" -> bindAddress
- )
- val reader = new BufferedReader(new
InputStreamReader(MiniKdc.getResourceAsStream("minikdc.ldiff")))
- try {
- var line: String = null
- val builder = new StringBuilder
- while ({line = reader.readLine(); line != null})
- builder.append(line).append("\n")
- addEntriesToDirectoryService(StrSubstitutor.replace(builder,
map.asJava))
+ val kdcConfig = new KdcConfig()
+ kdcConfig.setLong(KdcConfigKey.MAXIMUM_RENEWABLE_LIFETIME,
config.getProperty(MiniKdc.MaxRenewableLifetime).toLong)
+ kdcConfig.setLong(KdcConfigKey.MAXIMUM_TICKET_LIFETIME,
+ config.getProperty(MiniKdc.MaxTicketLifetime).toLong)
+ kdcConfig.setString(KdcConfigKey.KDC_REALM, realm)
+ kdcConfig.setString(KdcConfigKey.KDC_HOST,
host.toLowerCase(Locale.ENGLISH))
+ kdcConfig.setInt(KdcConfigKey.KDC_TCP_PORT, port)
+ kdcConfig.setBoolean(KdcConfigKey.PA_ENC_TIMESTAMP_REQUIRED, false)
+ kdcConfig.setString(KdcConfigKey.KDC_SERVICE_NAME,
config.getProperty(MiniKdc.Instance))
+// val bindAddress = config.getProperty(MiniKdc.KdcBindAddress)
Review Comment:
can we delete this committed out line please?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]