Search in sources :

Example 91 with AttributeType

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());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 92 with AttributeType

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());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 93 with AttributeType

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());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 94 with AttributeType

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);
    }
}
Also used : OpenLdapSchemaParser(org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ArrayList(java.util.ArrayList) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 95 with AttributeType

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;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) TelephoneNumberAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.TelephoneNumberAnonymizer) StringAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.StringAnonymizer) BinaryAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.BinaryAnonymizer) IntegerAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.IntegerAnonymizer) CaseSensitiveStringAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.CaseSensitiveStringAnonymizer) Anonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer) Value(org.apache.directory.api.ldap.model.entry.Value) Dn(org.apache.directory.api.ldap.model.name.Dn) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DnSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.DnSyntaxChecker) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Aggregations

AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)135 Test (org.junit.Test)68 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)42 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)25 ParseException (java.text.ParseException)15 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)15 Value (org.apache.directory.api.ldap.model.entry.Value)15 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)11 HashSet (java.util.HashSet)10 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)10 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)10 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)9 IOException (java.io.IOException)7 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)7 Before (org.junit.Before)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)6 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)6 ArrayList (java.util.ArrayList)5 Dn (org.apache.directory.api.ldap.model.name.Dn)4