Java Code Examples for org.apache.directory.api.ldap.model.ldif.LdifEntry#getEntry()
The following examples show how to use
org.apache.directory.api.ldap.model.ldif.LdifEntry#getEntry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemorySchemaPartition.java From bouncr with Eclipse Public License 1.0 | 5 votes |
/** * Partition initialization - loads schema entries from the files on classpath. * * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override protected void doInit() throws InvalidNameException, Exception { if (initialized) return; LOG.debug("Initializing schema partition " + getId()); suffixDn.apply(schemaManager); super.doInit(); // load schema final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet<>(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); LdifReader reader = new LdifReader(resource.openStream()); LdifEntry ldifEntry = reader.next(); reader.close(); Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); // add mandatory attributes if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); } if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); } AddOperationContext addContext = new AddOperationContext(null, entry); super.add(addContext); } } }
Example 2
Source File: InMemorySchemaPartition.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Partition initialization - loads schema entries from the files on classpath. * * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override protected void doInit() throws InvalidNameException, Exception { if (initialized) { return; } LOG.debug("Initializing schema partition " + getId()); suffixDn.apply(schemaManager); super.doInit(); // load schema final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet<>(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); LdifEntry ldifEntry; try (LdifReader reader = new LdifReader(resource.openStream())) { ldifEntry = reader.next(); } Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); // add mandatory attributes if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); } if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); } AddOperationContext addContext = new AddOperationContext(null, entry); super.add(addContext); } } }
Example 3
Source File: InMemorySchemaPartition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Partition initialization - loads schema entries from the files on classpath. * * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override protected void doInit() throws Exception { if (initialized) return; LOG.debug("Initializing schema partition " + getId()); suffixDn.apply(schemaManager); super.doInit(); // load schema final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet<String>(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); LdifReader reader = new LdifReader(resource.openStream()); LdifEntry ldifEntry = reader.next(); reader.close(); Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); // add mandatory attributes if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); } if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); } AddOperationContext addContext = new AddOperationContext(null, entry); super.add(addContext); } } }
Example 4
Source File: InMemorySchemaPartition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Partition initialization - loads schema entries from the files on classpath. * * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override protected void doInit() throws Exception { if (initialized) return; LOG.debug("Initializing schema partition " + getId()); suffixDn.apply(schemaManager); super.doInit(); // load schema final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet<String>(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); LdifReader reader = new LdifReader(resource.openStream()); LdifEntry ldifEntry = reader.next(); reader.close(); Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); // add mandatory attributes if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); } if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); } AddOperationContext addContext = new AddOperationContext(null, entry); super.add(addContext); } } }
Example 5
Source File: InMemorySchemaPartition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Partition initialization - loads schema entries from the files on classpath. * * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override protected void doInit() throws Exception { if (initialized) return; LOG.debug("Initializing schema partition " + getId()); suffixDn.apply(schemaManager); super.doInit(); // load schema final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet<String>(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); LdifReader reader = new LdifReader(resource.openStream()); LdifEntry ldifEntry = reader.next(); reader.close(); Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); // add mandatory attributes if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); } if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); } AddOperationContext addContext = new AddOperationContext(null, entry); super.add(addContext); } } }
Example 6
Source File: InMemorySchemaPartition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Partition initialization - loads schema entries from the files on classpath. * * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit() */ @Override protected void doInit() throws Exception { if (initialized) return; LOG.debugf("Initializing schema partition %s", getId()); suffixDn.apply(schemaManager); super.doInit(); // load schema final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*")); for (String resourcePath : new TreeSet<String>(resMap.keySet())) { if (resourcePath.endsWith(".ldif")) { URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file"); LdifReader reader = new LdifReader(resource.openStream()); LdifEntry ldifEntry = reader.next(); reader.close(); Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry()); // add mandatory attributes if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) { entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()); } if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) { entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString()); } AddOperationContext addContext = new AddOperationContext(null, entry); super.add(addContext); } } }
Example 7
Source File: LdifAnonymizerTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
@Test public void testLdifAnonymizer2() throws Exception { String ldif = "dn: cn=cn2 + sn=elecharny, dc=example, dc=com\n" + "ObjectClass: top\n" + "objectClass: person\n" + "cn: cn1\n" + "cn: cn2\n" + "cn: cn3\n" + "sn: elecharny\n" + "givenname: test\n"; LdifAnonymizer anonymizer = new LdifAnonymizer( schemaManager ); anonymizer.addNamingContext( "dc=example,dc=com" ); String result = anonymizer.anonymize( ldif ); List<LdifEntry> entries = ldifReader.parseLdif( result ); assertEquals( 1, entries.size() ); // Check the entry LdifEntry ldifEntry = entries.get( 0 ); assertTrue( ldifEntry.isEntry() ); Entry entry = ldifEntry.getEntry(); assertEquals( 4, entry.size() ); // Here, we expect cn2 to be translated to AAA, because it was encountered in teh DN first assertEquals( "cn=AAA+sn=AAAAAAAAA,dc=example,dc=com", entry.getDn().toString() ); Attribute cn = entry.get( "cn" ); assertEquals( 3, cn.size() ); assertTrue( cn.contains( "AAA", "AAB", "AAC" ) ); Attribute sn = entry.get( "sn" ); assertEquals( "AAAAAAAAA", sn.getString() ); Attribute givenname = entry.get( "givenname" ); assertEquals( "AAAA", givenname.getString() ); }
Example 8
Source File: LdifAnonymizerTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
@Test public void testLdifAnonymizer3() throws Exception { String ldif = "dn: cn=cn2 + sn=elecharny, dc=example, dc=com\n" + "ObjectClass: top\n" + "objectClass: person\n" + "cn: cn1\n" + "cn: cn2\n" + "cn: cn3\n" + "userPassword: test\n" + "userPassword: tesu\n" + "sn: elecharny\n" + "givenname: test\n"; LdifAnonymizer anonymizer = new LdifAnonymizer( schemaManager ); anonymizer.addNamingContext( "dc=example,dc=com" ); String result = anonymizer.anonymize( ldif ); List<LdifEntry> entries = ldifReader.parseLdif( result ); assertEquals( 1, entries.size() ); // Check the entry LdifEntry ldifEntry = entries.get( 0 ); assertTrue( ldifEntry.isEntry() ); Entry entry = ldifEntry.getEntry(); assertEquals( 5, entry.size() ); // Here, we expect cn2 to be translated to AAA, because it was encountered in teh DN first assertEquals( "cn=AAA+sn=AAAAAAAAA,dc=example,dc=com", entry.getDn().toString() ); Attribute cn = entry.get( "cn" ); assertEquals( 3, cn.size() ); assertTrue( cn.contains( "AAA", "AAB", "AAC" ) ); Attribute sn = entry.get( "sn" ); assertEquals( "AAAAAAAAA", sn.getString() ); Attribute givenname = entry.get( "givenname" ); assertEquals( "AAAA", givenname.getString() ); Attribute userPassword = entry.get( "userPassword" ); assertEquals( 2, userPassword.size() ); assertTrue( userPassword.contains( Strings.getBytesUtf8( "AAAA" ) ) ); assertTrue( userPassword.contains( Strings.getBytesUtf8( "AAAB" ) ) ); }