|
|
@ -12,11 +12,14 @@ import com.unboundid.ldap.sdk.SearchScope; |
|
|
|
import com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest; |
|
|
|
import com.unboundid.util.ssl.SSLUtil; |
|
|
|
import com.unboundid.util.ssl.TrustAllTrustManager; |
|
|
|
import sun.nio.ch.ThreadPool; |
|
|
|
|
|
|
|
import java.security.GeneralSecurityException; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
public class AccountSource { |
|
|
@ -24,6 +27,7 @@ public class AccountSource { |
|
|
|
final List<SearchResultEntry> searchResultEntryList; |
|
|
|
final Set<String> users; |
|
|
|
final String baseDN; |
|
|
|
final ExecutorService executorService = Executors.newFixedThreadPool(24); |
|
|
|
|
|
|
|
AccountSource(final String baseDN, final List<SearchResultEntry> searchResultEntryList) { |
|
|
|
this.baseDN = baseDN; |
|
|
@ -64,38 +68,48 @@ public class AccountSource { |
|
|
|
|
|
|
|
public void add(final List<Entry> usersToBeAdded) { |
|
|
|
for (final Entry entry : usersToBeAdded) { |
|
|
|
System.out.print("-> Füge Benutzer " + entry.getDN() + "..."); |
|
|
|
final LDAPResult ldapResult; |
|
|
|
try { |
|
|
|
ldapResult = connection.add(entry); |
|
|
|
|
|
|
|
if (ldapResult.getResultCode().intValue() == 0) { |
|
|
|
System.out.print("Ok\n"); |
|
|
|
} else { |
|
|
|
System.out.print("Fehler (" + ldapResult.getResultCode() + ")\n"); |
|
|
|
executorService.submit(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
final LDAPResult ldapResult; |
|
|
|
try { |
|
|
|
ldapResult = connection.add(entry); |
|
|
|
if (ldapResult.getResultCode().intValue() == 0) { |
|
|
|
System.out.print("-> Benutzer cn=" + entry.getDN() + " hinzugefügt...Ok\n"); |
|
|
|
} else { |
|
|
|
System.out.print("Fehler beim Hinzufügen von Benutzer cn=" + entry.getDN() + " (" + ldapResult.getResultCode() + ")\n"); |
|
|
|
} |
|
|
|
} catch (LDAPException e) { |
|
|
|
System.out.print("Fehler beim Hinzufügen von Benutzer cn=" + entry.getDN() + " (" + e.getMessage() + ")\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (LDAPException e) { |
|
|
|
System.out.print("Fehler (" + e.getMessage() + ")\n"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void del(final Set<String> usersToBeDeleted) { |
|
|
|
for (final String user : usersToBeDeleted) { |
|
|
|
System.out.print("-> Lösche Benutzer cn=" + user + "," + this.baseDN + "..."); |
|
|
|
final LDAPResult ldapResult; |
|
|
|
|
|
|
|
try { |
|
|
|
ldapResult = connection.delete("cn=" + user + "," + this.baseDN); |
|
|
|
executorService.submit(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
final LDAPResult ldapResult; |
|
|
|
try { |
|
|
|
ldapResult = connection.delete("cn=" + user + "," + AccountSource.this.baseDN); |
|
|
|
|
|
|
|
if (ldapResult.getResultCode().intValue() == 0) { |
|
|
|
System.out.print("Ok\n"); |
|
|
|
} else { |
|
|
|
System.out.print("Fehler (" + ldapResult.getResultCode() + ")\n"); |
|
|
|
if (ldapResult.getResultCode().intValue() == 0) { |
|
|
|
System.out.print("-> Benutzer cn=" + user + "," + AccountSource.this.baseDN + " gelöscht...Ok\n"); |
|
|
|
} else { |
|
|
|
System.out.print("Fehler beim Löschen von Benutzer cn=" + user + " (" + ldapResult.getResultCode() + ")\n"); |
|
|
|
} |
|
|
|
} catch (LDAPException e) { |
|
|
|
System.out.print("Fehler beim Löschen von Benutzer cn=" + user + " (" + e.getMessage() + ")\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (LDAPException e) { |
|
|
|
System.out.print("Fehler (" + e.getMessage() + ")\n"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void shutdown() { |
|
|
|
executorService.shutdown(); |
|
|
|
} |
|
|
|
} |