Skip to content

Commit ddeca97

Browse files
authored
Merge pull request ibmruntimes#307 from taoliult/sasl
Add provider name and class name mapping in Restricted Security mode
2 parents 2808eb5 + 1cbe1ff commit ddeca97

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java

+40-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ===========================================================================
3-
* (c) Copyright IBM Corp. 2022, 2023 All Rights Reserved
3+
* (c) Copyright IBM Corp. 2022, 2024 All Rights Reserved
44
* ===========================================================================
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -687,11 +687,19 @@ private void initProviders() {
687687

688688
// Remove the provider's optional arguments if there are.
689689
pos = providerName.indexOf(' ');
690-
providerName = (pos < 0) ? providerName.trim() : providerName.substring(0, pos).trim();
691-
// Remove the provider's class package names if there are.
692-
pos = providerName.lastIndexOf('.');
693-
providerName = (pos < 0) ? providerName : providerName.substring(pos + 1, providerName.length());
694-
// Provider without arguments and package names.
690+
if (pos >= 0) {
691+
providerName = providerName.substring(0, pos);
692+
}
693+
providerName = providerName.trim();
694+
695+
// Remove argument, e.g. -NSS-FIPS, if present.
696+
pos = providerName.indexOf('-');
697+
if (pos >= 0) {
698+
providerName = providerName.substring(0, pos);
699+
}
700+
701+
// Provider name defined in provider construction method.
702+
providerName = getProvidersSimpleName(providerName);
695703
providersSimpleName.add(pNum - 1, providerName);
696704
}
697705

@@ -959,11 +967,12 @@ boolean isRestrictedProviderAllowed(String providerName) {
959967

960968
// Remove argument, e.g. -NSS-FIPS, if there is.
961969
int pos = providerName.indexOf('-');
962-
providerName = (pos < 0) ? providerName : providerName.substring(0, pos);
970+
if (pos >= 0) {
971+
providerName = providerName.substring(0, pos);
972+
}
963973

964-
// Remove the provider class package name if there is.
965-
pos = providerName.lastIndexOf('.');
966-
providerName = (pos < 0) ? providerName : providerName.substring(pos + 1, providerName.length());
974+
// Provider name defined in provider construction method.
975+
providerName = getProvidersSimpleName(providerName);
967976

968977
// Check if the provider is in restricted security provider list.
969978
// If not, the provider won't be registered.
@@ -988,6 +997,27 @@ boolean isRestrictedProviderAllowed(String providerName) {
988997
return false;
989998
}
990999

1000+
/**
1001+
* Get the provider name defined in provider construction method.
1002+
*
1003+
* @param providerName provider name or provider with packages
1004+
* @return provider name defined in provider construction method
1005+
*/
1006+
private static String getProvidersSimpleName(String providerName) {
1007+
if (providerName.equals("com.sun.security.sasl.Provider")) {
1008+
// The main class for the SunSASL provider is com.sun.security.sasl.Provider.
1009+
return "SunSASL";
1010+
} else {
1011+
// Remove the provider's class package names if present.
1012+
int pos = providerName.lastIndexOf('.');
1013+
if (pos >= 0) {
1014+
providerName = providerName.substring(pos + 1);
1015+
}
1016+
// Provider without package names.
1017+
return providerName;
1018+
}
1019+
}
1020+
9911021
/**
9921022
* List audit info of all available RestrictedSecurity profiles.
9931023
*/

0 commit comments

Comments
 (0)