title: CKR_USER_NOT_LOGGED_IN when generating key pair using sunPKCS11 provider
body: <p>When trying to generate rsa key pair with sun PKCS11 provider, method <code>generateKeyPair()</code> throws <code>ProviderException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_USER_NOT_LOGGED_IN</code></p>
  
  <p>My code looks like this:</p>
  
  <pre><code>Provider prov = ... // initialize provider
  
  KeyStore ks = KeyStore.getInstance("PKCS11", prov);
  ks.load(null, "pass".toCharArray());
  
  KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", prov);
  keyGen.initialize(2048);
  KeyPair kp = keyGen.generateKeyPair();    // exception thrown here
  </code></pre>
  
  <p>I tried using <code>AuthProvider</code> right after provider initialization like so:</p>
  
  <pre><code>AuthProvider aprov = (AuthProvider) prov;
  aprov.login(null, callbacks -&gt; {
      log.error("@@@ Inside callbacks {}", callbacks.length);
  });
  aprov.setCallbackHandler(callbacks -&gt; {
      log.error("@@@ Inside setCallBackHandler {}", callbacks.length);
  });
  </code></pre>
  
  <p>But I don't see any logging output, so that means lambdas are not executed.</p>
  
  <p>The ultimate goal is to generate RSA key pair and store it in keystore (HSM) via PKCS11.</p>
  
  <p>I tried openjdk 8 and oracle jdk 8. Also when listing aliases from keystore, I get an empty list, but I know there is one entry. Adding <code>-Djava.security.debug=sunpkcs11</code> changed nothing.</p>