diff options
Diffstat (limited to 'src/main')
-rwxr-xr-x | src/main/java/io/trygvis/esper/testing/LdapImporter.java (renamed from src/main/java/io/trygvis/esper/testing/PersonGenerator.java) | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/PersonGenerator.java b/src/main/java/io/trygvis/esper/testing/LdapImporter.java index 28d8438..b29b325 100755 --- a/src/main/java/io/trygvis/esper/testing/PersonGenerator.java +++ b/src/main/java/io/trygvis/esper/testing/LdapImporter.java @@ -11,21 +11,21 @@ import java.util.*; import javax.naming.*; import javax.naming.directory.*; -public class PersonGenerator { +public class LdapImporter { public static void main(String[] args) throws Exception { Config config = Config.loadFromDisk("person-generator"); final Logger logger = LoggerFactory.getLogger(config.appName); - String ldapHost = System.getProperty("ldap.host", "localhost"); - int ldapPort = Integer.parseInt(System.getProperty("ldap.port", "386")); - String baseDn = System.getProperty("ldap.base"); - - if(baseDn == null) { - System.err.println("Missing system property: ldap.base"); - return; + if(args.length != 3) { + System.err.println("Usage: ldap-importer [ldap host] [ldap port] [base dn]"); + System.exit(1); } + String ldapHost = args[0]; + int ldapPort = Integer.parseInt(args[1]); + String baseDn = args[2]; + Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); properties.put(Context.PROVIDER_URL, "ldap://" + ldapHost + ":" + ldapPort); @@ -35,8 +35,7 @@ public class PersonGenerator { InitialDirContext context = new InitialDirContext(properties); SearchControls searchCtls = new SearchControls(); searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); - String returnedAtts[] = {"uid", "mail", "displayName"}; - searchCtls.setReturningAttributes(returnedAtts); + searchCtls.setReturningAttributes(new String[]{"uid", "mail", "displayName"}); NamingEnumeration answer = context.search(baseDn, "(&(uid=*)(mail=*)(displayName=*))", searchCtls); BoneCPDataSource dataSource = config.createBoneCp(); |