本文整理汇总了Java中org.apache.directory.api.ldap.model.ldif.LdifReader类的典型用法代码示例。如果您正苦于以下问题:Java LdifReader类的具体用法?Java LdifReader怎么用?Java LdifReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LdifReader类属于org.apache.directory.api.ldap.model.ldif包,在下文中一共展示了LdifReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPrincipal
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
/**
* Creates a principal in the KDC with the specified user and password.
*
* @param principal principal name, do not include the domain.
* @param password password.
* @throws Exception thrown if the principal could not be created.
*/
public synchronized void createPrincipal(String principal, String password)
throws Exception {
String orgName= conf.getProperty(ORG_NAME);
String orgDomain = conf.getProperty(ORG_DOMAIN);
String baseDn = "ou=users,dc=" + orgName.toLowerCase(Locale.ENGLISH)
+ ",dc=" + orgDomain.toLowerCase(Locale.ENGLISH);
String content = "dn: uid=" + principal + "," + baseDn + "\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"objectClass: inetOrgPerson\n" +
"objectClass: krb5principal\n" +
"objectClass: krb5kdcentry\n" +
"cn: " + principal + "\n" +
"sn: " + principal + "\n" +
"uid: " + principal + "\n" +
"userPassword: " + password + "\n" +
"krb5PrincipalName: " + principal + "@" + getRealm() + "\n" +
"krb5KeyVersionNumber: 0";
for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) {
ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(),
ldifEntry.getEntry()));
}
}
示例2: createPrincipal
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
/**
* Creates a principal in the KDC with the specified user and password.
*
* @param principal principal name, do not include the domain.
* @param password password.
* @throws Exception thrown if the principal could not be created.
*/
public synchronized void createPrincipal(String principal, String password) throws Exception {
String orgName = conf.getProperty(ORG_NAME);
String orgDomain = conf.getProperty(ORG_DOMAIN);
String baseDn = "ou=users,dc=" + orgName.toLowerCase(Locale.ENGLISH) + ",dc="
+ orgDomain.toLowerCase(Locale.ENGLISH);
String content = "dn: uid=" + principal + "," + baseDn + "\n" + "objectClass: top\n" + "objectClass: person\n"
+ "objectClass: inetOrgPerson\n" + "objectClass: krb5principal\n" + "objectClass: krb5kdcentry\n"
+ "cn: " + principal + "\n" + "sn: " + principal + "\n" + "uid: " + principal + "\n" + "userPassword: "
+ password + "\n" + "krb5PrincipalName: " + principal + "@" + getRealm() + "\n"
+ "krb5KeyVersionNumber: 0";
for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) {
ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(), ldifEntry.getEntry()));
}
}
示例3: applyLdif
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
public int applyLdif(final File ldifFile) throws Exception {
final File newLdif = new File("target/tmp/" + ldifFile.getName());
String ldif = FileUtils.readFileToString(ldifFile);
ldif = ldif.replace("${hostname}", AbstractUnitTest.getNonLocalhostAddress());
FileUtils.write(newLdif, ldif);
int i = 0;
for (final LdifEntry ldifEntry : new LdifReader(newLdif)) {
directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
log.trace(ldifEntry.toString());
i++;
}
return i;
}
示例4: createPrincipal
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
private void createPrincipal(String principal, String password)
throws Exception {
DirectoryService ds = getService();
String baseDn = "ou=users,ou=system";
String content = "dn: uid=" + principal + "," + baseDn + "\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"objectClass: inetOrgPerson\n" +
"cn: " + principal + "\n" +
"sn: " + principal + "\n" +
"uid: " + principal + "\n" +
"userPassword: " + password;
for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) {
ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(),
ldifEntry.getEntry()));
}
}
示例5: LdapServer
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
/**
* Create a single LDAP server.
*
* @param ldifFile
* @throws Exception
*/
public LdapServer(String ldifFile) throws Exception {
InMemoryDirectoryServiceFactory dsFactory = new InMemoryDirectoryServiceFactory();
dsFactory.init("ds");
directoryService = dsFactory.getDirectoryService();
final SchemaManager schemaManager = directoryService.getSchemaManager();
importLdif(directoryService, schemaManager, new LdifReader(ldifFile));
ldapServer = new org.apache.directory.server.ldap.LdapServer();
ldapServer.setTransports(new TcpTransport("127.0.0.1", 1024));
ldapServer.setDirectoryService(directoryService);
ldapServer.start();
}
示例6: importLdif
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
private void importLdif(DirectoryService directoryService,
final SchemaManager schemaManager,
LdifReader ldifReader) throws Exception {
try {
for (LdifEntry ldifEntry : ldifReader) {
checkPartition(ldifEntry);
directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
} finally {
try {
ldifReader.close();
} catch (IOException ioe) {
// ignore
}
}
}
示例7: importLdif
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
/**
* Import all of the entries from the provided LDIF stream.
*
* Note: The whole stream is read
*
* @param ldif - Stream containing the LDIF.
* @return This Builder for subsequent changes.
*/
public Builder importLdif(final InputStream ldif) throws Exception {
assertNotStarted();
if (directoryService == null) {
throw new IllegalStateException("The Directory service has not been created.");
}
CoreSession adminSession = directoryService.getAdminSession();
SchemaManager schemaManager = directoryService.getSchemaManager();
LdifReader ldifReader = new LdifReader(ldif);
for (LdifEntry ldifEntry : ldifReader) {
adminSession.add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
ldifReader.close();
ldif.close();
return this;
}
示例8: setUp
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
@BeforeClass
@CreateDS(
name = "WildFlyDS",
factory = org.jboss.as.test.integration.mgmt.access.ldap.InMemoryDirectoryServiceFactory.class,
partitions = @CreatePartition(name = "wildfly", suffix = "dc=wildfly,dc=org"),
allowAnonAccess = true
)
@CreateLdapServer(
transports = @CreateTransport(protocol = "LDAP", address = "localhost", port = 10389),
allowAnonymousAccess = true
)
public static void setUp() throws Exception {
directoryService = DSAnnotationProcessor.getDirectoryService();
SchemaManager schemaManager = directoryService.getSchemaManager();
InputStream ldif = LdapRoleMappingG2UTestCase.class.getResourceAsStream("/" + LdapRoleMappingG2UTestCase.class.getSimpleName() + ".ldif");
for (LdifEntry ldifEntry : new LdifReader(ldif)) {
directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
ldapServer = ServerAnnotationProcessor.getLdapServer(directoryService);
}
示例9: setUp
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
@BeforeClass
@CreateDS(
name = "WildFlyDS",
factory = org.jboss.as.test.integration.mgmt.access.ldap.InMemoryDirectoryServiceFactory.class,
partitions = @CreatePartition(name = "wildfly", suffix = "dc=wildfly,dc=org"),
allowAnonAccess = true
)
@CreateLdapServer(
transports = @CreateTransport(protocol = "LDAP", address = "localhost", port = 10389),
allowAnonymousAccess = true
)
public static void setUp() throws Exception {
directoryService = DSAnnotationProcessor.getDirectoryService();
SchemaManager schemaManager = directoryService.getSchemaManager();
InputStream ldif = LdapRoleMappingU2GTestCase.class.getResourceAsStream("/" + LdapRoleMappingU2GTestCase.class.getSimpleName() + ".ldif");
for (LdifEntry ldifEntry : new LdifReader(ldif)) {
directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
ldapServer = ServerAnnotationProcessor.getLdapServer(directoryService);
}
示例10: setUpLdap
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
@BeforeClass
@CreateDS(
name = "WildFlyDS",
factory = InMemoryDirectoryServiceFactory.class,
partitions = @CreatePartition(name = "wildfly", suffix = "dc=wildfly,dc=org"),
allowAnonAccess = true
)
@CreateLdapServer(
transports = @CreateTransport(protocol = "LDAP", address = "localhost", port = 10389),
allowAnonymousAccess = true
)
public static void setUpLdap() throws Exception {
directoryService = DSAnnotationProcessor.getDirectoryService();
final SchemaManager schemaManager = directoryService.getSchemaManager();
final InputStream ldif = OutboundLdapConnectionTestCase.class
.getResourceAsStream("/" + OutboundLdapConnectionTestCase.class.getSimpleName() + ".ldif");
for (LdifEntry ldifEntry : new LdifReader(ldif)) {
directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
ldapServer = ServerAnnotationProcessor.getLdapServer(directoryService);
}
示例11: createPrincipal
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
/**
* Creates a principal in the KDC with the specified user and password.
*
* @param principal principal name, do not include the domain.
* @param password password.
* @throws Exception thrown if the principal could not be created.
*/
public synchronized void createPrincipal(String principal, String password)
throws Exception {
String orgName= conf.getProperty(ORG_NAME);
String orgDomain = conf.getProperty(ORG_DOMAIN);
String baseDn = "ou=users,dc=" + orgName.toLowerCase() + ",dc=" +
orgDomain.toLowerCase();
String content = "dn: uid=" + principal + "," + baseDn + "\n" +
"objectClass: top\n" +
"objectClass: person\n" +
"objectClass: inetOrgPerson\n" +
"objectClass: krb5principal\n" +
"objectClass: krb5kdcentry\n" +
"cn: " + principal + "\n" +
"sn: " + principal + "\n" +
"uid: " + principal + "\n" +
"userPassword: " + password + "\n" +
"krb5PrincipalName: " + principal + "@" + getRealm() + "\n" +
"krb5KeyVersionNumber: 0";
for (LdifEntry ldifEntry : new LdifReader(new StringReader(content))) {
ds.getAdminSession().add(new DefaultEntry(ds.getSchemaManager(),
ldifEntry.getEntry()));
}
}
示例12: testConvertEntryNoControls
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
@Test
public void testConvertEntryNoControls() throws Exception
{
LdifReader reader = new LdifReader();
String expected =
"dn: ou=test\n" +
"ObjectClass: top\n" +
"ObjectClass: metaTop\n" +
"ObjectClass: metaSyntax\n" +
"m-oid: 1.2.3.4\n" +
"m-description: description\n\n";
List<LdifEntry> entries = reader.parseLdif( expected );
LdifEntry expectedEntry = entries.get( 0 );
LdifEntry entry = new LdifEntry();
entry.setDn( "ou=test" );
entry.addAttribute( "ObjectClass", "top", "metaTop", "metaSyntax" );
entry.addAttribute( "m-oid", "1.2.3.4" );
entry.addAttribute( "m-description", "description" );
String converted = LdifUtils.convertToLdif( entry );
assertNotNull( converted );
entries = reader.parseLdif( converted );
LdifEntry convertedEntry = entries.get( 0 );
assertEquals( expectedEntry, convertedEntry );
reader.close();
}
示例13: testConvertEntryOneControl
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
@Test
public void testConvertEntryOneControl() throws Exception
{
LdifReader reader = new LdifReader();
String expected =
"dn: ou=test\n" +
"control: 2.16.840.1.113730.3.4.2 false\n" +
"changetype: add\n" +
"ObjectClass: top\n" +
"ObjectClass: metaTop\n" +
"ObjectClass: metaSyntax\n" +
"m-oid: 1.2.3.4\n" +
"m-description: description\n\n";
List<LdifEntry> entries = reader.parseLdif( expected );
LdifEntry expectedEntry = entries.get( 0 );
LdifEntry entry = new LdifEntry();
entry.setDn( "ou=test" );
entry.addAttribute( "ObjectClass", "top", "metaTop", "metaSyntax" );
entry.addAttribute( "m-oid", "1.2.3.4" );
entry.addAttribute( "m-description", "description" );
ManageDsaITImpl control = new ManageDsaITImpl();
entry.addControl( control );
String converted = LdifUtils.convertToLdif( entry );
assertNotNull( converted );
entries = reader.parseLdif( converted );
LdifEntry convertedEntry = entries.get( 0 );
assertEquals( expectedEntry, convertedEntry );
reader.close();
}
示例14: initializeSchemas
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
/**
* Initialize the Schema object from a Single LDIF file
*/
private void initializeSchemas( InputStream in ) throws LdapException, IOException
{
try ( LdifReader ldifReader = new LdifReader( in ) )
{
Schema currentSchema = null;
while ( ldifReader.hasNext() )
{
LdifEntry ldifEntry = ldifReader.next();
String dn = ldifEntry.getDn().getName();
if ( SCHEMA_START_PATTERN.matcher( dn ).matches() )
{
Schema schema = getSchema( ldifEntry.getEntry() );
schemaMap.put( schema.getSchemaName(), schema );
currentSchema = schema;
}
else
{
if ( currentSchema == null )
{
throw new LdapException( "the first entry in the LDIF file is not a schema definition" );
}
loadSchemaObject( currentSchema.getSchemaName(), ldifEntry );
}
}
}
}
示例15: loadComparators
import org.apache.directory.api.ldap.model.ldif.LdifReader; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException
{
List<Entry> comparatorList = new ArrayList<>();
if ( schemas == null )
{
return comparatorList;
}
for ( Schema schema : schemas )
{
String start = getSchemaDirectoryString( schema )
+ SchemaConstants.COMPARATORS_PATH + "/" + "m-oid=";
String end = "." + LDIF_EXT;
for ( String resourcePath : RESOURCE_MAP.keySet() )
{
if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
{
URL resource = getResource( resourcePath, "comparator LDIF file" );
LdifReader reader = new LdifReader( resource.openStream() );
LdifEntry entry = reader.next();
reader.close();
comparatorList.add( entry.getEntry() );
}
}
}
return comparatorList;
}