本文整理汇总了Java中org.apache.directory.shared.ldap.ldif.LdifEntry类的典型用法代码示例。如果您正苦于以下问题:Java LdifEntry类的具体用法?Java LdifEntry怎么用?Java LdifEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LdifEntry类属于org.apache.directory.shared.ldap.ldif包,在下文中一共展示了LdifEntry类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadLdif
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
/**
* Loads an LDIF from an input stream and adds the entries it contains to the server. It appears
* as though the administrator added these entries to the server.
*
* @param in
* the input stream containing the LDIF entries to load
* @param verifyEntries
* whether or not all entry additions are checked to see if they were in fact
* correctly added to the server
* @return a list of entries added to the server in the order they were added
* @throws Exception
* of the load fails
*/
protected List<LdifEntry> loadLdif(InputStream in, boolean verifyEntries) throws Exception {
if (in == null) {
return EMPTY_LIST;
}
LdifReader ldifReader = new LdifReader(in);
ArrayList<LdifEntry> entries = new ArrayList<LdifEntry>();
for (LdifEntry entry : ldifReader) {
getRootDSE()
.add(new DefaultServerEntry(getDirectoryService().getRegistries(), entry
.getEntry()));
if (verifyEntries) {
verify(entry);
LOG.info("Successfully verified addition of entry " + entry.getDn());
} else {
LOG.info("Added entry " + entry.getDn() + " without verification");
}
entries.add(entry);
}
return entries;
}
示例2: verify
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
/**
* Verifies that an entry exists in the directory with the specified attributes.
*
* @param entry
* the entry to verify
* @throws Exception
* if there are problems accessing the entry
*/
protected void verify(LdifEntry entry) throws Exception {
Entry readEntry = getRootDSE().lookup(entry.getDn());
for (EntryAttribute readAttribute : readEntry) {
String id = readAttribute.getId();
EntryAttribute origAttribute = entry.getEntry().get(id);
for (Value<?> value : origAttribute) {
if (!readAttribute.contains(value)) {
LOG.error("Failed to verify entry addition of " + entry.getDn() + ". " + id
+ " attribute in original entry missing from read entry.");
throw new AssertionError("Failed to verify entry addition of " + entry.getDn());
}
}
}
}
示例3: injectLdifFiles
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
public static void injectLdifFiles(String... ldifFiles) throws Exception {
if (ldifFiles != null && ldifFiles.length > 0) {
for (String ldifFile : ldifFiles) {
InputStream is = null;
try {
is = LdapTestParent.class.getClassLoader().getResourceAsStream(ldifFile);
if (is == null) {
throw new FileNotFoundException("LDIF file '" + ldifFile + "' not found.");
} else {
try {
LdifReader ldifReader = new LdifReader(is);
for (LdifEntry entry : ldifReader) {
injectEntry(entry);
}
ldifReader.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} finally {
IOUtils.closeQuietly(is);
}
}
}
}
示例4: injectLdifFiles
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
public static void injectLdifFiles(String... ldifFiles) throws Exception {
if (ldifFiles != null && ldifFiles.length > 0) {
for (String ldifFile : ldifFiles) {
InputStream is = null;
try {
is = BasicAuthLDAPTest.class.getClassLoader().getResourceAsStream(ldifFile);
if (is == null) {
throw new FileNotFoundException("LDIF file '" + ldifFile + "' not found.");
} else {
try {
LdifReader ldifReader = new LdifReader(is);
for (LdifEntry entry : ldifReader) {
injectEntry(entry);
}
ldifReader.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} finally {
IOUtils.closeQuietly(is);
}
}
}
}
示例5: injectLdifFiles
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
public static void injectLdifFiles(String... ldifFiles) throws Exception {
if (ldifFiles != null && ldifFiles.length > 0) {
for (String ldifFile : ldifFiles) {
InputStream is = null;
try {
is = ApimanLdapServer.class.getClassLoader().getResourceAsStream(ldifFile);
if (is == null) {
throw new FileNotFoundException("LDIF file '" + ldifFile + "' not found.");
} else {
try {
LdifReader ldifReader = new LdifReader(is);
for (LdifEntry entry : ldifReader) {
injectEntry(entry);
}
ldifReader.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} finally {
IOUtils.closeQuietly(is);
}
}
}
}
示例6: importLdif
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
/**
* Stream will be closed automatically.
*/
public void importLdif(@WillClose InputStream is) throws Exception {
Preconditions.checkState(directoryService.isStarted(), "Directory service not started");
try {
LdifReader entries = new LdifReader(is);
CoreSession rootDSE = directoryService.getAdminSession();
for (LdifEntry ldifEntry : entries) {
rootDSE.add(new DefaultServerEntry(rootDSE.getDirectoryService().getRegistries(), ldifEntry.getEntry()));
}
} finally {
Closeables.closeQuietly(is);
}
}
示例7: importLdif
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
/**
* Imports the LDIF entries packaged with the Eve JNDI provider jar into the newly created
* system partition to prime it up for operation. Note that only ou=system entries will be added
* - entries for other partitions cannot be imported and will blow chunks.
*
* @throws Exception
* if there are problems reading the ldif file and adding those entries to the
* system partition
* @param in
* the input stream with the ldif
*/
protected void importLdif(InputStream in) throws Exception {
try {
for (LdifEntry ldifEntry : new LdifReader(in)) {
getRootDSE().add(
new DefaultServerEntry(getRootDSE().getDirectoryService().getRegistries(),
ldifEntry.getEntry()));
}
} catch (Exception e) {
String msg = "failed while trying to parse system ldif file";
Exception ne = new LdapConfigurationException(msg, e);
throw ne;
}
}
示例8: injectEntries
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
/**
* Inject an ldif String into the server. DN must be relative to the root.
*
* @param ldif
* the entries to inject
* @throws Exception
* if the entries cannot be added
*/
protected void injectEntries(String ldif) throws Exception {
LdifReader reader = new LdifReader();
List<LdifEntry> entries = reader.parseLdif(ldif);
for (LdifEntry entry : entries) {
getRootDSE().add(
new DefaultServerEntry(getRootDSE().getDirectoryService().getRegistries(),
entry.getEntry()));
}
}
示例9: injectEntry
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
private static void injectEntry(LdifEntry entry) throws Exception {
if (entry.isChangeAdd()) {
service.getAdminSession().add(
new DefaultServerEntry(service.getSchemaManager(), entry.getEntry()));
} else if (entry.isChangeModify()) {
service.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
} else {
String message = I18n.err(I18n.ERR_117, entry.getChangeType());
throw new NamingException(message);
}
}
示例10: loadTestLdif
import org.apache.directory.shared.ldap.ldif.LdifEntry; //导入依赖的package包/类
/**
* If there is an LDIF file with the same name as the test class but with the .ldif extension
* then it is read and the entries it contains are added to the server. It appears as though the
* administor adds these entries to the server.
*
* @param verifyEntries
* whether or not all entry additions are checked to see if they were in fact
* correctly added to the server
* @return a list of entries added to the server in the order they were added
* @throws Exception
* of the load fails
*/
protected List<LdifEntry> loadTestLdif(boolean verifyEntries) throws Exception {
return loadLdif(getClass().getResourceAsStream(getClass().getSimpleName() + ".ldif"),
verifyEntries);
}