Announcement Announcement Module
Collapse
No announcement yet.
Obtaining dn attributes(actually sub nodes) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Obtaining dn attributes(actually sub nodes)

    Hi,

    im implementing dao for fetching custom person data from Fedora Directory Server. In my person schema there are sub nodes of person node (such as custom addresses or security cards info). In person class there are dn attributes that contains dn's of these sub nodes.

    Aim: fetch list of person objects _with_ addresses and other sub-node objects.

    Simplified code:
    Code:
    class PersonBean {
    
    Address adres1;
    Address adres2;
    Address adres3;
    
    Card card1;
    Card card2;
    (...)
    }
    Im using cusomised PersonContextMapper to fetch persons list:

    Code:
    	public List<PersonBean> getAll() {
    		EqualsFilter filter = new EqualsFilter("objectclass",
    				"customPerson");
    
    		List<PersonBean> lista = null;
    		lista = ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter
    				.encode(), getContextMapper());
    		return lista;
    	}
    
    	private static class PersonContextMapper implements ContextMapper {
    		public Object mapFromContext(Object ctx) {
    			DirContextAdapter context = (DirContextAdapter) ctx;
    			PersonBean person = new PersonBean();
    (...)
    }
    and some ldap ldif:

    Code:
    attributeTypes: (
      1.3.6.1.4.1.23019.2.2.27
      NAME 'homeAddress'
      EQUALITY distinguishedNameMatch
      SYNTAX 1.3.6.1.4.1.1466.115.121.1.12
      )
    attributeTypes: (
      1.3.6.1.4.1.23019.2.2.28
      NAME 'contactAddress'
      EQUALITY distinguishedNameMatch
      SYNTAX 1.3.6.1.4.1.1466.115.121.1.12
      )
    ...
    attributeTypes: (
      1.3.6.1.4.1.23019.2.2.17
      NAME 'securityCard'
      EQUALITY distinguishedNameMatch
      SYNTAX 1.3.6.1.4.1.1466.115.121.1.12
      )
    My question is - can i obtain sub nodes of person (addresses and cards) in mapFromContext method? If yes how to? Is there a pattern to obtain such linked-objects data?

    Any help appreciated

    Kris

  • #2
    I'm not sure if I understand your problem correctly, but there should be no problem performing searches and lookups in your ContextMapper. Just make your private ContextMapper implementation non-static, and that will give you access to the LdapTemplate instance of the surrounding Dao class:
    Code:
    private class PersonContextMapper implements ContextMapper{
      public Object mapFromContext(Object ctx){
        DirContextAdapter context = (DirContextAdapter) ctx;
        String homeAddressDn = context.getStringAttribute("homeAddress");
        Address homeAddress = ldapTemplate.lookup(homeAddressDn, new AddressContextMapper()); // Uses the ldapTemplate instance of the surrounding class.
        ...
      }
    }

    Comment


    • #3
      Thanks for your help.
      Using lookup in ContextMapper works just fine, but I have another problem. The lookup method of LdapTemplate adds base dn to dn parameter while sending request to LDAP resulting in error. Can this behaviour be changed or maybe I should store values of distinguishedName attributes without base dn? Now I cut base dn fragment form value of distinguishedName attribute before calling lookup method but it seems to be not very nice.

      Kris

      Comment


      • #4
        Well, that's pretty much a matter of taste. The base DN is actually not added by LdaoTemplate - this is a feature of the Java LDAP Provider, so it's not much we can do about it.

        If you want to use the 'base' property (which is really convenient in the most cases), you'll either have to strip the base path from the DN in the database or in you code; of course the first option would only work if you have exclusive access to the LDAP database - if other applications will be accessing they'll most likely be confused if the refererring DNs are incomplete.

        Comment

        Working...
        X