use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project wildfly by wildfly.
the class LdapServerSetupTask method startLdapServer.
@CreateDS(name = "JBossDS-LdapServerSetupTask", 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 startLdapServer(final String hostname) throws Exception, IOException, ClassNotFoundException, FileNotFoundException {
final Map<String, String> map = new HashMap<String, String>();
map.put("hostname", NetworkUtils.formatPossibleIpv6Address(hostname));
directoryService = DSAnnotationProcessor.getDirectoryService();
final String ldifContent = StrSubstitutor.replace(IOUtils.toString(LdapServerSetupTask.class.getResourceAsStream("picketlink-idm-tests.ldif"), "UTF-8"), map);
final SchemaManager schemaManager = directoryService.getSchemaManager();
try {
for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) {
directoryService.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);
ldapServer = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService);
ldapServer.start();
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project jackrabbit-oak by apache.
the class AbstractServer method loadLdif.
protected List<LdifEntry> loadLdif(LdifReader ldifReader) throws Exception {
List<LdifEntry> entries = new ArrayList<LdifEntry>();
for (LdifEntry ldifEntry : ldifReader) {
Dn dn = ldifEntry.getDn();
if (ldifEntry.isEntry()) {
org.apache.directory.api.ldap.model.entry.Entry items = ldifEntry.getEntry();
rootDSE.add(new DefaultEntry(directoryService.getSchemaManager(), items));
LOG.info("Added entry {}", dn);
entries.add(ldifEntry);
}
}
return entries;
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project wildfly by wildfly.
the class LdapExtLDAPServerSetupTask method createLdap2.
//@formatter:off
@CreateDS(name = "JBossComDS", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jbossCom", suffix = "dc=jboss,dc=com", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=com\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }), @CreatePartition(name = "jbossOrg", 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_PORT2) })
public //@formatter:on
void createLdap2(final String hostname) throws Exception {
directoryService2 = DSAnnotationProcessor.getDirectoryService();
final SchemaManager schemaManager = directoryService2.getSchemaManager();
try {
for (LdifEntry ldifEntry : new LdifReader(LdapExtLoginModuleTestCase.class.getResourceAsStream(LdapExtLoginModuleTestCase.class.getSimpleName() + "2.ldif"))) {
directoryService2.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer((CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
fixTransportAddress(createLdapServer, hostname);
ldapServer2 = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService2);
ldapServer2.start();
LOGGER.trace("ldapServer2 = " + ldapServer2);
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project SEPA by arces-wot.
the class LdapSecurityManager method addJwt.
@Override
public void addJwt(String uid, SignedJWT token) throws SEPASecurityException {
logger.log(Level.getLevel("ldap"), "[LDAP] addToken " + uid + " uid=" + uid + ",ou=tokens," + prop.getBase(), "(objectclass=*)");
bind();
try {
cursor = ldap.search("uid=" + uid + ",ou=tokens," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
if (!cursor.next()) {
ldap.add(new DefaultEntry("uid=" + uid + ",ou=tokens," + prop.getBase(), "ObjectClass: top", "ObjectClass: account", "ObjectClass: javaSerializedObject", "javaClassName: " + token.getClass().getName(), "javaSerializedData: " + token.serialize()));
} else {
Modification replaceGn = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, "javaSerializedData", token.serialize());
ldap.modify("uid=" + uid + ",ou=tokens," + prop.getBase(), replaceGn);
}
} catch (LdapException | CursorException e) {
logger.error("[LDAP] addToken exception " + e.getMessage());
throw new SEPASecurityException("addToken exception " + e.getMessage());
} finally {
unbind();
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project SEPA by arces-wot.
the class LdapSecurityManager method storeCredentials.
@Override
public boolean storeCredentials(DigitalIdentity identity, String client_secret) throws SEPASecurityException {
logger.log(Level.getLevel("ldap"), "[LDAP] storeCredentials " + identity + " secret: " + client_secret);
byte[] password = PasswordUtil.createStoragePassword(client_secret.getBytes(), LdapSecurityConstants.HASH_METHOD_SSHA);
bind();
try {
cursor = ldap.search("uid=" + identity.getUid() + ",ou=credentials," + prop.getBase(), "(objectclass=*)", SearchScope.OBJECT, "*");
if (cursor.next())
removeCredentials(identity);
Entry entry = new DefaultEntry("uid=" + identity.getUid() + ",ou=credentials," + prop.getBase());
entry.add("ObjectClass", "top");
entry.add("ObjectClass", identity.getObjectClass());
entry.add("ObjectClass", "uidObject");
entry.add("ObjectClass", "simpleSecurityObject");
entry.add("ObjectClass", "javaSerializedObject");
if (identity.getObjectClass().equals("inetOrgPerson")) {
entry.add("cn", ((UserIdentity) identity).getCommonName());
entry.add("sn", ((UserIdentity) identity).getSurname());
} else
entry.add("cn", "Authorized Digital Identity " + identity.getUid());
entry.add("uid", identity.getUid());
entry.add("userPassword", password);
entry.add("javaClassName", identity.getEndpointCredentials().getClass().getName());
entry.add("javaSerializedData", identity.getEndpointCredentials().serialize());
ldap.add(entry);
} catch (LdapException | CursorException e) {
logger.error("[LDAP] storeCredentials exception " + e.getMessage());
throw new SEPASecurityException("storeCredentials exception " + e.getMessage());
} finally {
unbind();
}
return true;
}
Aggregations