当前位置: 首页>>代码示例>>Java>>正文


Java LdifReader类代码示例

本文整理汇总了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()));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:MiniKdc.java

示例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()));
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:23,代码来源:MiniKdc.java

示例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;
    }
 
开发者ID:petalmd,项目名称:armor,代码行数:17,代码来源:EmbeddedLDAPServer.java

示例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()));
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:TestLDAPAuthentication.java

示例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();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:LdapServer.java

示例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
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:17,代码来源:LdapServer.java

示例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;
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:26,代码来源:LdapService.java

示例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);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:21,代码来源:LdapRoleMappingG2UTestCase.java

示例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);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:21,代码来源:LdapRoleMappingU2GTestCase.java

示例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);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:22,代码来源:OutboundLdapConnectionTestCase.java

示例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()));
  }
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:32,代码来源:MiniKdc.java

示例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();
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:35,代码来源:LdifUtilsTest.java

示例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();
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:40,代码来源:LdifUtilsTest.java

示例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 );
            }
        }
    }
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:33,代码来源:SingleLdifSchemaLoader.java

示例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;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:36,代码来源:JarLdifSchemaLoader.java


注:本文中的org.apache.directory.api.ldap.model.ldif.LdifReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。