Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7043959

NTML impl of SaslClientFactory throws NPE for null CallBackHandler instance

XMLWordPrintable

    • b04
    • generic
    • generic
    • Verified

        Platform: Windows, Solaris
        JDK: Oracle JDK7
        (not reproducible on Sun's JDK6 as NTLMServer is not present there)

        The com.sun.security.sasl.ntlm.NTLMServer implementaiton of method
         http://download.java.net/jdk7/docs/api/javax/security/sasl/SaslClientFactory.html#createSaslClient%28java.lang.String[],%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.util.Map,%20javax.security.auth.callback.CallbackHandler%29

        Throws "java.lang.NullPointerException" when null callback handler is passed
        though the spec says implementation should accept null without any problems:

        Parameters:
            ...
            cbh - The possibly null callback handler


        Please see the following code sample:

        --------------------------------------------------------------------------------------------
        package sasl;

        import javax.security.sasl.*;
        import java.util.ArrayList;
        import java.util.Collections;
        import java.util.HashMap;

        public class CreateSaslClient {

            public static void main(String[] args) throws SaslException {
                ArrayList<SaslClientFactory> list = Collections.list(Sasl.getSaslClientFactories());
                for (SaslClientFactory clientFactory : list) {
                    System.err.println("clientFactory = " + clientFactory);
                    String[] mechanismNames = clientFactory.getMechanismNames(null);
                    if (mechanismNames.length == 1 && "NTLM".equals(mechanismNames[0])) {
                        System.err.println("Calling createSaslClient(..)");
                            clientFactory.createSaslClient(
                                new String[] {"NTLM"}, "abc", "ldap", "server", new HashMap<String, Object>(), null);
                    }
                }
            }
        }
        --------------------------------------------------------------------------------------------

        The output will look like:

        clientFactory = com.sun.security.sasl.digest.FactoryImpl@11a0d8b
        clientFactory = com.sun.security.sasl.ntlm.FactoryImpl@d32ea0
        Calling createSaslClient(..)
        Exception in thread "main" java.lang.NullPointerException
        at com.sun.security.sasl.ntlm.NTLMClient.<init>(NTLMClient.java:146)
        at com.sun.security.sasl.ntlm.FactoryImpl.createSaslClient(FactoryImpl.java:73)
        at sasl.CreateSaslClient.main(CreateSaslClient.java:17)

              weijun Weijun Wang
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: