Skip to content

Commit 67cacb6

Browse files
committed
Merge branch 'main' into WDT-599-filters
2 parents 9eecfcb + 873ad79 commit 67cacb6

File tree

20 files changed

+354
-39
lines changed

20 files changed

+354
-39
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.util;
@@ -854,6 +854,15 @@ public void extractDomainBinScript(String archivePath, File extractToLocation) t
854854
extractFileFromZip(archivePath, ARCHIVE_DOM_BIN_TARGET_DIR, "", extractToLocation);
855855
LOGGER.exiting(CLASS, METHOD);
856856
}
857+
858+
public void removeDomainBinScripts() throws WLSDeployArchiveIOException {
859+
final String METHOD = "removeDomainBinScripts";
860+
861+
LOGGER.entering(CLASS, METHOD);
862+
getZipFile().removeZipEntries(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP);
863+
LOGGER.exiting(CLASS, METHOD);
864+
}
865+
857866
/**
858867
* This method adds a classpath library to the archive. If a library with the same name already exists, this
859868
* method assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding

core/src/main/python/prepare_model.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
]
3737

3838
__optional_arguments = [
39-
CommandLineArgUtil.VARIABLE_FILE_SWITCH
39+
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
40+
CommandLineArgUtil.ARCHIVE_FILE_SWITCH
4041
]
4142

4243

@@ -55,8 +56,9 @@ def __process_args(args):
5556
target_configuration_helper.process_target_arguments(argument_map)
5657

5758
model_context = ModelContext(_program_name, argument_map)
58-
# override this check, since archive file is not supplied here
59-
model_context.get_validate_configuration().set_allow_unresolved_archive_references(True)
59+
if model_context.get_archive_file_name() is None:
60+
# override this check, if archive file is not supplied
61+
model_context.get_validate_configuration().set_allow_unresolved_archive_references(True)
6062
return model_context
6163

6264

core/src/main/python/wlsdeploy/aliases/alias_entries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class AliasEntries(object):
112112
'VirtualHost',
113113
'VirtualTarget',
114114
'WSReliableDeliveryPolicy',
115+
'WebserviceSecurity',
115116
'XMLEntityCache',
116117
'XMLRegistry'
117118
]
@@ -646,13 +647,13 @@ def get_wlst_mbean_type_for_location(self, location):
646647
:raises AliasException: if an error occurs
647648
"""
648649
_method_name = 'get_wlst_mbean_type_for_location'
650+
_logger.entering(str(location), class_name=_class_name, method_name=_method_name)
649651

650652
# some callers use this method to check for location valid.
651653
# they should call is_model_location_valid(location) directly instead.
652654
if not self.is_model_location_valid(location):
653655
return None
654656

655-
_logger.entering(str(location), class_name=_class_name, method_name=_method_name)
656657
folder_dict = self.__get_dictionary_for_location(location, False)
657658
if folder_dict is None:
658659
wlst_type = None

core/src/main/python/wlsdeploy/aliases/model_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
WEB_SERVICE_PHYSICAL_STORE = 'WebServicePhysicalStore'
315315
WEB_SERVICE_REQUEST_BUFFERING_QUEUE = 'WebServiceRequestBufferingQueue'
316316
WEB_SERVICE_RESPONSE_BUFFERING_QUEUE = 'WebServiceResponseBufferingQueue'
317+
WEB_SERVICE_SECURITY = 'WebserviceSecurity'
317318
WEBLOGIC_CERT_PATH_PROVIDER = 'WebLogicCertPathProvider'
318319
WORK_MANAGER = "WorkManager"
319320
WLDF_INSTRUMENTATION_MONITOR = "WLDFInstrumentationMonitor"

core/src/main/python/wlsdeploy/tool/create/atp_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def fix_jps_config(rcu_db_info, model_context):
6868

6969
def get_atp_connect_string(tnsnames_ora_path, tns_sid_name):
7070
try:
71-
f = open(tnsnames_ora_path, "r+")
71+
f = open(tnsnames_ora_path, "r")
7272
try:
7373
text = f.read()
7474
finally:

core/src/main/python/wlsdeploy/tool/create/domain_creator.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
from wlsdeploy.aliases.model_constants import VIRTUAL_TARGET
7272
from wlsdeploy.aliases.model_constants import WLS_USER_PASSWORD_CREDENTIAL_MAPPINGS
7373
from wlsdeploy.aliases.model_constants import WS_RELIABLE_DELIVERY_POLICY
74+
from wlsdeploy.aliases.model_constants import WEB_SERVICE_SECURITY
7475
from wlsdeploy.aliases.model_constants import XML_ENTITY_CACHE
7576
from wlsdeploy.aliases.model_constants import XML_REGISTRY
7677
from wlsdeploy.exception import exception_helper
@@ -699,6 +700,9 @@ def __create_mbeans_used_by_topology_mbeans(self, topology_folder_list):
699700
self.__create_xml_registry(location)
700701
topology_folder_list.remove(XML_REGISTRY)
701702

703+
self.__create_ws_security(location)
704+
topology_folder_list.remove(WEB_SERVICE_SECURITY)
705+
702706
def __create_security_folder(self):
703707
"""
704708
Create the the security objects if any. The security information
@@ -777,6 +781,20 @@ def __create_xml_registry(self, location):
777781
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
778782
return
779783

784+
def __create_ws_security(self, location):
785+
"""
786+
Create the WebserviceSecurity objects, if any.
787+
:param location: the current location
788+
"""
789+
_method_name = '__create_ws_security'
790+
self.logger.entering(str(location), class_name=self.__class_name, method_name=_method_name)
791+
ws_security = dictionary_utils.get_dictionary_element(self._topology, WEB_SERVICE_SECURITY)
792+
793+
if len(ws_security) > 0:
794+
self._create_named_mbeans(WEB_SERVICE_SECURITY, ws_security, location, log_created=True)
795+
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
796+
return
797+
780798
def __create_machines(self, location):
781799
"""
782800
Create the /Machine and /UnixMachine folder objects, if any.

core/src/main/python/wlsdeploy/tool/discover/domain_info_discoverer.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import glob
@@ -109,31 +109,35 @@ def get_domain_libs(self):
109109
def get_user_env_scripts(self):
110110
"""
111111
Look for the user overrides scripts run in setDomainEnv in the domain bin directory
112+
If discover is running with the -target <type> do not collect the domainBin scripts
112113
:raise: DiscoverException: an unexpected exception occurred writing a jar file to the archive file
113114
"""
114115
_method_name = 'get_user_env_scripts'
115116
_logger.entering(class_name=_class_name, method_name=_method_name)
116-
archive_file = self._model_context.get_archive_file()
117-
domain_bin = self._convert_path('bin')
118117
entries = []
119-
if os.path.isdir(domain_bin):
120-
search_directory = FileUtils.fixupFileSeparatorsForJython(os.path.join(domain_bin, "setUserOverrides*.*"))
121-
_logger.finer('WLSDPLY-06425', search_directory, class_name=_class_name, method_name=_method_name)
122-
file_list = glob.glob(search_directory)
123-
if file_list:
124-
_logger.finer('WLSDPLY-06423', domain_bin, class_name=_class_name, method_name=_method_name)
125-
for entry in file_list:
126-
try:
127-
updated_name = archive_file.addDomainBinScript(File(entry))
128-
except WLSDeployArchiveIOException, wioe:
129-
de = exception_helper.create_discover_exception('WLSDPLY-06426', entry,
130-
wioe.getLocalizedMessage())
131-
_logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
132-
raise de
133-
134-
entries.append(updated_name)
135-
_logger.finer('WLSDPLY-06424', entry, updated_name, class_name=_class_name,
136-
method_name=_method_name)
118+
if self._model_context.get_target_configuration().exclude_domain_bin_contents():
119+
_logger.fine('WLSDPLY-06427', class_name=_class_name, method_name=_method_name)
120+
else:
121+
archive_file = self._model_context.get_archive_file()
122+
domain_bin = self._convert_path('bin')
123+
if os.path.isdir(domain_bin):
124+
search_directory = FileUtils.fixupFileSeparatorsForJython(os.path.join(domain_bin, "setUserOverrides*.*"))
125+
_logger.finer('WLSDPLY-06425', search_directory, class_name=_class_name, method_name=_method_name)
126+
file_list = glob.glob(search_directory)
127+
if file_list:
128+
_logger.finer('WLSDPLY-06423', domain_bin, class_name=_class_name, method_name=_method_name)
129+
for entry in file_list:
130+
try:
131+
updated_name = archive_file.addDomainBinScript(File(entry))
132+
except WLSDeployArchiveIOException, wioe:
133+
de = exception_helper.create_discover_exception('WLSDPLY-06426', entry,
134+
wioe.getLocalizedMessage())
135+
_logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
136+
raise de
137+
138+
entries.append(updated_name)
139+
_logger.finer('WLSDPLY-06424', entry, updated_name, class_name=_class_name,
140+
method_name=_method_name)
137141

138142
_logger.exiting(class_name=_class_name, method_name=_method_name, result=entries)
139143
return model_constants.DOMAIN_SCRIPTS, entries

core/src/main/python/wlsdeploy/tool/discover/topology_discoverer.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def discover(self):
112112
model_folder_name, folder_result = self._get_xml_registries()
113113
discoverer.add_to_model_if_not_empty(self._dictionary, model_folder_name, folder_result)
114114

115+
model_folder_name, folder_result = self._get_ws_securities()
116+
discoverer.add_to_model_if_not_empty(self._dictionary, model_folder_name, folder_result)
117+
115118
_logger.exiting(class_name=_class_name, method_name=_method_name)
116119
return self._dictionary
117120

@@ -550,6 +553,32 @@ def _get_xml_registries(self):
550553
_logger.exiting(class_name=_class_name, method_name=_method_name, result=model_top_folder_name)
551554
return model_top_folder_name, result
552555

556+
def _get_ws_securities(self):
557+
"""
558+
Discover the Webservice Security configuration for the domain
559+
:return: model name for the folder: dictionary containing the discovered webservice security
560+
"""
561+
_method_name = '_get_ws_securities'
562+
_logger.entering(class_name=_class_name, method_name=_method_name)
563+
model_top_folder_name = model_constants.WEB_SERVICE_SECURITY
564+
result = OrderedDict()
565+
location = LocationContext(self._base_location)
566+
location.append_location(model_top_folder_name)
567+
wssecurities = self._find_names_in_folder(location)
568+
if wssecurities is not None:
569+
_logger.info('WLSDPLY-06649', len(wssecurities), class_name=_class_name, method_name=_method_name)
570+
name_token = self._aliases.get_name_token(location)
571+
for wssecurity in wssecurities:
572+
_logger.info('WLSDPLY-06650', wssecurity, class_name=_class_name, method_name=_method_name)
573+
location.add_name_token(name_token, wssecurity)
574+
result[wssecurity] = OrderedDict()
575+
self._populate_model_parameters(result[wssecurity], location)
576+
self._discover_subfolders(result[wssecurity], location)
577+
location.remove_name_token(name_token)
578+
579+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=model_top_folder_name)
580+
return model_top_folder_name, result
581+
553582
def _massage_security_credential(self, result, location):
554583
_method_name = 'massage_security_credential'
555584
# Determine if the SecurityConfiguration/CredentialEncrypted can be removed

core/src/main/python/wlsdeploy/tool/prepare/model_preparer.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
from wlsdeploy.aliases.aliases import Aliases
1414
from wlsdeploy.aliases.location_context import LocationContext
1515
from wlsdeploy.aliases.model_constants import DOMAIN_INFO
16+
from wlsdeploy.aliases.model_constants import DOMAIN_SCRIPTS
1617
from wlsdeploy.aliases.wlst_modes import WlstModes
1718
from wlsdeploy.exception import exception_helper
1819
from wlsdeploy.exception.expection_types import ExceptionType
1920
from wlsdeploy.logging.platform_logger import PlatformLogger
2021
from wlsdeploy.tool.util import filter_helper
22+
from wlsdeploy.tool.util.archive_helper import ArchiveHelper
2123
from wlsdeploy.tool.util.credential_injector import CredentialInjector
2224
from wlsdeploy.tool.util.variable_injector import VARIABLE_FILE_UPDATE
2325
from wlsdeploy.tool.util.variable_injector import VariableInjector
@@ -221,6 +223,10 @@ def _apply_filter_and_inject_variable(self, model_dict, model_context):
221223
else:
222224
credential_properties = self.credential_injector.get_variable_cache()
223225

226+
if target_config.exclude_domain_bin_contents() and DOMAIN_INFO in model_dict \
227+
and DOMAIN_SCRIPTS in model_dict[DOMAIN_INFO]:
228+
del model_dict[DOMAIN_INFO][DOMAIN_SCRIPTS]
229+
224230
variable_injector = VariableInjector(_program_name, model_dict, model_context,
225231
WebLogicHelper(self._logger).get_actual_weblogic_version(),
226232
credential_properties)
@@ -279,6 +285,23 @@ def _clean_variable_files(self, merged_model_dictionary):
279285
self._logger.warning('WLSDPLY-05803', e.getLocalizedMessage(),
280286
class_name=_class_name, method_name=_method_name)
281287

288+
def _clean_archive_files(self):
289+
"""
290+
Remove any content necessary from the archive file.
291+
"""
292+
_method_name = '_clean_archive_files'
293+
294+
archive_file_name = self.model_context.get_archive_file_name()
295+
if archive_file_name is None:
296+
return
297+
298+
# If the archive file(s) exist, always make a copy even if we aren't filtering them
299+
archive_helper = ArchiveHelper(archive_file_name, None, self._logger, exception_helper.ExceptionType.PREPARE)
300+
archive_helper = archive_helper.copy_archives_to_target_directory(self.model_context.get_output_dir())
301+
302+
if self.model_context.get_target_configuration().exclude_domain_bin_contents():
303+
archive_helper.remove_domain_scripts()
304+
282305
def prepare_models(self):
283306
"""
284307
Replace password attributes in each model file with secret tokens, and write each model.
@@ -327,9 +350,10 @@ def prepare_models(self):
327350
if variable_file is not None and not os.path.exists(variable_file):
328351
variable_file = None
329352

353+
archive_file_name = self.model_context.get_archive_file_name()
330354
return_code = validator.validate_in_tool_mode(model_dictionary,
331355
variables_file_name=variable_file,
332-
archive_file_name=None)
356+
archive_file_name=archive_file_name)
333357

334358
if return_code == Validator.ReturnCode.STOP:
335359
ex = exception_helper.create_prepare_exception('WLSDPLY-05804', model_file_name)
@@ -359,6 +383,7 @@ def prepare_models(self):
359383
filter_helper.apply_filters(merged_model_dictionary, "discover", self.model_context)
360384
self.credential_injector.filter_unused_credentials(merged_model_dictionary)
361385
self._clean_variable_files(merged_model_dictionary)
386+
self._clean_archive_files()
362387

363388
# use a merged, substituted, filtered model to get domain name and create additional target output.
364389
full_model_dictionary = cla_helper.load_model(_program_name, self.model_context, self._aliases,

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5+
import os
6+
import shutil
7+
58
from java.io import File
69
from java.lang import IllegalArgumentException
710
from java.lang import IllegalStateException
@@ -359,6 +362,25 @@ def extract_domain_bin_script(self, script_path):
359362
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name)
360363
return
361364

365+
def remove_domain_scripts(self):
366+
"""
367+
Remove any domain bin scripts from the archive.
368+
:raises: BundleAwareException of the appropriate type: if an error occurs
369+
"""
370+
_method_name = 'remove_domain_scripts'
371+
372+
self.__logger.entering(class_name=self.__class_name, method_name=_method_name)
373+
for archive_file in self.__archive_files:
374+
try:
375+
archive_file.removeDomainBinScripts()
376+
except (WLSDeployArchiveIOException, IllegalArgumentException), e:
377+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19311',
378+
archive_file.getArchiveFileName(), e.getLocalizedMessage(),
379+
error=e)
380+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
381+
raise ex
382+
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name)
383+
362384
def get_archive_entries(self):
363385
"""
364386
Get the entries from all the archives.
@@ -439,6 +461,46 @@ def get_manifest(self, source_path):
439461
return archive.getManifest(source_path)
440462
return None
441463

464+
def copy_archives_to_target_directory(self, target_directory):
465+
"""
466+
Makes a copy of the specified archive file(s) to the target directory.
467+
:param target_directory: the directory to which the archive file(s) will be copied
468+
:return: new ArchiveHelper for the new archive file(s)
469+
:raises: BundleAwareException of the appropriate type: if an error occurred while copying the file
470+
"""
471+
_method_name = 'copy_archives_to_target_directory'
472+
self.__logger.entering(target_directory, class_name=self.__class_name, method_name=_method_name)
473+
474+
file_names = self.__archive_files_text.split(CommandLineArgUtil.ARCHIVE_FILES_SEPARATOR)
475+
new_file_names = []
476+
for file_name in file_names:
477+
new_file_name = self._copy_file(file_name, target_directory)
478+
new_file_names.append(new_file_name)
479+
new_archive_file_text = CommandLineArgUtil.ARCHIVE_FILES_SEPARATOR.join(new_file_names)
480+
return ArchiveHelper(new_archive_file_text, self.__domain_home, self.__logger, self.__exception_type)
481+
482+
def _copy_file(self, source_file_name, target_directory):
483+
"""
484+
Make a copy of the source file to the target directory
485+
:param source_file_name: source file name
486+
:param target_directory: target directory name
487+
:return: file name of the new file in the target directory
488+
:raises: BundleAwareException of the appropriate type: if an error occurred while copying the file
489+
"""
490+
_method_name = '_copy_file'
491+
492+
self.__logger.entering(source_file_name, target_directory, class_name=self.__class_name, method_name=_method_name)
493+
base_name = os.path.basename(source_file_name)
494+
target_file_name = os.path.join(target_directory, base_name)
495+
try:
496+
shutil.copyfile(source_file_name, target_file_name)
497+
except Exception, e:
498+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19312', source_file_name,
499+
target_file_name, e.getLocalizedMessage(), error=e)
500+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
501+
raise ex
502+
return target_file_name
503+
442504
def _find_archive_for_path(self, path, required=False):
443505
"""
444506
Find the archive file containing the specified path.

0 commit comments

Comments
 (0)