如何在 ApacheDS 1.5.5 上实现自定义分区?

发布于 2024-11-04 16:51:12 字数 344 浏览 1 评论 0原文

我正在 Apache DS 上实现自定义分区(实现 org.apache.directory.server.core.partition.Partition)。

我可以在我的自定义分区上进行搜索,但是如果我想使用过滤器(即 objectClass=”person”),我的分区将返回找到的所有条目,根本不进行任何过滤。

谁能举例说明如何使用自定义分区过滤“搜索”方法返回的条目?

另外,如果有人能指出我完成搜索方法实现的示例,我将不胜感激。我需要更多信息,特别是有关搜索范围(OBJECT、ONELEVEL 或 SUBTREE)的信息。

我使用的是 ApacheDS 1.5.5 版本。

多谢!

I'm implementing a custom partition on Apache DS (implementing org.apache.directory.server.core.partition.Partition).

I´m able to do searches on my custom partition, however if I want to use a filter (i.e. objectClass=”person”) my partition returns all the entries found, with no filtering at all.

Can anyone give an example of how to filter the entries returned by the "search" method using a custom partition?

Also, it would be highly appreciated if someone can point me to complete examples of implementing the search method. I need more information, specially regarding Search Scopes (OBJECT, ONELEVEL or SUBTREE).

I'm using version 1.5.5 of ApacheDS.

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狂之美人 2024-11-11 16:51:12

目录是一棵树。当您在目录中使用 LDAP 进行搜索(编写搜索协议数据单元)时,您给出:

  1. 开始搜索的节点的 DN
  2. 您想要检索的属性
  3. 过滤器 ((&(objectClass=*))
  4. 您的深度搜索

对于深度,您有 3 种可能性

  • 子树:尝试从起始节点开始递归搜索来匹配过滤器
  • OneLevel:尝试仅在起始节点下的节点中匹配过滤器
  • 基础:尝试将过滤器与 。 nod 属性(用于获取 RootDSE 属性),

请注意 SCHEMA 中定义的类型的实现都是从 top 类型派生的。如果我以 inetOrgPerson 类型为例,您可以在 SCHEMA 中看到该类型是 organizationalPerson 的子级,而 organizationalPersonperson 的子级。 code>,它是 top 的子级,在这种特殊情况下,inetOrgPerson 对象的 objectClass 属性值将是 4 倍:

objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson

因此,如果您使用 (&(objectClass=person)) 等过滤器编写搜索 PDU,您将获得从 personorganizationalPersoninetOrPerson 类型发出的对象在你的结果中。

某些搜索工具中的另一件事是,如果过滤器写得不好或不理解,则使用默认过滤器 ((&(objectClass=*)) (这意味着一切)。

A Directory is a tree. When you search (write a SEARCH Protocol Data Unit) with LDAP in a Directory you give :

  1. The DN of the nod where begin the search
  2. The attributes you want to retreive
  3. The filter ((&(objectClass=*))
  4. The deepness of your search

For the deepness you've got 3 possibilities

  • Subtree : try to match the filter in a recursive search from the begining nod.
  • OneLevel : try to match the filter only in the nods under the begining nod.
  • base : try to match the filter with the nod attributes (used to get RootDSE attributes).

If I come back to your problem. Be careful to the fact that there are implementation of type defined in the SCHEMA. Types are all derived from the type top. If I take as an example the type inetOrgPerson you can see in the SCHEMA that this type is a child of organizationalPerson, which is a chil of person, which is a chil of top. In this particular case an inetOrgPerson object will have his objectClass attribute valued 4 times :

objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson

So if you write a search PDU with a filter like (&(objectClass=person)) you will have objects issued from person, organizationalPerson and inetOrPerson types in your result.

Another thing in some search tools if the filter is bad written or not understood the default filter ((&(objectClass=*)) is used (this means everything).

佞臣 2024-11-11 16:51:12

我前一段时间就开始工作了,但没有时间发布解决方案。

基于此页面的示例: 如何为 apache ds 编写一个简单的自定义分区。

我能够构建初始分区。然而,这对我的情况没有用。如果 ApacheDS 有更好的文档那就太好了。

因此,对于过滤,我收到了来自 Apache 开发人员列表的一封电子邮件,基本上解释说根本没有任何类可以帮助您,您必须自己完成(如果我错了,请纠正我,因为我有兴趣改进我的代码很快)。

例如,您获得了过滤器 (objectClass=person),那么您应该执行如下操作:

if(ctx.getFilter().toString().contains("objectClass=person")) {
  //Somehow return entries that only correspond to persons on the data base (were you store your directory entries).
}

实际上,请注意上面的代码示例将不起作用,因为 ApacheDS 将属性名称转换为其相应的 OID。因此,我们将得到 2.5.6,而不是“objectClass”,它是“objectClass”属性的 OID。

现在关于搜索范围,JPBlanc 的答案已经说了很多,所以我不再重复他所说的。在您的自定义分区上,您将需要编写代码来以不同的方式处理树情况。

例如:

switch (ctx.getScope()) {

  case OBJECT:
    //Find a particular entry on your entry database.
  case ONELEVEL:
    //Find all entries that match directly below a given entry.
  case SUBTREE:
    //Find all entries that match recursively below a given entry.

问候。

I got this working some time ago but had no time to post the solution.

Based on the example of this page: How to write a simple custom partition for apache ds.

I was able to build the initial partition. This however was not useful to my case. It would be great if ApacheDS had a nicer documentation.

So for filtering, I got an email from the Apache Developers List basically explaining that there are no classes to help you at all, you must do it your self (please correct me if I'm wrong since I'm interested on improving my code soon).

For example, you got the filter (objectClass=person) then you should do something like this:

if(ctx.getFilter().toString().contains("objectClass=person")) {
  //Somehow return entries that only correspond to persons on the data base (were you store your directory entries).
}

Actually, notice that the code example from above won't work, since ApacheDS translates the attribute names to their corresponding OID. So, instead of "objectClass" we would get 2.5.6, which is the OID for "objectClass" attribute.

Now regarding search scopes, the answer from JPBlanc says pretty much about it so I'm not repeating what he said. On your custom partition you will need to write your code to handle the tree cases differently.

For example:

switch (ctx.getScope()) {

  case OBJECT:
    //Find a particular entry on your entry database.
  case ONELEVEL:
    //Find all entries that match directly below a given entry.
  case SUBTREE:
    //Find all entries that match recursively below a given entry.

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文