You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by co...@apache.org on 2023/01/26 06:44:49 UTC

[directory-kerby] branch coheigea/DIRKRB-764 created (now 842389dd)

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a change to branch coheigea/DIRKRB-764
in repository https://gitbox.apache.org/repos/asf/directory-kerby.git


      at 842389dd DIRKRB-764 - ClassCastException during KerbConf creation

This branch includes the following new commits:

     new 842389dd DIRKRB-764 - ClassCastException during KerbConf creation

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[directory-kerby] 01/01: DIRKRB-764 - ClassCastException during KerbConf creation

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch coheigea/DIRKRB-764
in repository https://gitbox.apache.org/repos/asf/directory-kerby.git

commit 842389ddb24f46f6dd4942681c00b8fb7e33d772
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Jan 26 06:44:27 2023 +0000

    DIRKRB-764 - ClassCastException during KerbConf creation
---
 .../org/apache/kerby/config/MapConfigLoader.java   | 40 ++++--------
 .../kerberos/kerb/client/KrbConfigLoadTest.java    |  9 +++
 .../src/test/resources/krb5include.conf            | 75 ++++++++++++++++++++++
 3 files changed, 97 insertions(+), 27 deletions(-)

diff --git a/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java b/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
index 3ba5d4c3..90284f7e 100644
--- a/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
+++ b/kerby-common/kerby-config/src/main/java/org/apache/kerby/config/MapConfigLoader.java
@@ -28,35 +28,21 @@ public class MapConfigLoader extends ConfigLoader {
         @SuppressWarnings("unchecked")
         Map<String, Object> mapConfig = (Map<String, Object>) resource.getResource();
         Iterator<Map.Entry<String, Object>> iter = mapConfig.entrySet().iterator();
-        if (iter.hasNext()) {
-            Map.Entry entry = iter.next();
+        while (iter.hasNext()) {
+            Map.Entry<String, Object> entry = iter.next();
             if (entry.getValue() instanceof String) {
-                //insert StringMap
-                loadStringMap(config, mapConfig);
-            }   else {
-                //insert objectMap
-                loadObjectMap(config, mapConfig);
-            }
-        }
-    }
-
-    private void loadStringMap(ConfigImpl config, Map<String, Object> stringMap) {
-        for (Map.Entry<String, Object> entry: stringMap.entrySet()) {
-            config.set(entry.getKey(), (String) entry.getValue());
-        }
-    }
+                config.set(entry.getKey(), (String) entry.getValue());
+            } else {
+                String key = entry.getKey();
+                Object value = entry.getValue();
 
-    private void loadObjectMap(ConfigImpl config, Map<String, Object> objectMap) {
-        for (Map.Entry<String, Object> entry: objectMap.entrySet()) {
-            String key = entry.getKey();
-            Object value = entry.getValue();
-
-            if (value instanceof Map) {
-                ConfigImpl subConfig = new ConfigImpl(key); //new section
-                loadSubmap(subConfig, (Map) value);
-                config.add(subConfig);
-            }   else {
-                throw new RuntimeException("Unable to resolve config:" + key);
+                if (value instanceof Map) {
+                    ConfigImpl subConfig = new ConfigImpl(key); //new section
+                    loadSubmap(subConfig, (Map) value);
+                    config.add(subConfig);
+                } else {
+                    throw new RuntimeException("Unable to resolve config:" + key);
+                }
             }
         }
     }
diff --git a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java
index eb792d11..881c746a 100644
--- a/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java
+++ b/kerby-kerb/kerb-client/src/test/java/org/apache/kerby/kerberos/kerb/client/KrbConfigLoadTest.java
@@ -65,4 +65,13 @@ public class KrbConfigLoadTest {
         assertThat(krbConfig.getRealmSectionItems("ATHENA.MIT.EDU", "admin_server")).hasSize(1);
         assertThat(krbConfig.getCapath("ATHENA.MIT.EDU", "ANDREW.CMU.EDU")).hasSize(3);
     }
+
+    @Test
+    public void testIncludeDir() throws Exception {
+        URL confFileUrl = KrbConfigLoadTest.class.getResource("/krb5include.conf");
+        File confFile = new File(confFileUrl.toURI());
+
+        KrbConfig krbConfig = new KrbConfig();
+        krbConfig.addKrb5Config(confFile);
+    }
 }
diff --git a/kerby-kerb/kerb-client/src/test/resources/krb5include.conf b/kerby-kerb/kerb-client/src/test/resources/krb5include.conf
new file mode 100644
index 00000000..95962954
--- /dev/null
+++ b/kerby-kerb/kerb-client/src/test/resources/krb5include.conf
@@ -0,0 +1,75 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+includedir /etc
+includedir /tmp
+[libdefaults]
+  default_realm = KRB.COM
+  kdc_host = kdc-server.example.com
+  kdc_realm = TEST.COM
+  dns_lookup_kdc = false
+  dns_lookup_realm = false
+  allow_weak_crypto = true
+  ticket_lifetime = 86400
+  renew_lifetime = 604800
+  forwardable = true
+  permitted_enctypes = des-cbc-crc aes128-cts-hmac-sha1-96
+  clockskew = 300
+  proxiable = true
+  default_tgs_enctypes = des-cbc-crc
+  default_tkt_enctypes = des-cbc-crc
+  pkinit_anchors = FILE:/etc/krb5/cacert.pem
+  pkinit_identities = FILE:/etc/krb5/client.pem,/etc/krb5/clientkey.pem
+  pkinit_kdc_hostname = kdc-server.example.com
+[realms]
+  ATHENA.MIT.EDU = {
+        admin_server = KERBEROS.MIT.EDU
+        default_domain = MIT.EDU
+        v4_instance_convert = {
+            mit = mit.edu
+            lithium = lithium.lcs.mit.edu
+        }
+    }
+    ANDREW.CMU.EDU = {
+      admin_server = vice28.fs.andrew.cmu.edu
+    }
+  GNU.ORG = {
+    kdc = kerberos.gnu.org
+    kdc = kerberos-2.gnu.org
+    admin_server = kerberos.gnu.org
+ }
+[domain_realm]
+  .mit.edu = ATHENA.MIT.EDU
+    mit.edu = ATHENA.MIT.EDU
+    .media.mit.edu = MEDIA-LAB.MIT.EDU
+    media.mit.edu = MEDIA-LAB.MIT.EDU
+    .ucsc.edu = CATS.UCSC.EDU
+[logging]
+ default = FILE:/var/log/krb5libs.log
+ kdc = FILE:/var/log/krb5kdc.log
+ admin_server = FILE:/var/log/kadmind.log
+[capaths]
+  ATHENA.MIT.EDU = {
+    ANDREW.CMU.EDU = GNU.ORG
+    GNU.ORG = .
+  }
+  ANDREW.CMU.EDU = {
+    ATHENA.MIT.EDU = GNU.ORG
+  }
+  GNU.ORG = {
+    ATHENA.MIT.EDU = .
+  }
\ No newline at end of file