From 94cccdb9d5d5896bc9851535b09d64b45bef2161 Mon Sep 17 00:00:00 2001 From: Christian Pape Date: Thu, 2 Nov 2023 11:28:20 +0100 Subject: [PATCH] Allow new fd-number scheme (7 digits) --- src/main/java/de/hsfulda/informatik/LdapSync.java | 11 +++++++++-- src/test/java/de/hsfulda/informatik/LdapSyncTest.java | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsfulda/informatik/LdapSync.java b/src/main/java/de/hsfulda/informatik/LdapSync.java index 7b101b6..fc2f8d7 100644 --- a/src/main/java/de/hsfulda/informatik/LdapSync.java +++ b/src/main/java/de/hsfulda/informatik/LdapSync.java @@ -25,7 +25,8 @@ import java.util.stream.Collectors; */ public class LdapSync { private final Properties properties = new Properties(); - private final static Pattern pattern = Pattern.compile("^fd([a-z][a-z])?([0-9]*?)$"); + private final static Pattern legacyPattern = Pattern.compile("^fd([a-z][a-z])?([0-9]*?)$"); + private final static Pattern newPattern = Pattern.compile("^fd([0-9][0-9][0-9][0-9][0-9][0-9][0-9])$"); private Map userDefinedMappings = Collections.emptyMap(); public LdapSync() throws IOException, LDAPException, GeneralSecurityException { @@ -150,7 +151,13 @@ public class LdapSync { return mappings.get(cn); } - final Matcher m = pattern.matcher(cn); + final Matcher x = newPattern.matcher(cn); + + if (x.find()) { + return 270000000 + Integer.parseInt(x.group(1)); + } + + final Matcher m = legacyPattern.matcher(cn); if (m.find()) { int a = 0; diff --git a/src/test/java/de/hsfulda/informatik/LdapSyncTest.java b/src/test/java/de/hsfulda/informatik/LdapSyncTest.java index c0612b6..3f7ee27 100644 --- a/src/test/java/de/hsfulda/informatik/LdapSyncTest.java +++ b/src/test/java/de/hsfulda/informatik/LdapSyncTest.java @@ -96,6 +96,8 @@ public class LdapSyncTest { assertEquals(10149999, (int) LdapSync.computeUid("fdaa9999")); assertEquals(262641000, (int) LdapSync.computeUid("fdzz1000")); assertEquals(262649999, (int) LdapSync.computeUid("fdzz9999")); + assertEquals(270000001, (int) LdapSync.computeUid("fd0000001")); + assertEquals(279999999, (int) LdapSync.computeUid("fd9999999")); // test user defined mappings Map mappings;