Custom socket factory is not checked for the existence of a getDefault() method

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Component/s: core-libs
    • None
    • behavioral
    • medium
    • Hide
      Applications that would have configured a `java.naming.ldap.factory.socket` environment property that corresponded to a class that did not extend `javax.net.SocketFactory` or did not have an implementation for the `public static SocketFactory getDefault()` method will now see a `javax.naming.NamingException` being thrown. Such applications are expected to follow the pre-existing specification of the `java.naming.ldap.factory.socket` environment property to provide a valid `javax.net.SocketFactory` type with the right `getDefault()` method.

      Given the nature of this dynamic configuration, it's not easy to determine how many applications might have configured an incorrect value for this environment property. That makes this change a potential "medium" compatibility risk.
      Show
      Applications that would have configured a `java.naming.ldap.factory.socket` environment property that corresponded to a class that did not extend `javax.net.SocketFactory` or did not have an implementation for the `public static SocketFactory getDefault()` method will now see a `javax.naming.NamingException` being thrown. Such applications are expected to follow the pre-existing specification of the `java.naming.ldap.factory.socket` environment property to provide a valid `javax.net.SocketFactory` type with the right `getDefault()` method. Given the nature of this dynamic configuration, it's not easy to determine how many applications might have configured an incorrect value for this environment property. That makes this change a potential "medium" compatibility risk.
    • Other
    • JDK

      Summary

      The default LDAP Naming Service Provider implementation in the JDK is updated to verify that the class configured through the java.naming.ldap.factory.socket JNDI environment property extends the javax.net.SocketFactory class and implements the following method:

      public static SocketFactory getDefault() {...}
      

      Problem

      The default LDAP Naming Service Provider implementation in the JDK specifies the java.naming.ldap.factory.socket JNDI environment property as follows:

      java.naming.ldap.factory.socket:

      The value of this environment property specifies the fully qualified class name of the socket factory used by the LDAP provider. This class must implement the SocketFactory abstract class and provide an implementation of the static "getDefault()" method that returns an instance of the socket factory. By default the environment property is not set.

      However, the implementation in the JDK does not apply these checks against the class constructed out of the configured environment property value. As a result, if this property was configured to a class which isn't of type javax.net.SocketFactory, the implementation in the JDK ends up calling the getDefault() method on it, if there was one. Furthermore, the implementation currently has no checks on the method itself and it can end up invoking a getDefault() method which isn't declared on the configured class but is present on some class in the hierarchy of that class. Both of these behaviours are incorrect and go against the specification of this environment property.

      Solution

      The implementation in the JDK is enhanced to do the necessary type and method checks against the class configured through the java.naming.ldap.factory.socket environment property. If the configured class fails these validation checks, then the default LDAP Naming Service Provider implementation in the JDK will now raise a javax.naming.ConfigurationException, which is a javax.naming.NamingException. The specification of the java.naming.ldap.factory.socket environment property too has been clarified to explicitly state the expected method signature of the getDefault() method.

      Specification

      No actual specification change - this is editorial only.

      diff --git a/src/java.naming/share/classes/module-info.java b/src/java.naming/share/classes/module-info.java
      index 5a731000194c9..30b33594d53af 100644
      --- a/src/java.naming/share/classes/module-info.java
      +++ b/src/java.naming/share/classes/module-info.java
      ...
        * <li>{@code java.naming.ldap.factory.socket}:
        *         <br>The value of this environment property specifies the fully
        *         qualified class name of the socket factory used by the LDAP provider.
        *         This class must implement the {@link javax.net.SocketFactory} abstract class
      - *         and provide an implementation of the static "getDefault()" method that
      - *         returns an instance of the socket factory. By default the environment
      + *         and provide an implementation of the {@code public static SocketFactory getDefault()}
      + *         method that returns an instance of the socket factory. By default the environment
        *         property is not set.
      

            Assignee:
            Jaikiran Pai
            Reporter:
            Pavel Rappo
            Daniel Fuchs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: