Skip to content

Commit d996c47

Browse files
rakillenrobertpatrick
authored andcommitted
Check for files in zipped archive wallet during validation
1 parent 20837b0 commit d996c47

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,6 +3836,54 @@ public List<String> getDatabaseWalletPaths() throws WLSDeployArchiveIOException
38363836
return new ArrayList<>(results);
38373837
}
38383838

3839+
/**
3840+
* Return the wallet entry names at the specified path in the archive, if any.
3841+
* If that archive path contains a single zip (a wallet zip), return the entries from that zip.
3842+
*/
3843+
public List<String> getDatabaseWalletEntries(String walletPath) throws WLSDeployArchiveIOException {
3844+
final String METHOD = "getDatabaseWalletEntries";
3845+
LOGGER.entering(CLASS, METHOD);
3846+
3847+
List<String> walletEntries = new ArrayList<>();
3848+
3849+
if(containsPath(walletPath)) {
3850+
String walletPrefix = walletPath + ZIP_SEP;
3851+
List<String> allEntries = new ArrayList<>(); // all entries excluding the directory entry
3852+
List<String> zipEntries = getZipFile().listZipEntries();
3853+
for (String zipEntry : zipEntries) {
3854+
if (zipEntry.startsWith(walletPrefix) && !zipEntry.equals(walletPrefix)) {
3855+
allEntries.add(zipEntry);
3856+
}
3857+
}
3858+
3859+
String firstEntry = allEntries.isEmpty() ? null : allEntries.get(0);
3860+
if((firstEntry != null) && firstEntry.toLowerCase().endsWith(".zip")) {
3861+
try (ZipInputStream zipStream = new ZipInputStream(getZipFile().getZipEntry(firstEntry))) {
3862+
ZipEntry zipEntry;
3863+
while ((zipEntry = zipStream.getNextEntry()) != null) {
3864+
walletEntries.add(zipEntry.getName());
3865+
zipStream.closeEntry();
3866+
}
3867+
3868+
} catch(IOException e) {
3869+
WLSDeployArchiveIOException aioe = new WLSDeployArchiveIOException("WLSDPLY-01467", firstEntry,
3870+
getArchiveFileName(), e.getLocalizedMessage());
3871+
LOGGER.throwing(aioe);
3872+
throw aioe;
3873+
}
3874+
} else {
3875+
// just return the entry names that were found in the archive directory
3876+
for(String entry: allEntries) {
3877+
String entryName = entry.substring(walletPath.length() + 1);
3878+
walletEntries.add(entryName);
3879+
}
3880+
}
3881+
}
3882+
3883+
LOGGER.exiting(CLASS, METHOD, walletEntries);
3884+
return walletEntries;
3885+
}
3886+
38393887
/**
38403888
* Add a database wallet to the archive.
38413889
*

core/src/main/python/wlsdeploy/tool/util/archive_helper.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,22 @@ def has_rcu_wallet_path(self):
539539
or archive_file.containsPath(WLSDeployArchive.DEPRECATED_RCU_WALLET_PATH)):
540540
return True
541541

542+
def get_wallet_entries(self, wallet_path):
543+
_method_name = 'get_wallet_entries'
544+
self.__logger.entering(class_name=self.__class_name, method_name=_method_name)
545+
546+
archive = None
547+
entries = []
548+
for archive_file in self.__archive_files[::-1]:
549+
wallet_entries = archive_file.getDatabaseWalletEntries(wallet_path)
550+
if wallet_entries:
551+
archive = archive_file
552+
entries = wallet_entries
553+
break
554+
555+
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name, result=(archive, entries))
556+
return archive, entries
557+
542558
def extract_opss_wallet(self):
543559
"""
544560
Extract the and unzip the OPSS wallet, if present, and return the path to the wallet directory.

core/src/main/python/wlsdeploy/tool/validate/domain_info_validator.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
DRIVER_PARAMS_TRUSTSTORE_PROPERTY
2828
]
2929

30+
3031
class DomainInfoValidator(ModelValidator):
3132
"""
3233
Class for validating the domainInfo section of a model file
@@ -85,8 +86,7 @@ def _validate_single_path_in_archive(self, path, attribute_name, model_folder_pa
8586
Extend this method to allow wallet paths to be in a wallet zip in the archive.
8687
"""
8788
if attribute_name in WALLET_PATH_ATTRIBUTES:
88-
if WLSDeployArchive.isPathIntoArchive(path):
89-
# TODO: check inside the wallet zip
89+
if self.__is_path_in_zipped_archive_wallet(path):
9090
return
9191

9292
ModelValidator._validate_single_path_in_archive(self, path, attribute_name, model_folder_path)
@@ -168,3 +168,20 @@ def _validate_single_server_group_target_limits_value(self, key, value, model_fo
168168
self._logger.severe('WLSDPLY-05035', key, str_helper.to_string(value), model_folder_path,
169169
str_helper.to_string(type(value)),
170170
class_name=_class_name, method_name=_method_name)
171+
172+
def __is_path_in_zipped_archive_wallet(self, path):
173+
if not WLSDeployArchive.isPathIntoArchive(path) or not self._archive_helper:
174+
return False
175+
176+
if self._archive_helper.contains_file(path):
177+
# the file is directly in the archive, return for regular validation
178+
return False
179+
180+
last_slash = path.rfind('/')
181+
wallet_path = ''
182+
if last_slash != -1:
183+
wallet_path = path[:last_slash]
184+
file_name = path[last_slash + 1:]
185+
archive, entries = self._archive_helper.get_wallet_entries(wallet_path)
186+
187+
return file_name in entries

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ WLSDPLY-01464=Database wallet found in deprecated archive path {0}, should be ch
254254
The archive contents have been extracted and assigned to that path.
255255
WLSDPLY-01465=Failed to add WebLogic Remote Console Extension file {0} to archive file {1} because the archive file already contains this entry at {2}.
256256
WLSDPLY-01466=Failed to remove WebLogic Remote Console Extension file {0} from archive file {1} because the archive file did not contain {2}.
257+
WLSDPLY-01467=Unable to open the database wallet zip for path {0} in archive file {1}: {2}
257258

258259
# oracle.weblogic.deploy.util.WLSDeployZipFile.java
259260
WLSDPLY-01500=The zip file {0} has the saved entry {1}

0 commit comments

Comments
 (0)