3 Commits

  1. 21
      src/main/java/de/hsfulda/informatik/LdapSync.java
  2. 18
      src/test/java/de/hsfulda/informatik/LdapSyncTest.java

21
src/main/java/de/hsfulda/informatik/LdapSync.java

@ -25,7 +25,9 @@ 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 final static Pattern newGuestPattern = Pattern.compile("^fdg([0-9][0-9][0-9][0-9][0-9])$");
private Map<String, Integer> userDefinedMappings = Collections.emptyMap();
public LdapSync() throws IOException, LDAPException, GeneralSecurityException {
@ -150,7 +152,20 @@ 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 y = newGuestPattern.matcher(cn);
if (y.find()) {
return 300000000 + Integer.parseInt(y.group(1));
}
final Matcher m = legacyPattern.matcher(cn);
if (m.find()) {
int a = 0;
@ -158,8 +173,10 @@ public class LdapSync {
if (m.group(1) != null) {
a = m.group(1).charAt(0) - 96;
if (m.group(1).length()>1) {
b = m.group(1).charAt(1) - 96;
}
}
final int s = m.group(2).length();
final int z = Integer.parseInt(m.group(2));

18
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"));
@ -96,6 +97,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<String, Integer> mappings;
@ -114,12 +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());

Loading…
Cancel
Save