63 |
{ |
{ |
64 |
private static final String ALG_ALIAS = "Alg.Alias."; |
private static final String ALG_ALIAS = "Alg.Alias."; |
65 |
|
|
66 |
private static Vector providers = new Vector(); |
private static final Vector providers_lazy = new Vector(); |
67 |
|
private static boolean providers_lazy_set = false; |
68 |
private static Properties secprops = new Properties(); |
private static Properties secprops = new Properties(); |
69 |
static |
|
70 |
|
/** |
71 |
|
* Returns the Vector of security providers. This method will load |
72 |
|
* the security providers when they are needed for the first time. |
73 |
|
* This allows for a faster startup. |
74 |
|
* @return vector of security providers |
75 |
|
*/ |
76 |
|
private static Vector providers() |
77 |
{ |
{ |
78 |
String base = System.getProperty("gnu.classpath.home.url"); |
synchronized (providers_lazy) |
|
String vendor = System.getProperty("gnu.classpath.vm.shortname"); |
|
|
|
|
|
// Try VM specific security file |
|
|
boolean loaded = loadProviders(base, vendor); |
|
|
|
|
|
// Append classpath standard provider if possible |
|
|
if (!loadProviders(base, "classpath") && !loaded && providers.size() == 0) |
|
79 |
{ |
{ |
80 |
// No providers found and both security files failed to load properly. |
if (!providers_lazy_set) |
81 |
System.err.println |
{ |
82 |
("WARNING: could not properly read security provider files:"); |
String base = System.getProperty("gnu.classpath.home.url"); |
83 |
System.err.println |
String vendor = System.getProperty("gnu.classpath.vm.shortname"); |
84 |
(" " + base + "/security/" + vendor + ".security"); |
|
85 |
System.err.println |
// Try VM specific security file |
86 |
(" " + base + "/security/" + "classpath" + ".security"); |
boolean loaded = loadProviders(base, vendor); |
87 |
System.err.println |
|
88 |
(" Falling back to standard GNU security provider"); |
// Append classpath standard provider if possible |
89 |
providers.addElement(new gnu.java.security.provider.Gnu()); |
if (!loadProviders(base, "classpath") && !loaded && providers_lazy.size() == 0) |
90 |
|
{ |
91 |
|
// No providers found and both security files failed to load properly. |
92 |
|
System.err.println |
93 |
|
("WARNING: could not properly read security provider files:"); |
94 |
|
System.err.println |
95 |
|
(" " + base + "/security/" + vendor + ".security"); |
96 |
|
System.err.println |
97 |
|
(" " + base + "/security/" + "classpath" + ".security"); |
98 |
|
System.err.println |
99 |
|
(" Falling back to standard GNU security provider"); |
100 |
|
providers_lazy.addElement(new gnu.java.security.provider.Gnu()); |
101 |
|
} |
102 |
|
} |
103 |
} |
} |
104 |
|
return providers_lazy; |
105 |
} |
} |
106 |
|
|
107 |
|
|
108 |
// This class can't be instantiated. |
// This class can't be instantiated. |
109 |
private Security () |
private Security () |
134 |
Exception exception = null; |
Exception exception = null; |
135 |
try |
try |
136 |
{ |
{ |
137 |
providers.addElement(Class.forName(name).newInstance()); |
providers().addElement(Class.forName(name).newInstance()); |
138 |
} |
} |
139 |
catch (ClassNotFoundException x) |
catch (ClassNotFoundException x) |
140 |
{ |
{ |
191 |
|
|
192 |
String property = String.valueOf(propName) + "." + String.valueOf(algName); |
String property = String.valueOf(propName) + "." + String.valueOf(algName); |
193 |
Provider p; |
Provider p; |
194 |
for (Iterator i = providers.iterator(); i.hasNext(); ) |
for (Iterator i = providers().iterator(); i.hasNext(); ) |
195 |
{ |
{ |
196 |
p = (Provider) i.next(); |
p = (Provider) i.next(); |
197 |
for (Iterator j = p.keySet().iterator(); j.hasNext(); ) |
for (Iterator j = p.keySet().iterator(); j.hasNext(); ) |
247 |
sm.checkSecurityAccess("insertProvider." + provider.getName()); |
sm.checkSecurityAccess("insertProvider." + provider.getName()); |
248 |
|
|
249 |
position--; |
position--; |
250 |
int max = providers.size (); |
int max = providers().size (); |
251 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
252 |
{ |
{ |
253 |
if (((Provider) providers.elementAt(i)).getName() == provider.getName()) |
if (((Provider) providers().elementAt(i)).getName() == provider.getName()) |
254 |
return -1; |
return -1; |
255 |
} |
} |
256 |
|
|
259 |
if (position > max) |
if (position > max) |
260 |
position = max; |
position = max; |
261 |
|
|
262 |
providers.insertElementAt(provider, position); |
providers().insertElementAt(provider, position); |
263 |
|
|
264 |
return position + 1; |
return position + 1; |
265 |
} |
} |
289 |
*/ |
*/ |
290 |
public static int addProvider(Provider provider) |
public static int addProvider(Provider provider) |
291 |
{ |
{ |
292 |
return insertProviderAt (provider, providers.size () + 1); |
return insertProviderAt (provider, providers().size () + 1); |
293 |
} |
} |
294 |
|
|
295 |
/** |
/** |
322 |
if (sm != null) |
if (sm != null) |
323 |
sm.checkSecurityAccess("removeProvider." + name); |
sm.checkSecurityAccess("removeProvider." + name); |
324 |
|
|
325 |
int max = providers.size (); |
int max = providers().size (); |
326 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
327 |
{ |
{ |
328 |
if (((Provider) providers.elementAt(i)).getName() == name) |
if (((Provider) providers().elementAt(i)).getName() == name) |
329 |
{ |
{ |
330 |
providers.remove(i); |
providers().remove(i); |
331 |
break; |
break; |
332 |
} |
} |
333 |
} |
} |
341 |
*/ |
*/ |
342 |
public static Provider[] getProviders() |
public static Provider[] getProviders() |
343 |
{ |
{ |
344 |
Provider array[] = new Provider[providers.size ()]; |
Provider array[] = new Provider[providers().size ()]; |
345 |
providers.copyInto (array); |
providers().copyInto (array); |
346 |
return array; |
return array; |
347 |
} |
} |
348 |
|
|
358 |
public static Provider getProvider(String name) |
public static Provider getProvider(String name) |
359 |
{ |
{ |
360 |
Provider p; |
Provider p; |
361 |
int max = providers.size (); |
int max = providers().size (); |
362 |
for (int i = 0; i < max; i++) |
for (int i = 0; i < max; i++) |
363 |
{ |
{ |
364 |
p = (Provider) providers.elementAt(i); |
p = (Provider) providers().elementAt(i); |
365 |
if (p.getName() == name) |
if (p.getName() == name) |
366 |
return p; |
return p; |
367 |
} |
} |
515 |
*/ |
*/ |
516 |
public static Provider[] getProviders(String filter) |
public static Provider[] getProviders(String filter) |
517 |
{ |
{ |
518 |
if (providers == null || providers.isEmpty()) |
if (providers() == null || providers().isEmpty()) |
519 |
return null; |
return null; |
520 |
|
|
521 |
if (filter == null || filter.length() == 0) |
if (filter == null || filter.length() == 0) |
575 |
*/ |
*/ |
576 |
public static Provider[] getProviders(Map filter) |
public static Provider[] getProviders(Map filter) |
577 |
{ |
{ |
578 |
if (providers == null || providers.isEmpty()) |
if (providers() == null || providers().isEmpty()) |
579 |
return null; |
return null; |
580 |
|
|
581 |
if (filter == null) |
if (filter == null) |
585 |
if (querries == null || querries.isEmpty()) |
if (querries == null || querries.isEmpty()) |
586 |
return getProviders(); |
return getProviders(); |
587 |
|
|
588 |
LinkedHashSet result = new LinkedHashSet(providers); // assume all |
LinkedHashSet result = new LinkedHashSet(providers()); // assume all |
589 |
int dot, ws; |
int dot, ws; |
590 |
String querry, service, algorithm, attribute, value; |
String querry, service, algorithm, attribute, value; |
591 |
LinkedHashSet serviceProviders = new LinkedHashSet(); // preserve insertion order |
LinkedHashSet serviceProviders = new LinkedHashSet(); // preserve insertion order |