Search in sources :

Example 66 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class OpenLdapSchemaParserTest method testDescWithSpaces.

@Test
public void testDescWithSpaces() throws Exception {
    String attributeTypeData = "attributetype ( 1.3.6.1.4.1.8104.1.1.37 NAME 'versionNumber'\n" + "        DESC 'versionNumber ' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch\n" + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE)";
    parser.parse(attributeTypeData);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    Map<String, AttributeType> mapAttributeTypes = mapAttributeTypes(attributeTypes);
    AttributeType attributeType = mapAttributeTypes.get("1.3.6.1.4.1.8104.1.1.37");
    assertNotNull(attributeType);
    assertEquals("1.3.6.1.4.1.8104.1.1.37", attributeType.getOid());
    assertEquals("versionNumber", attributeType.getName());
    assertEquals("versionNumber ", attributeType.getDescription());
    assertEquals("1.3.6.1.4.1.1466.115.121.1.15", attributeType.getSyntaxOid());
    assertTrue(attributeType.isSingleValued());
}
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 67 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class OpenLdapSchemaParserTest method testAttributeTypeParseWithDescQuotes.

@Test
public void testAttributeTypeParseWithDescQuotes() 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 68 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.

the class OpenLdapSchemaParserTest method testOpenLdapObjectIdentifiereMacros.

@Test
public void testOpenLdapObjectIdentifiereMacros() throws Exception {
    InputStream input = getClass().getResourceAsStream("dyngroup.schema");
    parser.parse(input);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
    Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
    assertEquals(2, attributeTypes.size());
    assertEquals(2, objectClassTypes.size());
    assertEquals(8, objectIdentifierMacros.size());
    // check that all macros are resolved
    for (OpenLdapObjectIdentifierMacro macro : objectIdentifierMacros.values()) {
        assertTrue(macro.isResolved());
        assertNotNull(macro.getResolvedOid());
        assertTrue(macro.getResolvedOid().matches("[0-9]+(\\.[0-9]+)+"));
    }
    // check that OIDs in attribute types and object classes are resolved
    for (ObjectClass objectClass : objectClassTypes) {
        List<String> asList = objectClass.getNames();
        if (asList.contains("groupOfURLs")) {
            assertEquals("2.16.840.1.113730.3.2.33", objectClass.getOid());
        } else if (asList.contains("dgIdentityAux")) {
            assertEquals("1.3.6.1.4.1.4203.666.11.8.2.1", objectClass.getOid());
        } else {
            fail("object class 'groupOfURLs' or 'dgIdentityAux' expected");
        }
    }
    for (AttributeType attributeType : attributeTypes) {
        List<String> asList = attributeType.getNames();
        if (asList.contains("memberURL")) {
            assertEquals("2.16.840.1.113730.3.1.198", attributeType.getOid());
        } else if (asList.contains("dgIdentity")) {
            assertEquals("1.3.6.1.4.1.4203.666.11.8.1.1", attributeType.getOid());
        } else {
            fail("attribute type 'memberURL' or 'dgIdentity' expected");
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) OpenLdapObjectIdentifierMacro(org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro) InputStream(java.io.InputStream) 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 69 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project structr by structr.

the class StructrLDAPWrapper method add.

public void add(final Entry entry) throws LdapException {
    try (final Tx tx = app().tx()) {
        // create while descending
        final Dn dn = entry.getDn();
        final LDAPNode parent = find(dn.getParent());
        if (parent != null) {
            final Attribute objectClasses = entry.get(schemaManager.getAttributeType(SchemaConstants.OBJECT_CLASS_AT_OID));
            final ObjectClassRegistry reg = schemaManager.getObjectClassRegistry();
            final Set<String> classes = new LinkedHashSet<>();
            final Rdn rdn = dn.getRdn();
            String mainClass = null;
            // make rdn schema aware
            if (!rdn.isSchemaAware()) {
                rdn.apply(schemaManager);
            }
            if (objectClasses != null) {
                for (final Value<?> value : objectClasses) {
                    final String cls = value.getString();
                    final String objectClassOid = reg.getOidByName(cls);
                    if (reg.get(objectClassOid).isStructural()) {
                        mainClass = cls;
                    } else {
                        classes.add(cls);
                    }
                }
                final LDAPNode newChild = parent.createChild(rdn.getNormName(), rdn.getName(), mainClass, classes);
                if (newChild != null) {
                    for (final Attribute attr : entry) {
                        AttributeType type = attr.getAttributeType();
                        String oid = null;
                        if (type != null) {
                            oid = type.getOid();
                        } else {
                            type = schemaManager.getAttributeType(attr.getUpId());
                            oid = type.getOid();
                        }
                        newChild.createAttribute(oid, attr.getUpId(), attr);
                    }
                } else {
                    logger.warn("Unable to add entry {}, could not create new instance", entry);
                }
            } else {
                logger.warn("Unable to add entry {}, could not determine object class(es)", entry);
            }
        } else {
            logger.warn("Unable to add entry {}, parent not found", entry);
        }
        tx.success();
    } catch (FrameworkException fex) {
        handleException(fex);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LDAPNode(org.structr.ldap.entity.LDAPNode) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) NodeAttribute(org.structr.core.graph.NodeAttribute) LDAPAttribute(org.structr.ldap.entity.LDAPAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ObjectClassRegistry(org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn)

Example 70 with AttributeType

use of org.apache.directory.api.ldap.model.schema.AttributeType in project structr by structr.

the class StructrLDAPWrapper method getAttribute.

public Attribute getAttribute(final LDAPAttribute src) throws LdapInvalidAttributeValueException {
    final AttributeType type = schemaManager.getAttributeType(src.getOid());
    final Attribute attribute = new DefaultAttribute(type);
    final String name = src.getUserProvidedId();
    if (name != null) {
        attribute.setUpId(name);
    }
    for (final LDAPValue value : src.getValues()) {
        attribute.add(value.getStringValue());
    }
    return attribute;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) NodeAttribute(org.structr.core.graph.NodeAttribute) LDAPAttribute(org.structr.ldap.entity.LDAPAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) LDAPValue(org.structr.ldap.entity.LDAPValue) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

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