use of com.novell.ldapchai.provider.ChaiProviderFactory in project ldapchai by ldapchai.
the class AdvancedConnection method main.
public static void main(final String[] args) {
// connection parameters
String ldapURL = "ldap://ldaphost:389";
String ldapBindDN = "cn=admin,ou=ou,o=o";
String ldapBindPW = "password";
// allocate a new ChaiConfiguration
ChaiConfiguration chaiConfig = ChaiConfiguration.builder(ldapURL, ldapBindDN, ldapBindPW).setSetting(ChaiSetting.CR_CHAI_STORAGE_ATTRIBUTE, "title").setSetting(ChaiSetting.WATCHDOG_ENABLE, "false").setSetting(ChaiSetting.PROMISCUOUS_SSL, "true").setSetting(ChaiSetting.EDIRECTORY_ENABLE_NMAS, "true").build();
try {
// create a ChaiProviderFactory;
ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
// create a ChaiProvider
ChaiProvider provider = chaiProviderFactory.newProvider(chaiConfig);
// create a ChaiProvider
ChaiUser bindUser = provider.getEntryFactory().newChaiUser(ldapBindDN);
// read the user's last name.
String surname = bindUser.readStringAttribute(ChaiUser.ATTR_SURNAME);
// read the bind user's surname
System.out.println("surname = " + surname);
} catch (ChaiUnavailableException e) {
System.out.println("LDAP unreachable: " + e.getMessage());
} catch (ChaiOperationException e) {
System.out.println("LDAP error: " + e.getMessage());
}
}
use of com.novell.ldapchai.provider.ChaiProviderFactory in project ldapchai by ldapchai.
the class CreateUser method main.
public static void main(final String[] args) {
String ldapURL = "ldap://ldaphost:389";
String ldapBindDN = "cn=admin,ou=ou,o=o";
String ldapBindPW = "password";
// create a provider using the standard JNDI factory.
ChaiProvider provider = null;
try {
final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
provider = chaiProviderFactory.newProvider(ldapURL, ldapBindDN, ldapBindPW);
} catch (ChaiUnavailableException e) {
System.out.println("LDAP error while connecting: " + e);
System.exit(-1);
}
// setup string values to use for the creation
String createDN = "cn=gwashington,ou=ou,o=o";
String createClass = "inetOrgPerson";
// create a Properties to set the initial attribute values for the new user.
Map<String, String> createAttributes = new HashMap<>();
createAttributes.put("givenName", "George");
createAttributes.put("sn", "Washingon");
createAttributes.put("title", "President");
createAttributes.put("mail", "president@whitehouse.gov");
try {
// perform the create operation
provider.createEntry(createDN, createClass, createAttributes);
System.out.println("created user " + createDN);
} catch (ChaiException e) {
System.out.println("error creating user: " + e.getMessage());
}
}
use of com.novell.ldapchai.provider.ChaiProviderFactory in project pwm by pwm-project.
the class LdapSchemaExtendCommand method doCommand.
public void doCommand() throws Exception {
final String ldapUrl = (String) cliEnvironment.getOptions().get(OPTION_LDAPURL);
final String bindDN = (String) cliEnvironment.getOptions().get(OPTION_BIND_DN);
final String bindPW;
if (cliEnvironment.getOptions().containsKey(OPTION_BIND_PW)) {
bindPW = (String) cliEnvironment.getOptions().get(OPTION_BIND_PW);
} else {
final Console console = System.console();
console.writer().write("enter " + OPTION_BIND_PW + ":");
console.writer().flush();
bindPW = new String(console.readPassword());
}
final ChaiProviderFactory chaiProviderFactory = cliEnvironment.getPwmApplication().getLdapConnectionService().getChaiProviderFactory();
final ChaiProvider chaiProvider = chaiProviderFactory.newProvider(ldapUrl, bindDN, bindPW);
final SchemaOperationResult operationResult = SchemaManager.extendSchema(chaiProvider);
final boolean checkOk = operationResult.isSuccess();
if (checkOk) {
out("schema extension complete. all extensions in place = " + checkOk);
} else {
out("schema extension did not complete.\n" + operationResult.getOperationLog());
}
}
use of com.novell.ldapchai.provider.ChaiProviderFactory in project ldapchai by ldapchai.
the class ReadUserData method main.
public static void main(final String[] args) {
String ldapURL = "ldap://ldaphost:389";
String ldapBindDN = "cn=admin,ou=ou,o=o";
String ldapBindPW = "password";
if (args.length == 3) {
ldapURL = args[0];
ldapBindDN = args[1];
ldapBindPW = args[2];
}
try {
// create provider factory
final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
// create a provider using the standard JNDI factory.
ChaiProvider chaiProvider = chaiProviderFactory.newProvider(ldapURL, ldapBindDN, ldapBindPW);
ChaiUser user = chaiProvider.getEntryFactory().newChaiUser(ldapBindDN);
// read the value of the bindDN's cn attribute, and print it to stdout.
Map<String, String> allUserAttributes = user.readStringAttributes(null);
System.out.println("UserDN: " + user.getEntryDN());
// Output each of the user's attributes, and one value for each attribute:
for (String key : allUserAttributes.keySet()) {
String value = allUserAttributes.get(key);
System.out.println(key + ": " + value);
}
// Detect the user's password and output the debug string
ChaiPasswordPolicy pwdPolicy = user.getPasswordPolicy();
System.out.println("PasswordPolicy = " + pwdPolicy);
System.out.println("PasswordModificationDate = " + user.readPasswordModificationDate());
System.out.println("PasswordExpirationDate = " + user.readPasswordExpirationDate());
System.out.println("PasswordExpired = " + user.isPasswordExpired());
System.out.println("PasswordLocked = " + user.isPasswordLocked());
// Read the user's group membership, and output each group DN.
System.out.println(user.getEntryDN() + " groups: ");
for (ChaiGroup group : user.getGroups()) {
System.out.println(group.getEntryDN());
}
System.out.println("");
} catch (ChaiException e) {
System.out.println("LDAP error: " + e.getMessage());
}
}
use of com.novell.ldapchai.provider.ChaiProviderFactory in project ldapchai by ldapchai.
the class SimpleConnection method main.
public static void main(final String[] args) throws ChaiException {
final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
final ChaiProvider chaiProvider = chaiProviderFactory.newProvider("ldap://ldaphost:389", "cn=admin,ou=ou,o=o", "password");
// create a provider using the quick chai factory
final ChaiUser user = chaiProvider.getEntryFactory().newChaiUser("cn=admin,ou=ou,o=o");
// read the value of the bindDN's cn attribute, and print it to stdout.
final String cnValue = user.readStringAttribute("cn");
// output the CN of the user
System.out.println("cnValue = " + cnValue);
}
Aggregations