use of org.structr.ldap.entity.LDAPNode 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.structr.ldap.entity.LDAPNode in project structr by structr.
the class StructrLDAPWrapper method find.
private LDAPNode find(final Dn dn) throws FrameworkException, LdapException, LdapInvalidDnException {
final List<Rdn> rdns = new LinkedList<>(dn.getRdns());
Collections.reverse(rdns);
LDAPNode current = getRoot();
for (final Rdn rdn : rdns) {
if (!rdn.isSchemaAware()) {
rdn.apply(schemaManager);
}
current = current.getChild(rdn.getNormName());
// break early to avoid NPE
if (current == null) {
return null;
}
}
return current;
}
use of org.structr.ldap.entity.LDAPNode in project structr by structr.
the class StructrLDAPWrapper method getRoot.
private LDAPNode getRoot() throws FrameworkException {
final Class type = StructrApp.getConfiguration().getNodeEntityClass("LDAPNode");
final App app = app();
LDAPNode root = (LDAPNode) app.nodeQuery(type).andName(partitionId).getFirst();
if (root == null) {
root = app.create(type, new NodeAttribute<>(StructrApp.key(LDAPNode.class, "name"), partitionId), new NodeAttribute<>(StructrApp.key(LDAPNode.class, "isRoot"), true));
}
return root;
}
use of org.structr.ldap.entity.LDAPNode in project structr by structr.
the class StructrLDAPWrapper method filter.
private List<Entry> filter(final LDAPNode node, final ExprNode filter, final SearchScope scope, final int depth) throws FrameworkException, LdapException {
final boolean base = SearchScope.OBJECT.equals(scope);
final boolean oneLevel = SearchScope.ONELEVEL.equals(scope);
final boolean subtree = SearchScope.SUBTREE.equals(scope);
final List<Entry> list = new LinkedList<>();
if (base || !(depth == 0 && oneLevel)) {
if (matches(node, filter)) {
list.add(getEntry(node));
}
}
if (!base && (subtree || (depth == 0 && oneLevel))) {
// recurse
for (final LDAPNode child : node.getChildren()) {
list.addAll(filter(child, filter, scope, depth + 1));
}
}
return list;
}
use of org.structr.ldap.entity.LDAPNode in project structr by structr.
the class StructrLDAPWrapper method delete.
public void delete(final Dn dn) throws LdapException {
final App app = app();
try (final Tx tx = app.tx()) {
final LDAPNode entry = find(dn);
if (entry != null) {
entry.delete();
}
tx.success();
} catch (FrameworkException fex) {
handleException(fex);
}
}
Aggregations