63 |
{ |
{ |
64 |
private static final String ALG_ALIAS = "Alg.Alias."; |
private static final String ALG_ALIAS = "Alg.Alias."; |
65 |
|
|
66 |
private static final Vector providersList = new Vector(); |
private static Vector providers = new Vector(); |
|
private static boolean providersInited = false; |
|
67 |
private static Properties secprops = new Properties(); |
private static Properties secprops = new Properties(); |
68 |
|
|
69 |
/** |
static |
70 |
* Returns the Vector of security providers. This method will load |
{ |
71 |
* the security providers when they are needed for the first time. |
String base = System.getProperty ("gnu.classpath.home.url"); |
72 |
* This allows for a faster startup. |
String vendor = System.getProperty ("gnu.classpath.vm.shortname"); |
|
* @return vector of security providers |
|
|
*/ |
|
|
private static Vector providers() |
|
|
{ |
|
|
synchronized (providersList) |
|
|
{ |
|
|
if (!providersInited) |
|
|
{ |
|
|
providersInited = true; |
|
|
String base = System.getProperty("gnu.classpath.home.url"); |
|
|
String vendor = System.getProperty("gnu.classpath.vm.shortname"); |
|
73 |
|
|
74 |
// Try VM specific security file |
// Try VM specific security file |
75 |
boolean loaded = loadProviders(base, vendor); |
boolean loaded = loadProviders (base, vendor); |
76 |
|
|
77 |
// Append classpath standard provider if possible |
// Append classpath standard provider if possible |
78 |
if (!loadProviders(base, "classpath") |
if (!loadProviders (base, "classpath") |
79 |
&& !loaded && providersList.size() == 0) |
&& !loaded |
80 |
{ |
&& providers.size() == 0) |
81 |
// No providers found |
{ |
82 |
// and both security files failed to load properly. |
// No providers found |
83 |
System.err.println |
// and both security files failed to load properly. |
84 |
("WARNING: " |
System.err.println |
85 |
+ "could not properly read security provider files:"); |
("WARNING: could not properly read security provider files:"); |
86 |
System.err.println |
System.err.println |
87 |
(" " |
(" " + base + "/security/" + vendor + ".security"); |
88 |
+ base + "/security/" + vendor + ".security"); |
System.err.println |
89 |
System.err.println |
(" " + base + "/security/" + "classpath" + ".security"); |
90 |
(" " |
System.err.println |
91 |
+ base + "/security/" + "classpath" + ".security"); |
(" Falling back to standard GNU security provider"); |
92 |
System.err.println |
providers.addElement (new gnu.java.security.provider.Gnu()); |
93 |
(" Falling back to standard GNU security provider"); |
} |
94 |
providersList.addElement(new gnu.java.security.provider.Gnu()); |
} |
|
} |
|
|
} |
|
|
} |
|
|
return providersList; |
|
|
} |
|
|
|
|
95 |
|
|
96 |
// This class can't be instantiated. |
// This class can't be instantiated. |
97 |
private Security () |
private Security() |
98 |
{ |
{ |
99 |
} |
} |
100 |
|
|
122 |
Exception exception = null; |
Exception exception = null; |
123 |
try |
try |
124 |
{ |
{ |
125 |
providers().addElement(Class.forName(name).newInstance()); |
providers.addElement(Class.forName(name).newInstance()); |
126 |
} |
} |
127 |
catch (ClassNotFoundException x) |
catch (ClassNotFoundException x) |
128 |
{ |
{ |
179 |
|
|
180 |
String property = String.valueOf(propName) + "." + String.valueOf(algName); |
String property = String.valueOf(propName) + "." + String.valueOf(algName); |
181 |
Provider p; |
Provider p; |
182 |
for (Iterator i = providers().iterator(); i.hasNext(); ) |
for (Iterator i = providers.iterator(); i.hasNext(); ) |
183 |
{ |
{ |
184 |
p = (Provider) i.next(); |
p = (Provider) i.next(); |
185 |
for (Iterator j = p.keySet().iterator(); j.hasNext(); ) |
for (Iterator j = p.keySet().iterator(); j.hasNext(); ) |
235 |
sm.checkSecurityAccess("insertProvider." + provider.getName()); |
sm.checkSecurityAccess("insertProvider." + provider.getName()); |
236 |
|
|
237 |
position--; |
position--; |
238 |
int max = providers().size (); |
int max = providers.size (); |
239 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
240 |
{ |
{ |
241 |
if (((Provider) providers().elementAt(i)).getName() == provider.getName()) |
if (((Provider) providers.elementAt(i)).getName() == provider.getName()) |
242 |
return -1; |
return -1; |
243 |
} |
} |
244 |
|
|
247 |
if (position > max) |
if (position > max) |
248 |
position = max; |
position = max; |
249 |
|
|
250 |
providers().insertElementAt(provider, position); |
providers.insertElementAt(provider, position); |
251 |
|
|
252 |
return position + 1; |
return position + 1; |
253 |
} |
} |
277 |
*/ |
*/ |
278 |
public static int addProvider(Provider provider) |
public static int addProvider(Provider provider) |
279 |
{ |
{ |
280 |
return insertProviderAt (provider, providers().size () + 1); |
return insertProviderAt (provider, providers.size () + 1); |
281 |
} |
} |
282 |
|
|
283 |
/** |
/** |
310 |
if (sm != null) |
if (sm != null) |
311 |
sm.checkSecurityAccess("removeProvider." + name); |
sm.checkSecurityAccess("removeProvider." + name); |
312 |
|
|
313 |
int max = providers().size (); |
int max = providers.size (); |
314 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
315 |
{ |
{ |
316 |
if (((Provider) providers().elementAt(i)).getName() == name) |
if (((Provider) providers.elementAt(i)).getName() == name) |
317 |
{ |
{ |
318 |
providers().remove(i); |
providers.remove(i); |
319 |
break; |
break; |
320 |
} |
} |
321 |
} |
} |
329 |
*/ |
*/ |
330 |
public static Provider[] getProviders() |
public static Provider[] getProviders() |
331 |
{ |
{ |
332 |
Provider array[] = new Provider[providers().size ()]; |
Provider array[] = new Provider[providers.size ()]; |
333 |
providers().copyInto (array); |
providers.copyInto (array); |
334 |
return array; |
return array; |
335 |
} |
} |
336 |
|
|
346 |
public static Provider getProvider(String name) |
public static Provider getProvider(String name) |
347 |
{ |
{ |
348 |
Provider p; |
Provider p; |
349 |
int max = providers().size (); |
int max = providers.size (); |
350 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
351 |
{ |
{ |
352 |
p = (Provider) providers().elementAt(i); |
p = (Provider) providers.elementAt(i); |
353 |
if (p.getName() == name) |
if (p.getName() == name) |
354 |
return p; |
return p; |
355 |
} |
} |
503 |
*/ |
*/ |
504 |
public static Provider[] getProviders(String filter) |
public static Provider[] getProviders(String filter) |
505 |
{ |
{ |
506 |
if (providers() == null || providers().isEmpty()) |
if (providers == null || providers.isEmpty()) |
507 |
return null; |
return null; |
508 |
|
|
509 |
if (filter == null || filter.length() == 0) |
if (filter == null || filter.length() == 0) |
563 |
*/ |
*/ |
564 |
public static Provider[] getProviders(Map filter) |
public static Provider[] getProviders(Map filter) |
565 |
{ |
{ |
566 |
if (providers() == null || providers().isEmpty()) |
if (providers == null || providers.isEmpty()) |
567 |
return null; |
return null; |
568 |
|
|
569 |
if (filter == null) |
if (filter == null) |
573 |
if (querries == null || querries.isEmpty()) |
if (querries == null || querries.isEmpty()) |
574 |
return getProviders(); |
return getProviders(); |
575 |
|
|
576 |
LinkedHashSet result = new LinkedHashSet(providers()); // assume all |
LinkedHashSet result = new LinkedHashSet(providers); // assume all |
577 |
int dot, ws; |
int dot, ws; |
578 |
String querry, service, algorithm, attribute, value; |
String querry, service, algorithm, attribute, value; |
579 |
LinkedHashSet serviceProviders = new LinkedHashSet(); // preserve insertion order |
LinkedHashSet serviceProviders = new LinkedHashSet(); // preserve insertion order |