title: Adding a provider in a signed applet
body: <p>I'm working with a signed applet which adds a new provider.
  If the applet is signed such code is considered to be trusted.</p>
  
  <p>In a private method:</p>
  
  <pre><code>private Provider addProvider() throws Exception {
  
      logger.log(Level.INFO, "addProvider ... "); 
  
      Provider p = new sun.security.pkcs11.SunPKCS11(
                       new ByteArrayInputStream(config.getBytes())
                       );
      //Security.addProvider(p);
  
      return p;
  }
  </code></pre>
  
  <p><code>config</code> is a string with the name and the library for PKCS11.</p>
  
  <p>When I debug with netbeans the applet works perfectly and the new provider is added, but when I execute the applet in an html file the applet is not initialized.  And if I uncomment the next the lines where the provider is added the applet in the html is initialized.</p>
  
  <pre><code>private Provider addProvider() throws Exception {
  
      logger.log(Level.INFO, "addProvider ... "); 
  
      //Provider p = new sun.security.pkcs11.SunPKCS11(
                   //     new ByteArrayInputStream(config.getBytes())
                   //   );
      // Security.addProvider(p);
  
      return p;
  }
  </code></pre>
  
  <p>Then there is a problem adding the provider.</p>
  
  <p>Only this line causes that the applet is not initialized:</p>
  
  <pre><code>Provider p = new sun.security.pkcs11.SunPKCS11(
                   new ByteArrayInputStream(config.getBytes())
                   );
  </code></pre>
  
  <p>I have inserted a <code>try {}</code></p>
  
  <pre><code>private Provider addProvider() throws Exception {
  
      logger.log(Level.INFO, "addProvider ... "); 
  
      try{
          Provider p = new sun.security.pkcs11.SunPKCS11(
                           new ByteArrayInputStream(config.getBytes())
                       );
          Security.addProvider(p);
  
      } catch (Exception ex) {
          logger.log(Level.SEVERE, "Excepcion provider: {0}", ex);
      }    
      return p;
  }
  </code></pre>
  
  <p>But like the applet is not initialized I'm not getting any exception
  Any suggestion?</p>
  
  <p>Thanks Andrew for your comment.</p>
  
  <p>I have added your suggestion and now I'm getting an error:</p>
  
  <pre><code>            try{
  
                  provider = new sun.security.pkcs11.SunPKCS11(
                                  new ByteArrayInputStream(config.getBytes())
                                  );
                  Security.addProvider(provider);
  
              } catch (Throwable t) {                    
                  logger.log(Level.SEVERE, "Excepcion provider:", t);
                  logger.log(Level.SEVERE, "Throwable.Cause: ", t.getCause());                          
  
              } 
  </code></pre>
  
  <p>The log shows:</p>
  
  <p>Excepcion provider:</p>
  
  <p></p>
  
  <pre><code>&lt;message&gt;java.lang.ExceptionInInitializerError&lt;/message&gt;
  </code></pre>
  
  <p>Throwable.Cause: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.security.util)</p>