Uploaded image for project: 'Crowd Data Center'
  1. Crowd Data Center
  2. CWD-5176

Using RemoteDirectory methods from a plugin executes them in the plugin's classloader, rather than the host product one

      When executing code in a plugin, and calling methods on a RemoteDirectory instance, retrieved from a DirectoryInstanceLoader, these methods get executed using the context classloader of the plugin, rather than that of the host product (which they should, as they're service objects instantiated by the product).

      Most of the time this doesn't prevent them from being used, but in some cases (for example when executing the method causes an LDAP interaction), having the wrong contextclassloader might cause the calls to fail with a ClassNotFoundException. 

      Sample stacktrace:

      com.atlassian.crowd.exception.OperationFailedException: org.springframework.transaction.CannotCreateTransactionException: Could not create DirContext instance for transaction; nested exception is org.springframework.ldap.CommunicationException: Loading the socket factory; nested exception is javax.naming.CommunicationException: Loading the socket factory [Root exception is java.lang.ClassNotFoundException: com.atlassian.crowd.directory.ssl.LdapHostnameVerificationSSLSocketFactory]
      at com.atlassian.crowd.directory.SpringLDAPConnector.pageSearchResults(SpringLDAPConnector.java:405)
      at com.atlassian.crowd.directory.SpringLDAPConnector.searchEntitiesWithRequestControls(SpringLDAPConnector.java:440)
      at com.atlassian.crowd.directory.SpringLDAPConnector.searchEntities(SpringLDAPConnector.java:424)
      at com.atlassian.crowd.directory.SpringLDAPConnector.searchUserObjects(SpringLDAPConnector.java:627)
      at com.atlassian.crowd.directory.SpringLDAPConnector.searchUsers(SpringLDAPConnector.java:974)
       

            [CWD-5176] Using RemoteDirectory methods from a plugin executes them in the plugin's classloader, rather than the host product one

            Lukasz Pater added a comment - - edited

            This is due to `com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler` not wrapping the result of the call from DirectoryInstanceLoader. So the RemoteDirectory service objects don't get wrapped, and it's methods are executed without the classloader switching.

            Lukasz Pater added a comment - - edited This is due to `com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler` not wrapping the result of the call from DirectoryInstanceLoader. So the RemoteDirectory service objects don't get wrapped, and it's methods are executed without the classloader switching.

              Unassigned Unassigned
              lpater Lukasz Pater
              Affected customers:
              10 This affects my team
              Watchers:
              11 Start watching this issue

                Created:
                Updated: