Announcement Announcement Module
Collapse
No announcement yet.
mapFromContext doesn't get DirContextAdapter as parameter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mapFromContext doesn't get DirContextAdapter as parameter

    Hi,

    After I upgraded from ldaptemlate to the spring-ldap-1.1.2, the following code doesn't work anymore.

    Code:
    private static class GroupContextMapper	implements ContextMapper {
    				
          public Object mapFromContext(Object ctx) {
    	DirContextAdapter context = (DirContextAdapter) ctx;
    ...
    I get always ClassCastException. It looks like the parameter "ctx" is a DirContext instead of a DirContextAdapter.

    Following is my context source configuration:

    Code:
    <bean id="ldapSource" class="org.springframework.ldap.support.LdapContextSource">
          	<property name="url" value="ldap://server1234:389" />
          	<property name="base" value="DC=test,DC=com" />
          	<property name="userName" value="CN=test,CN=Users,DC=test,DC=com" />
          	<property name="password" value="secret" />
          	<property name="anonymousReadOnly" value="false" />
          	<property name="dirObjectFactory" value="org.springframework.ldap.support.DefaultDirObjectFactory" />
       	</bean>
    Why can't the ldaptemplate.lookup method pass a DirContextAdapter to the ConterxMapper anymore?

    Please help me!

    Thanks in advance

  • #2
    There's no change in the way this works, so I'm just taking a wild guess here: Could it be that the import clause for DirContextAdapter refers to the old ldaptemplate definition of the class? Did you remove the ldaptemplate jar from your classpath?

    Comment


    • #3
      Hi,

      thanks for the anwser. I checked all my code and library. There is no old ldaptemplate jar used.

      I can use ldaptemplate to create object like the following:
      Code:
      DirContextAdapter adapter = new DirContextAdapter(dn);
      ...
      try{
          ldapTemplate.bind(dn, adapter, null);	
      }catch(DataAccessException e){
           ...
      }
      I can also use ldapTemplate.lookup(dn, attributeMapper).

      I only have problem when I try to use ldapTemplate.lookup(dn, contextMapper).

      Any other idea?

      Thanks in advance!

      Kanyin

      Comment


      • #4
        Have you verified that the object being sent to the ContextMapper is indeed a DirContext instance? You might want to try and remove the configuration row for DirObjectFactory from your ContextSource configuration. This is automatically configured in Spring LDAP (as opposed to LdapTemplate).

        Comment


        • #5
          Use AbstractContextMapper

          I also got the ClassCastException, the solution seems to be to use the AbstractContextMapper as explained at http://static.springsource.org/sprin...ry.html#d0e853.

          Comment

          Working...
          X