10

I am working with some code from back in 2003. There is a reference to the following class:

new com.sun.net.ssl.internal.ssl.Provider()

It is causing an error:

Access restriction: The type Provider is not accessible due to restriction on required library /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/jre/lib/jsse.jar

Does anyone have any suggestions for a suitable alternative to using this class?

Bruno
  • 119,590
  • 31
  • 270
  • 376
Dan
  • 101
  • 1
  • 1
  • 3
  • I don't know that class, but I can read 'ssl'. If that's Secure Socket Layer, please consider [javax.net.ssl.*](http://docs.oracle.com/javase/7/docs/api/javax/net/ssl/package-summary.html) – ignis Oct 31 '12 at 15:04
  • 2
    There's rarely any reason to instantiate the provider manually like this. What's the code around? – Bruno Oct 31 '12 at 15:05

3 Answers3

10

Throw that line of code away. Also throw away any reference to the com.sun.net.ssl package and its sub-packages: fix the imports so they refer to the classes in javax.net.ssl.

This is pre-JDK 1.4 code, from the days when JSSE was a separate download.

user207421
  • 305,947
  • 44
  • 307
  • 483
8

Most of the time, you don't actually need to create or get hold of a provider instance yourself. As the Oracle Providers documentation says:

General purpose applications SHOULD NOT request cryptographic services from specific providers. That is:

getInstance("...", "SunJCE");  // not recommended
    vs.
getInstance("...");            // recommended

In addition, wherever there's an overloaded parameter for the provider, it tends to take either a string or an instance, but the string (name) would probably be more common. (Passing an instance can be useful sometimes, e.g. for some PKCS#11 configurations, but it's unusual.)

The JCA documentation about Providers should be useful.

If you really want to get hold of a specific instance, you can use Security.getProvider(name). You'll find the appropriate names in the providers documentation.

Bruno
  • 119,590
  • 31
  • 270
  • 376
1

You can turn this into a warning or non-event in Eclipse preferences Java->Compiler->Errors/Warnings->Deprecated and restricted API. Note, as others have said, this not the best practice and should be avoided when you have alternatives.

Martin Serrano
  • 3,727
  • 1
  • 35
  • 48