Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed scheme from URI before fetching path for CRL path check #2622

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Collections;
Expand Down Expand Up @@ -284,20 +285,27 @@ private static void createConnectionRules(LinkedList<String> listOfRules) throws
private static String getCurrentClassPath() throws SQLServerException {
String location = "";
String className = "";
String schemeSpecificPart = "";

try {
className = new Object() {}.getClass().getEnclosingClass().getName();
location = Class.forName(className).getProtectionDomain().getCodeSource().getLocation().getPath();

if (Files.isDirectory(Paths
.get(ConfigurableRetryLogic.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
schemeSpecificPart = ConfigurableRetryLogic.class.getProtectionDomain().getCodeSource().getLocation()
.toURI().getSchemeSpecificPart();
schemeSpecificPart = schemeSpecificPart.substring(1); // Remove leading /
if (Files.isDirectory(Paths.get(schemeSpecificPart))) {
// We check if the Path we get from the CodeSource location is a directory. If so, we are running
// from class files and should remove a suffix (i.e. the props file is in a different location from the
// location returned)
location = location.substring(0, location.length() - ("target/classes/").length());
}

return new URI(location).getPath() + DEFAULT_PROPS_FILE; // TODO: Allow custom paths
} catch (InvalidPathException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_PathInvalid"));
Object[] msgArgs = {schemeSpecificPart};
throw new SQLServerException(form.format(msgArgs), null, 0, e);
} catch (URISyntaxException e) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_URLInvalid"));
Object[] msgArgs = {location};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ protected Object[][] getContents() {
{"R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumn", "Cannot execute statement or procedure {0} because Force Encryption was set as true for parameter {1} and the database expects this parameter to be sent as plaintext. This may be due to a configuration error."},
{"R_ForceEncryptionTrue_HonorAEFalseRS", "Cannot set Force Encryption to true for parameter {0} because encryption is not enabled for the statement or procedure."},
{"R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumnRS", "Cannot execute update because Force Encryption was set as true for parameter {0} and the database expects this parameter to be sent as plaintext. This may be due to a configuration error."},
{"R_NullValue", "{0} cannot be null."},
{"R_NullValue", "{0} cannot be null."},
{"R_PathInvalid", "Invalid path specified: {0}."},
{"R_URLInvalid", "Invalid URL specified: {0}."},
{"R_AKVPathNull", "Azure Key Vault key path cannot be null."},
{"R_AKVMasterKeyPathInvalid", "Invalid Azure Key Vault key path specified: {0}."},
Expand Down
Loading