diff --git a/src/main/java/de/hsfulda/informatik/LdapSync.java b/src/main/java/de/hsfulda/informatik/LdapSync.java index d46b44e..1188e40 100644 --- a/src/main/java/de/hsfulda/informatik/LdapSync.java +++ b/src/main/java/de/hsfulda/informatik/LdapSync.java @@ -25,7 +25,7 @@ import java.util.stream.Collectors; */ public class LdapSync { private final Properties properties = new Properties(); - private final static Pattern legacyPattern = 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 final static Pattern newGuestPattern = Pattern.compile("^fdg([0-9][0-9][0-9][0-9][0-9])$"); private Map userDefinedMappings = Collections.emptyMap(); @@ -173,7 +173,9 @@ public class LdapSync { if (m.group(1) != null) { a = m.group(1).charAt(0) - 96; - b = m.group(1).charAt(1) - 96; + if (m.group(1).length()>1) { + b = m.group(1).charAt(1) - 96; + } } final int s = m.group(2).length(); diff --git a/src/test/java/de/hsfulda/informatik/LdapSyncTest.java b/src/test/java/de/hsfulda/informatik/LdapSyncTest.java index 52ce44a..95ad068 100644 --- a/src/test/java/de/hsfulda/informatik/LdapSyncTest.java +++ b/src/test/java/de/hsfulda/informatik/LdapSyncTest.java @@ -30,6 +30,7 @@ public class LdapSyncTest { remoteEntries.add(searchResultEntry("dn=fDai1235,dc=remote,dc=de", "FDai1235", "Schuster", "Schuster")); remoteEntries.add(searchResultEntry("dn=fdaI1236,dc=remote,dc=de", "fdAI1236", "Bunsen", "Bunsen")); remoteEntries.add(searchResultEntry("dn=fDeT123,dc=remote,dc=de", "FDET123", "Bauer", "Bauer")); + remoteEntries.add(searchResultEntry("dn=fdw9424,dc=remote,dc=de", "fdw9424", "Hein", "Bloed")); remoteEntries.add(searchResultEntry("dn=fdXx9999,dc=remote,dc=de", "fdxX9999", "Schmidt", "Schmidt")); final AccountSource remote = new AccountSource("dc=remote,dc=de", remoteEntries); @@ -55,7 +56,7 @@ public class LdapSyncTest { assertTrue(delSet.contains("fdai1237")); assertTrue(delSet.contains("fdai1238")); - assertEquals(addList.size(), 4); + assertEquals(5, addList.size()); for (final Entry entry : addList) { assertTrue(entry.getDN().endsWith(",dc=local,dc=de")); @@ -116,14 +117,17 @@ public class LdapSyncTest { mappings = LdapSync.parseUserDefinedMappings("fdg00244:300000244"); assertEquals(300000244, (int) LdapSync.computeUid("fdg00244", mappings)); - assertEquals(41000, (int) LdapSync.computeUid("fd1000", mappings)); - assertEquals(49999, (int) LdapSync.computeUid("fd9999", mappings)); - assertEquals(10141000, (int) LdapSync.computeUid("fdaa1000", mappings)); - assertEquals(10149999, (int) LdapSync.computeUid("fdaa9999", mappings)); + assertEquals( 41000, (int) LdapSync.computeUid("fd1000", mappings)); + assertEquals( 49999, (int) LdapSync.computeUid("fd9999", mappings)); + assertEquals( 10141000, (int) LdapSync.computeUid("fdaa1000", mappings)); assertEquals(262641000, (int) LdapSync.computeUid("fdzz1000", mappings)); + assertEquals( 10041000, (int) LdapSync.computeUid("fda1000", mappings)); + assertEquals(260041000, (int) LdapSync.computeUid("fdz1000", mappings)); + assertEquals( 10149999, (int) LdapSync.computeUid("fdaa9999", mappings)); assertEquals(262649999, (int) LdapSync.computeUid("fdzz9999", mappings)); assertEquals(300000000, (int) LdapSync.computeUid("fdg00000", mappings)); assertEquals(300099999, (int) LdapSync.computeUid("fdg99999", mappings)); + assertEquals(230049123, (int) LdapSync.computeUid("fdw9123", mappings)); mappings = LdapSync.parseUserDefinedMappings("aaabbb"); assertEquals(0, mappings.size());