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());
}
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());
}
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");
}
}
}
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);
}
}
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;
}
Aggregations