use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project wildfly by wildfly.
the class LdapExtLDAPServerSetupTask method createLdap1.
//@formatter:off
@CreateDS(name = "JBossDS-LdapExtLDAPServerSetupTask", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jboss", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }) }, additionalInterceptors = { KeyDerivationInterceptor.class })
@CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP", port = LDAP_PORT), @CreateTransport(protocol = "LDAPS", port = LDAPS_PORT) }, certificatePassword = "secret")
public //@formatter:on
void createLdap1(final String hostname) throws Exception {
final Map<String, String> map = new HashMap<String, String>();
map.put("hostname", NetworkUtils.formatPossibleIpv6Address(hostname));
map.put("ldapPort2", Integer.toString(LDAP_PORT2));
directoryService1 = DSAnnotationProcessor.getDirectoryService();
final String ldifContent = StrSubstitutor.replace(IOUtils.toString(LdapExtLoginModuleTestCase.class.getResourceAsStream(LdapExtLoginModuleTestCase.class.getSimpleName() + ".ldif"), "UTF-8"), map);
LOGGER.debug(ldifContent);
final SchemaManager schemaManager = directoryService1.getSchemaManager();
try {
for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) {
directoryService1.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer((CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
FileOutputStream fos = new FileOutputStream(KEYSTORE_FILE);
IOUtils.copy(getClass().getResourceAsStream(KEYSTORE_FILENAME), fos);
fos.close();
createLdapServer.setKeyStore(KEYSTORE_FILE.getAbsolutePath());
fixTransportAddress(createLdapServer, hostname);
ldapServer1 = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService1);
ldapServer1.start();
LOGGER.trace("ldapServer1 = " + ldapServer1);
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project midpoint by Evolveum.
the class AbstractAdLdapTest method createAccountEntry.
@Override
protected Entry createAccountEntry(String uid, String cn, String givenName, String sn) throws LdapException {
byte[] password = encodePassword("Secret.123");
Entry entry = new DefaultEntry(toAccountDn(uid, cn), "objectclass", getLdapAccountObjectClass(), ATTRIBUTE_SAM_ACCOUNT_NAME_NAME, uid, "cn", cn, "givenName", givenName, "sn", sn, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512", ATTRIBUTE_UNICODE_PWD_NAME, password);
return entry;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project midpoint by Evolveum.
the class AbstractAdLdapMultidomainTest method createAccountEntry.
@Override
protected Entry createAccountEntry(String uid, String cn, String givenName, String sn) throws LdapException {
byte[] password = encodePassword("Secret.123");
Entry entry = new DefaultEntry(toAccountDn(uid, cn), "objectclass", getLdapAccountObjectClass(), ATTRIBUTE_SAM_ACCOUNT_NAME_NAME, uid, "cn", cn, "givenName", givenName, "sn", sn, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512", ATTRIBUTE_UNICODE_PWD_NAME, password);
return entry;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project aws-iam-ldap-bridge by denismo.
the class Runner method createStructure.
public void createStructure() throws Exception {
String rootDN = AWSIAMAuthenticator.getConfig().rootDN;
Dn dnIAM = service.getDnFactory().create(rootDN);
if (!utils.exists(dnIAM)) {
IAM_LOG.info("Creating partition " + rootDN);
Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory());
// Index some attributes on the apache partition
utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn");
if (!utils.exists(dnIAM)) {
IAM_LOG.info("Creating root node " + rootDN);
Rdn rdn = dnIAM.getRdn(0);
Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain", "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString(), rdn.getType() + ": " + rdn.getValue());
service.getAdminSession().add(entryIAM);
checkErrors();
}
}
service.sync();
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project undertow by undertow-io.
the class KerberosKDCUtil method processLdif.
private static void processLdif(final SchemaManager schemaManager, final CoreSession adminSession, final String ldifName, final Map<String, String> mappings) throws Exception {
InputStream resourceInput = KerberosKDCUtil.class.getResourceAsStream("/ldif/" + ldifName);
ByteArrayOutputStream baos = new ByteArrayOutputStream(resourceInput.available());
int current;
while ((current = resourceInput.read()) != -1) {
if (current == '$') {
// Enter String replacement mode.
int second = resourceInput.read();
if (second == '{') {
ByteArrayOutputStream substitute = new ByteArrayOutputStream();
while ((current = resourceInput.read()) != -1 && current != '}') {
substitute.write(current);
}
if (current == -1) {
baos.write(current);
baos.write(second);
// Terminator never found.
baos.write(substitute.toByteArray());
}
String toReplace = new String(substitute.toByteArray(), StandardCharsets.UTF_8);
if (mappings.containsKey(toReplace)) {
baos.write(mappings.get(toReplace).getBytes());
} else {
throw new IllegalArgumentException(String.format("No mapping found for '%s'", toReplace));
}
} else {
baos.write(current);
baos.write(second);
}
} else {
baos.write(current);
}
}
ByteArrayInputStream ldifInput = new ByteArrayInputStream(baos.toByteArray());
LdifReader ldifReader = new LdifReader(ldifInput);
for (LdifEntry ldifEntry : ldifReader) {
adminSession.add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
ldifReader.close();
ldifInput.close();
}
Aggregations