use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class OpenLdapSchemaParserTest method testComplexAttributeTypeParse.
@Test
public void testComplexAttributeTypeParse() throws Exception {
String attributeTypeData = "# adding a comment \n" + "attributetype ( 2.5.4.2 NAME ( 'knowledgeInformation' 'asdf' ) \n" + " DESC 'RFC2256: knowledge information'\n" + " EQUALITY caseIgnoreMatch\n" + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
parser.parse(attributeTypeData);
List<MutableAttributeType> attributeTypeList = parser.getAttributeTypes();
Map<String, AttributeType> attributeTypes = mapAttributeTypes(attributeTypeList);
AttributeType type = attributeTypes.get("2.5.4.2");
assertNotNull(type);
assertEquals("2.5.4.2", type.getOid());
assertEquals("knowledgeInformation", type.getName());
assertEquals("RFC2256: knowledge information", type.getDescription());
assertEquals("1.3.6.1.4.1.1466.115.121.1.15", type.getSyntaxOid());
assertEquals(32768, type.getSyntaxLength());
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class OpenLdapSchemaParserTest method testSimpleAttributeTypeParse.
@Test
public void testSimpleAttributeTypeParse() throws Exception {
String attributeTypeData = "# adding a comment \n" + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n" + " DESC 'RFC2256: knowledge information'\n" + " EQUALITY caseIgnoreMatch\n" + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
parser.parse(attributeTypeData);
List<MutableAttributeType> attributeTypeList = parser.getAttributeTypes();
Map<String, AttributeType> attributeTypes = mapAttributeTypes(attributeTypeList);
AttributeType type = attributeTypes.get("2.5.4.2");
assertNotNull(type);
assertEquals("2.5.4.2", type.getOid());
assertEquals("knowledgeInformation", type.getName());
assertEquals("RFC2256: knowledge information", type.getDescription());
assertEquals("1.3.6.1.4.1.1466.115.121.1.15", type.getSyntaxOid());
assertEquals(32768, type.getSyntaxLength());
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class OpenLdapSchemaParserTest method testAttributeTypeParseWithSpaceDesc.
/**
* Test that we can handle a DESC which contains only spaces
*/
@Test
public void testAttributeTypeParseWithSpaceDesc() throws Exception {
String attributeTypeData = "# adding a comment \n" + "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n" + " DESC ' '\n" + " EQUALITY caseIgnoreMatch\n" + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
parser.parse(attributeTypeData);
List<MutableAttributeType> attributeTypeList = parser.getAttributeTypes();
Map<String, AttributeType> attributeTypes = mapAttributeTypes(attributeTypeList);
AttributeType type = attributeTypes.get("2.5.4.2");
assertNotNull(type);
assertEquals("2.5.4.2", type.getOid());
assertEquals("knowledgeInformation", type.getName());
assertEquals(" ", type.getDescription());
assertEquals("1.3.6.1.4.1.1466.115.121.1.15", type.getSyntaxOid());
assertEquals(32768, type.getSyntaxLength());
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class LdapNetworkConnection method addSchema.
/**
* parses the given schema file present in OpenLDAP schema format
* and adds all the SchemaObjects present in it to the SchemaManager
*
* @param schemaFile the schema file in OpenLDAP schema format
* @throws LdapException in case of any errors while parsing
*/
public void addSchema(File schemaFile) throws LdapException {
try {
if (schemaManager == null) {
loadSchema();
}
if (schemaManager == null) {
throw new LdapException("Cannot load the schema");
}
OpenLdapSchemaParser olsp = new OpenLdapSchemaParser();
olsp.setQuirksMode(true);
olsp.parse(schemaFile);
Registries registries = schemaManager.getRegistries();
List<Throwable> errors = new ArrayList<>();
for (AttributeType atType : olsp.getAttributeTypes()) {
registries.buildReference(errors, atType);
registries.getAttributeTypeRegistry().register(atType);
}
for (ObjectClass oc : olsp.getObjectClassTypes()) {
registries.buildReference(errors, oc);
registries.getObjectClassRegistry().register(oc);
}
LOG.info("successfully loaded the schema from file {}", schemaFile.getAbsolutePath());
} catch (Exception e) {
LOG.error(I18n.err(I18n.ERR_03206_FAIL_LOAD_SCHEMA_FILE, schemaFile.getAbsolutePath()));
throw new LdapException(e);
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class LdifAnonymizer method anonymizeChangeAdd.
/**
* Anonymize a Add change
*/
private LdifEntry anonymizeChangeAdd(LdifEntry ldifEntry) throws LdapException {
Dn entryDn = ldifEntry.getDn();
LdifEntry newLdifEntry = new LdifEntry(schemaManager);
newLdifEntry.setChangeType(ChangeType.Add);
// Process the DN first
Dn anonymizedDn = anonymizeDn(entryDn);
newLdifEntry.setDn(anonymizedDn);
// Now, process the entry's attributes
for (Attribute attribute : ldifEntry) {
AttributeType attributeType = attribute.getAttributeType();
Attribute anonymizedAttribute = new DefaultAttribute(attributeType);
if (attributeType.getSyntax().getSyntaxChecker() instanceof DnSyntaxChecker) {
for (Value dnValue : attribute) {
Dn dn = new Dn(schemaManager, dnValue.getValue());
Dn newdDn = anonymizeDn(dn);
anonymizedAttribute.add(newdDn.toString());
}
newLdifEntry.addAttribute(attribute);
} else {
Anonymizer anonymizer = attributeAnonymizers.get(attribute.getAttributeType().getOid());
if (anonymizer == null) {
newLdifEntry.addAttribute(attribute);
} else {
anonymizedAttribute = anonymizer.anonymize(valueMap, valueSet, attribute);
if (anonymizedAttribute != null) {
newLdifEntry.addAttribute(anonymizedAttribute);
}
}
}
}
return newLdifEntry;
}
Aggregations