8285263: Minor cleanup could be done in java.security

Reviewed-by: weijun
This commit is contained in:
Mark Powers 2022-06-13 15:13:56 +00:00 committed by Weijun Wang
parent b97a4f6cdc
commit 17695962ac
94 changed files with 480 additions and 601 deletions

View file

@ -72,11 +72,9 @@ public final class Security {
// (the FileInputStream call and the File.exists call,
// the securityPropFile call, etc)
@SuppressWarnings("removal")
var dummy = AccessController.doPrivileged(new PrivilegedAction<>() {
public Void run() {
initialize();
return null;
}
var dummy = AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
initialize();
return null;
});
}
@ -229,12 +227,11 @@ public final class Security {
* properties file.
*/
private static ProviderProperty getProviderProperty(String key) {
ProviderProperty entry = null;
List<Provider> providers = Providers.getProviderList().providers();
for (int i = 0; i < providers.size(); i++) {
String matchKey = null;
String matchKey;
Provider prov = providers.get(i);
String prop = prov.getProperty(key);
@ -242,7 +239,7 @@ public final class Security {
// Is there a match if we do a case-insensitive property name
// comparison? Let's try ...
for (Enumeration<Object> e = prov.keys();
e.hasMoreElements() && prop == null; ) {
e.hasMoreElements(); ) {
matchKey = (String)e.nextElement();
if (key.equalsIgnoreCase(matchKey)) {
prop = prov.getProperty(matchKey);
@ -259,7 +256,7 @@ public final class Security {
}
}
return entry;
return null;
}
/**
@ -271,7 +268,7 @@ public final class Security {
// Is there a match if we do a case-insensitive property name
// comparison? Let's try ...
for (Enumeration<Object> e = provider.keys();
e.hasMoreElements() && prop == null; ) {
e.hasMoreElements(); ) {
String matchKey = (String)e.nextElement();
if (key.equalsIgnoreCase(matchKey)) {
prop = provider.getProperty(matchKey);
@ -534,8 +531,8 @@ public final class Security {
* @since 1.3
*/
public static Provider[] getProviders(String filter) {
String key = null;
String value = null;
String key;
String value;
int index = filter.indexOf(':');
if (index == -1) {
@ -631,17 +628,11 @@ public final class Security {
firstSearch = false;
}
if ((newCandidates != null) && !newCandidates.isEmpty()) {
if (!newCandidates.isEmpty()) {
// For each provider in the candidates set, if it
// isn't in the newCandidate set, we should remove
// it from the candidate set.
for (Iterator<Provider> cansIte = candidates.iterator();
cansIte.hasNext(); ) {
Provider prov = cansIte.next();
if (!newCandidates.contains(prov)) {
cansIte.remove();
}
}
candidates.removeIf(prov -> !newCandidates.contains(prov));
} else {
candidates = null;
break;
@ -735,7 +726,7 @@ public final class Security {
* {@code checkPermission} method is called with a
* {@code java.security.SecurityPermission("getProperty."+key)}
* permission to see if it's ok to retrieve the specified
* security property value..
* security property value.
*
* @param key the key of the property being retrieved.
*
@ -858,7 +849,7 @@ public final class Security {
// The first component is the service name.
// The second is the algorithm name.
// If the third isn't null, that is the attrinute name.
// If the third isn't null, that is the attribute name.
String serviceName = filterComponents[0];
String algName = filterComponents[1];
String attrName = filterComponents[2];
@ -953,10 +944,7 @@ public final class Security {
if (attribute.equalsIgnoreCase("KeySize"))
return true;
if (attribute.equalsIgnoreCase("ImplementedIn"))
return true;
return false;
return attribute.equalsIgnoreCase("ImplementedIn");
}
/*
@ -971,11 +959,7 @@ public final class Security {
if (attribute.equalsIgnoreCase("KeySize")) {
int requestedSize = Integer.parseInt(value);
int maxSize = Integer.parseInt(prop);
if (requestedSize <= maxSize) {
return true;
} else {
return false;
}
return requestedSize <= maxSize;
}
// For Type, prop is the type of the implementation
@ -997,7 +981,7 @@ public final class Security {
}
String serviceName = filterKey.substring(0, algIndex);
String algName = null;
String algName;
String attrName = null;
if (filterValue.isEmpty()) {
@ -1005,7 +989,7 @@ public final class Security {
// should be in the format of <crypto_service>.<algorithm_or_type>.
algName = filterKey.substring(algIndex + 1).trim();
if (algName.isEmpty()) {
// There must be a algorithm or type name.
// There must be an algorithm or type name.
throw new InvalidParameterException("Invalid filter");
}
} else {