本文整理汇总了Java中com.unboundid.ldif.LDIFReader类的典型用法代码示例。如果您正苦于以下问题:Java LDIFReader类的具体用法?Java LDIFReader怎么用?Java LDIFReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LDIFReader类属于com.unboundid.ldif包,在下文中一共展示了LDIFReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importLdifFileInLdap
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException {
ResultCode result = ResultCode.UNAVAILABLE;
LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
try {
LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
LDIFReader importLdifReader = new LDIFReader(is);
result = ldifDataUtility.importLdifFile(connection, importLdifReader);
importLdifReader.close();
} catch (Exception ex) {
log.error("Failed to import ldif file: ", ex);
} finally {
ldapEntryManager.getOperationService().releaseConnection(connection);
}
return result;
}
示例2: start
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
@Override
public void start() {
try {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=MyDomain");
config.addAdditionalBindCredentials("cn=Directory Manager", "password");
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", 1389));
config.setSchema(null);
ds = new InMemoryDirectoryServer(config);
ds.startListening();
ds.importFromLDIF(true, new LDIFReader(getClass().getResourceAsStream("/conf/realm.ldif")));
} catch (LDAPException e) {
ds = null;
log.error("Failed to start UnboundID LDAP server!", e);
}
}
示例3: loadLdifFiles
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
/**
* Load any LDIF files identified within the annotation @Ldif
*/
protected void loadLdifFiles() throws Exception {
Iterable<String> ldifResources = ldifResources();
for (String ldif : ldifResources) {
Class clazz = (annotatedClass != null) ? annotatedClass : getClass();
InputStream resourceAsStream = clazz.getResourceAsStream(ldif);
if (resourceAsStream == null) {
throw new FileNotFoundException("Should be able to load " + ldif);
}
LDIFReader r = new LDIFReader(resourceAsStream);
LDIFChangeRecord readEntry = null;
while ((readEntry = r.readChangeRecord()) != null) {
readEntry.processChange(server);
}
resourceAsStream.close();
}
}
示例4: init
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
@Before
public void init() throws Exception {
ds.clear();
ds.importFromLDIF(true, new LDIFReader(getClass().getResourceAsStream("/conf/realm.ldif")));
Map<String, Object> settings = getSettings();
ldap = newRealm(settings);
}
示例5: loadLdifFiles
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
/**
* Loads LDIF files as specified in the configuration file.
*
* @throws Exception
*/
protected void loadLdifFiles() throws Exception {
LOG.info(">>>loadLdifFiles()");
LOG.debug("{}", System.getProperty("java.class.path"));
LOG.info(" ...loading LDIF resources: ");
int ldifLoadCount = 0;
for (Ldif ldif : configuration.getLdifs()) {
LOG.info("----------------------------------------------------------");
LOG.info(" loading LDIF: {}", ldif.getName());
ldifLoadCount++;
InputStream resourceAsStream = null;
try {
LOG.info(" file: '{}'", ldif.getName());
resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(ldif.getName());
if (resourceAsStream == null) {
throw new FileNotFoundException("Should be able to load: " + ldif.getName());
}
LDIFReader r = new LDIFReader(resourceAsStream);
LDIFChangeRecord readEntry = null;
int entryCount = 0;
while ((readEntry = r.readChangeRecord()) != null) {
LOG.debug(" ...readEntry");
LOG.debug("{}", ToStringBuilder.reflectionToString(readEntry, ToStringStyle.MULTI_LINE_STYLE));
entryCount++;
readEntry.processChange(server);
}
LOG.info(" # of entries loaded: {}", entryCount);
} finally {
if (resourceAsStream != null) {
resourceAsStream.close();
}
}
}
LOG.info("----------------------------------------------------------");
LOG.info(" # of LDIF files loaded: {}", ldifLoadCount);
LOG.info(" Post LDIF load server entry count: {}", server.countEntries());
LOG.info("<<<loadLdifFiles()");
}
示例6: validateLdifFile
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
public ResultCode validateLdifFile(InputStream is, String dn) throws LDAPException {
ResultCode result = ResultCode.UNAVAILABLE;
try {
LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
LDIFReader validateLdifReader = new LDIFReader(is);
result = ldifDataUtility.validateLDIF(validateLdifReader, dn);
validateLdifReader.close();
} catch (Exception ex) {
log.error("Failed to validate ldif file: ", ex);
}
return result;
}
示例7: importLdifFile
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
/**
* Performs ldif file import
*
* @param connection
* Connection to LDAP server
* @param ldifFileName
* LDIF file
* @return The result code for the processing that was performed
*/
public ResultCode importLdifFile(LDAPConnection connection, String ldifFileName) {
LDIFReader ldifReader = createLdifReader(ldifFileName);
if (ldifReader == null) {
return ResultCode.LOCAL_ERROR;
}
try {
return importLdifFile(connection, ldifReader);
} finally {
disposeLdifReader(ldifReader);
}
}
示例8: disposeLdifReader
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
private void disposeLdifReader(LDIFReader ldifReader) {
if (ldifReader != null) {
try {
ldifReader.close();
} catch (IOException ex) {
}
}
}
示例9: validateLDIF
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
public ResultCode validateLDIF(LDIFReader ldifReader, String dn) {
String baseDn = dn.toLowerCase();
ResultCode resultCode = ResultCode.SUCCESS;
while (true) {
// Read the next change to process
LDIFChangeRecord ldifRecord = null;
try {
ldifRecord = ldifReader.readChangeRecord(true);
if (ldifRecord != null) {
if (StringHelper.isNotEmpty(baseDn)) {
if (!ldifRecord.getDN().toLowerCase().endsWith(baseDn)) {
resultCode = ResultCode.NOT_SUPPORTED;
break;
}
}
}
} catch (LDIFException le) {
log.info("Malformed ldif record " + ldifRecord);
log.error("Malformed ldif record", le);
resultCode = ResultCode.DECODING_ERROR;
break;
} catch (IOException ioe) {
log.error("I/O error encountered while reading a change record", ioe);
resultCode = ResultCode.LOCAL_ERROR;
break;
}
// If the change record was null, then it means there are no more
// changes to be processed.
if (ldifRecord == null) {
break;
}
}
return resultCode;
}
示例10: EmbeddedDirectoryServer
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
private EmbeddedDirectoryServer(@NotNull String dn, @NotNull URL ldifStream) throws Exception {
baseDn = new DN(dn);
final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(dn);
server = new InMemoryDirectoryServer(config);
try (InputStream in = ldifStream.openStream()) {
server.importFromLDIF(false, new LDIFReader(in));
}
server.startListening();
}
示例11: loadLdifFiles
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
protected void loadLdifFiles() throws Exception {
Iterable<String> ldifResources = ldifResources();
for (String ldif : ldifResources) {
InputStream ldifStream = new FileInputStream(ldif);
try {
LDIFReader r = new LDIFReader(ldifStream);
LDIFChangeRecord readEntry;
while ((readEntry = r.readChangeRecord()) != null) {
readEntry.processChange(server);
}
} finally {
ldifStream.close();
}
}
}
示例12: createInMemoryLdapServer
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
@BeforeClass
public static void createInMemoryLdapServer() throws Exception {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=MyDomain");
config.addAdditionalBindCredentials("cn=Directory Manager", "password");
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", ldapPort));
config.setSchema(null);
InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
ds.importFromLDIF(true, new LDIFReader(LdapUserServiceTest.class.getResourceAsStream("resources/ldapUserServiceSampleData.ldif")));
ds.startListening();
}
示例13: loadLdifs
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
private void loadLdifs(InMemoryDirectoryServer ds) {
try {
for (InputStream ldif : _ldifs) {
LDIFReader ldifReader = new LDIFReader(ldif);
ds.importFromLDIF(CLEAR_BEFORE_LDIF_IMPORT, ldifReader);
}
} catch (LDAPException e) {
throw propagate(e);
}
}
示例14: addEntries
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
/**
* Attempts to add a set of entries provided in LDIF form in which each
* element of the provided array is a line of the LDIF representation, with
* empty strings as separators between entries (as you would have for blank
* lines in an LDIF file). If a problem is encountered while attempting to
* add any of the provided entries, then the server will remain populated with
* the data it held before this method was called.
* <BR><BR>
* This method may be used regardless of whether the server is listening for
* client connections, and regardless of whether add operations are allowed in
* the server.
*
* @param ldifEntryLines The lines comprising the LDIF representation of the
* entries to be added.
*
* @throws LDAPException If a problem is encountered while attempting to add
* any of the provided entries.
*/
public void addEntries(final String... ldifEntryLines)
throws LDAPException
{
final ByteStringBuffer buffer = new ByteStringBuffer();
for (final String line : ldifEntryLines)
{
buffer.append(line);
buffer.append(StaticUtils.EOL_BYTES);
}
final ArrayList<Entry> entryList = new ArrayList<Entry>(10);
final LDIFReader reader = new LDIFReader(buffer.asInputStream());
while (true)
{
try
{
final Entry entry = reader.readEntry();
if (entry == null)
{
break;
}
else
{
entryList.add(entry);
}
}
catch (final Exception e)
{
Debug.debugException(e);
throw new LDAPException(ResultCode.PARAM_ERROR,
ERR_MEM_DS_ADD_ENTRIES_LDIF_PARSE_EXCEPTION.get(
StaticUtils.getExceptionMessage(e)),
e);
}
}
addEntries(entryList);
}
示例15: reset
import com.unboundid.ldif.LDIFReader; //导入依赖的package包/类
public void reset() throws LDAPException, IOException {
logger.warn("Resetting embedded LDAP");
InputStream ldifStream = getClass().getResourceAsStream("/testuser.ldif");
dirServer.importFromLDIF(true, new LDIFReader(ldifStream));
}