Welcome Guest  |  Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | Help


Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 33
Posts: 33   Pages: 4   [ 1 2 3 4 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 4828 times and has 32 replies Next Thread
Male azevedo
Newbie




Joined: Nov 27, 2008
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Ldap SearchControls

Hi,

I have been playing around with the ldap datastore and it is very easy to use biggrin .
I would like to know if it is possible to LDAP SearchControls, I have noticied that when querying for an entry (with JPA or JDO) it goes one leaf down, but I need to serach the whole ldap tree
SearchControls.SUBTREE_SCOPE
for a specifique uid. Is this yet possible?

Thanks,

azevedo
[Dec 2, 2008 4:38:08 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male seelmann
Novice




Joined: Jul 2, 2008
Post Count: 36
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

Hi,

no, that is not possible yet. I'll investigate if it is easy to implement.

Regards,
Stefan
[Dec 2, 2008 10:03:18 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male seelmann
Novice




Joined: Jul 2, 2008
Post Count: 36
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

Right now the DN is just constructed using the attribute and value of the primary-key field as RDN and the value of the "dn" extension of the class as parent.

Here is what we need to do:
- Query/Search is easy to change, just add a SearchControl.
- For fetch, update and delete it is necessary to search for the entry first, but it's also easy to change.
- For insert I would suggest keep the current implementation. This means that new objects are created directly under the entry defined in the "dn" extension. Do you have another idea?

To make the the search scope configurable I would suggest to add an "searchScope" extension with possible values sub, one or base:
<class ...>
<extension vendor-name="datanucleus" key="dn" value="dc=example,dc=com" />
<extension vendor-name="datanucleus" key="searchScope" value="sub" />
...
</class>


Could you file an issue, please? I could finish the implementation tomorrow.
[Dec 3, 2008 12:51:05 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male andy
Expert
Member's Avatar

UK
Joined: Mar 13, 2004
Post Count: 5686
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

I have noticied that when querying for an entry (with JPA or JDO) it goes one leaf down, but I need to serach the whole ldap tree for a specifique uid. Is this yet possible?

When querying via
pm.getObjectById(id);

will obviously go through the whole database. The "id" is unique for a class, and so it searches for an instance of that class with the right key. The point here is not to add features that are specific to a datastore when there is a generic mechanism.

So why not provide an example of what you are doing? then we can understand it
----------------------------------------
-Andy smile

[Dec 3, 2008 9:24:10 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male azevedo
Newbie




Joined: Nov 27, 2008
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

Hi,

Do you want me to create it as an improvement or a new feature?

Thanks,

azevedo
[Dec 3, 2008 10:32:43 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male azevedo
Newbie




Joined: Nov 27, 2008
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

I have noticied that when querying for an entry (with JPA or JDO) it goes one leaf down, but I need to serach the whole ldap tree for a specifique uid. Is this yet possible?

When querying via
pm.getObjectById(id);

will obviously go through the whole database. The "id" is unique for a class, and so it searches for an instance of that class with the right key. The point here is not to add features that are specific to a datastore when there is a generic mechanism.

So why not provide an example of what you are doing? then we can understand it


Hi,

I will provide an example, before opening a issue

azevedo
[Dec 3, 2008 10:36:34 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male azevedo
Newbie




Joined: Nov 27, 2008
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

Hi,

Here an example,

I have the LDAP tree ass root DN o=umc, under that root dn I have a lot of o dns

-o=umc
+ o=Network
+ o=Services
+ o=Operators
- o=Users
- retailerName=default
+ou=AA
+ou=AI
-ou=AR
+unqiueID=azevedo
+ou=BA
.
.
.
etc.


So above you can see how the ldap tree is structred. Now I need to search for uniqueID azevedo on the tree.
Here the Person.java file


package lu.ept.dt.ldap;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

@PersistenceCapable(extensions={
@Extension(vendorName="DataNucleus", key="dn", value="retailerName=default,o=Users,o=UMC"),
@Extension(vendorName="DataNucleus", key="objectClass", value="top,person,umcSubscriber,organizationalPerson,inetOrgPerson,umcUser")})
public class Person {

@Persistent(primaryKey="true")
@Extension(vendorName="DataNucleus", key="dn", value="uniqueID")
private String uniqueID;

@Persistent
@Extension(vendorName="DataNucleus", key="dn", value="cn")
private String name;

@Persistent(name="userPassword")
@Extension(vendorName="DataNucleus", key="dn", value="userPassword")
private String password;

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getUniqueId() {
return uniqueID;
}

public void setUniqueId(String uniqueId) {
this.uniqueID = uniqueId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}


Here the codes of my queries:

Person person = new Person();
person.setUniqueId("azevedo");
Person p = (Person)pm.getObjectById(Person.class, person.getUniqueId());

ERROR output:
2008-12-03 12:23:51,620 [DEBUG] (Retrieve:58) - Object "lu.ept.dt.ldap.Person@1a68ef9" (id="azevedo") being retrieved from LDAP
Exception in thread "main" javax.jdo.JDODataStoreException: [LDAP: error code 32 - No Such Object]
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:379)
at org.datanucleus.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1670)
at org.datanucleus.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1761)
at lu.ept.dt.ldap.LdapConnection.main(LdapConnection.java:34)
NestedThrowablesStackTrace:
javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'uniqueID=azevedo,retailerName=default,o=Users,o=UMC'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3030)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2951)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2758)
at com.sun.jndi.ldap.LdapCtx.c_getAttributes(LdapCtx.java:1295)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:213)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:12
1)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:10
9)
at javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:123)
at org.datanucleus.store.ldap.LDAPPersistenceHandler.fetchObject(LDAPPersistenceHandler.java:316)
at org.datanucleus.state.JDOStateManagerImpl.validate(JDOStateManagerImpl.java:4097)
at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:2442)
at org.datanucleus.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1665)
at org.datanucleus.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1761)
at lu.ept.dt.ldap.LdapConnection.main(LdapConnection.java:34)



From the Error you see that the uniqueID is appened at the end of the dn specified in the Person.java


javax.jdo.Query query = pm.newQuery("javax.jdo.query.JDOQL", "SELECT FROM lu.ept.dt.ldap.Person WHERE uniqueID == \"azevedo\"");

With this query it doesn't find the user in the LDAP tree, I have no error log.

And here a getObjectById(id) as you suggest

Person person = new Person();
person.setUniqueId("tst-jero");
Person p = (Person)pm.getObjectById(person);

Error output:
Exception in thread "main" javax.jdo.JDOObjectNotFoundException: No such object
FailedObject:lu.ept.dt.ldap.Person@153f67e
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:398)
at org.datanucleus.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1670)
at org.datanucleus.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1641)
at lu.ept.dt.ldap.LdapConnection.main(LdapConnection.java:35)


So it looks like the LDAP search is not searching the whole LDAP tree it just goes one leaf below, I changed in Person.java the entry


@Extension(vendorName="DataNucleus", key="dn", value="ou=AR,retailerName=default,o=Users,o=UMC"),


An the two first queries worked, the user was found with all its attributes, and the last query (getObjectById(id)) did return the same error.

I hope it is clear, for you and I think the suggestion of seelmann



<class ...>
<extension vendor-name="datanucleus" key="dn" value="dc=example,dc=com" />
<extension vendor-name="datanucleus" key="searchScope" value="sub" />
...
</class>


to add a
<extension vendor-name="datanucleus" key="searchScope" value="sub" />
is a good idea since in SearchControls are used to set database controls specifique to a database.

Thanks,

azevedo
[Dec 3, 2008 12:40:46 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male andy
Expert
Member's Avatar

UK
Joined: Mar 13, 2004
Post Count: 5686
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

So calling pm.getObjectById results in an incorrect query of LDAP so that it doesn't find the object. This implies a change internal to "store.ldap" and the query sent to LDAP, and doesn't imply exposing LDAP internals to the user (via some "searchControl"). If the user persists an object, they then should be able to call getObjectById on the id ... without having to configure database specifics, this is the whole point of JDO.
----------------------------------------
-Andy smile

[Dec 3, 2008 1:43:50 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male azevedo
Newbie




Joined: Nov 27, 2008
Post Count: 17
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

So calling pm.getObjectById results in an incorrect query of LDAP so that it doesn't find the object. This implies a change internal to "store.ldap" and the query sent to LDAP, and doesn't imply exposing LDAP internals to the user (via some "searchControl"). If the user persists an object, they then should be able to call getObjectById on the id ... without having to configure database specifics, this is the whole point of JDO.


Hi,

I have been looking at the store.ldap source files and the dn used for queries and search is construct using the value in the extension like in my case
@Extension(vendorName="DataNucleus", key="dn", value="retailerName=default,o=Users,o=UMC")


So, If I am correct for the getObjectById in the LDAPPersistenceHandler.java the method fetchObject has to be changed. I noticied that this
String dn = LDAPUtils.getDistinguishedNameForObject(sm);

is creating the dn and in my case it is the wrong dn.

The JDOQL query excutes the LDAPUtils.getObjectsOfCandidateType method which calls ctx.search. I noticied that the query is done on the wohle leaf and than filter is applied in the in-memory. So, I think is best to implment a ctx.search with a filter like and set directly SearchControls.SUBTREE_SCOPE
ctx.search("dc=example", "uid=user", SearchControls)

So it will return the single user if any.

Bye,
azevedo
[Dec 3, 2008 4:39:03 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male seelmann
Novice




Joined: Jul 2, 2008
Post Count: 36
Status: Offline
Reply to this Post  Reply with Quote 
Re: Ldap SearchControls

Hi Andy,

it depends on the structure of the directory and IMO the user has to configure it.

In LDAP there are different ways to structure data.

Some choose a 'flat' hierarchy and just put e.g. all user entries into one container entry, this case is already supported by store.ldap:
ou=users
|-uid=user1
|-uid=user2
|-uid=user3
|-...


Others model the tree like their organisational structure, so the users are on different locations in the tree (just think like the files in a file system):
ou=users
|-ou=brazil
|-uid=user1
|-ou=germany
|-l=berlin
|-uid=user2
|-ou=spain
|-uid=user3



I think the user has to configure which kind of directory structure s/he has.

Regards,
Stefan
[Dec 3, 2008 11:14:05 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 33   Pages: 4   [ 1 2 3 4 | Next Page ]
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread