Skip to content

Commit bc94bd5

Browse files
committed
Merge branch 'secure-production-fixes' into 'main'
Set production and secure modes before initial domain write See merge request weblogic-cloud/weblogic-deploy-tooling!1777
2 parents aaa315c + 7dbbd06 commit bc94bd5

File tree

6 files changed

+90
-7
lines changed

6 files changed

+90
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2017, 2025, Oracle 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 array
@@ -535,7 +535,7 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
535535
if attribute_info and not self.__is_wlst_attribute_read_only_or_ignored(location, attribute_info):
536536
wlst_attribute_name = attribute_info[WLST_NAME]
537537
uses_path_tokens = USES_PATH_TOKENS in attribute_info and \
538-
string_utils.to_boolean(attribute_info[USES_PATH_TOKENS])
538+
alias_utils.convert_boolean(attribute_info[USES_PATH_TOKENS])
539539

540540
data_type = attribute_info[WLST_TYPE]
541541
if data_type == 'password':

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2017, 2025, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import os
@@ -10,6 +10,7 @@
1010
from weblogic.security.internal import SerializedSystemIni
1111
from weblogic.security.internal.encryption import ClearOrEncryptedService
1212

13+
from wlsdeploy.aliases import alias_utils
1314
from wlsdeploy.aliases.location_context import LocationContext
1415
from wlsdeploy.aliases.model_constants import ADMIN_PASSWORD
1516
from wlsdeploy.aliases.model_constants import ADMIN_SERVER_NAME
@@ -36,6 +37,8 @@
3637
from wlsdeploy.aliases.model_constants import PRODUCTION_MODE_ENABLED
3738
from wlsdeploy.aliases.model_constants import RESOURCE_GROUP
3839
from wlsdeploy.aliases.model_constants import RESOURCE_GROUP_TEMPLATE
40+
from wlsdeploy.aliases.model_constants import SECURE_MODE
41+
from wlsdeploy.aliases.model_constants import SECURE_MODE_ENABLED
3942
from wlsdeploy.aliases.model_constants import SECURITY
4043
from wlsdeploy.aliases.model_constants import SECURITY_CONFIGURATION
4144
from wlsdeploy.aliases.model_constants import SERVER
@@ -551,6 +554,8 @@ def __set_core_domain_params(self):
551554
use_sample_db = str_helper.to_string(use_sample_db)
552555
self.wlst_helper.set_option_if_needed(USE_SAMPLE_DATABASE, use_sample_db)
553556

557+
self.__set_secure_and_production_modes()
558+
554559
self.__set_domain_name()
555560
self.__set_admin_password()
556561
self.__set_admin_server_name()
@@ -946,6 +951,42 @@ def __set_admin_server_name(self):
946951
else:
947952
self._admin_server_name = self.__default_admin_server_name
948953

954+
def __set_secure_and_production_modes(self):
955+
"""
956+
Set secure and production mode enabled before initial writeDomain
957+
"""
958+
root_location = LocationContext()
959+
domain_name_token = self.aliases.get_name_token(root_location)
960+
root_location.add_name_token(domain_name_token, self._domain_name)
961+
962+
production_mode_enabled = dictionary_utils.get_element(self._topology, PRODUCTION_MODE_ENABLED)
963+
if production_mode_enabled is not None:
964+
wlst_name = self.aliases.get_wlst_attribute_name(root_location, PRODUCTION_MODE_ENABLED)
965+
production_mode_enabled = alias_utils.convert_boolean(production_mode_enabled)
966+
self.wlst_helper.set(wlst_name, production_mode_enabled)
967+
968+
if production_mode_enabled: # check for secure mode specified, may be disabled
969+
security_config_folder = dictionary_utils.get_dictionary_element(self._topology, SECURITY_CONFIGURATION)
970+
secure_mode_folder = dictionary_utils.get_dictionary_element(security_config_folder, SECURE_MODE)
971+
secure_mode_enabled = dictionary_utils.get_element(secure_mode_folder, SECURE_MODE_ENABLED)
972+
if secure_mode_enabled is not None:
973+
secure_mode_enabled = alias_utils.convert_boolean(secure_mode_enabled)
974+
secure_location = LocationContext(root_location)
975+
secure_location.append_location(SECURITY_CONFIGURATION)
976+
977+
# secure mode doesn't exist in older WLS versions
978+
code, message = self.aliases.is_valid_model_folder_name(secure_location, SECURE_MODE)
979+
if code == ValidationCodes.VALID:
980+
existing_subfolder_names = deployer_utils.get_existing_object_list(secure_location, self.aliases)
981+
deployer_utils.create_and_cd(secure_location, existing_subfolder_names, self.aliases)
982+
secure_location.append_location(SECURE_MODE)
983+
existing_subfolder_names = deployer_utils.get_existing_object_list(secure_location, self.aliases)
984+
deployer_utils.create_and_cd(secure_location, existing_subfolder_names, self.aliases)
985+
986+
wlst_name = self.aliases.get_wlst_attribute_name(secure_location, SECURE_MODE_ENABLED)
987+
self.wlst_helper.set(wlst_name, secure_mode_enabled)
988+
self.wlst_helper.cd('/')
989+
949990
def __set_domain_attributes(self):
950991
"""
951992
Set the Domain attributes
@@ -989,7 +1030,7 @@ def __create_boot_dot_properties(self):
9891030
return
9901031

9911032
if PRODUCTION_MODE_ENABLED in self._topology:
992-
if string_utils.to_boolean(self._topology[PRODUCTION_MODE_ENABLED]):
1033+
if alias_utils.convert_boolean(self._topology[PRODUCTION_MODE_ENABLED]):
9931034
return
9941035

9951036
system_ini = SerializedSystemIni.getEncryptionService(self._domain_home)

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2023, 2025, Oracle 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
from java.lang import Boolean
@@ -35,13 +35,16 @@
3535
from wlsdeploy.aliases.model_constants import RCU_PREFIX
3636
from wlsdeploy.aliases.model_constants import RCU_SCHEMA_PASSWORD
3737
from wlsdeploy.aliases.model_constants import REALM
38+
from wlsdeploy.aliases.model_constants import SECURE_MODE
3839
from wlsdeploy.aliases.model_constants import SECURITY
3940
from wlsdeploy.aliases.model_constants import SECURITY_CONFIGURATION
41+
from wlsdeploy.aliases.model_constants import SERVER_START_MODE
4042
from wlsdeploy.aliases.model_constants import STORE_TYPE_SSO
4143
from wlsdeploy.aliases.model_constants import SYSTEM_PASSWORD_VALIDATOR
4244
from wlsdeploy.aliases.model_constants import TNS_ENTRY
4345
from wlsdeploy.aliases.model_constants import TOPOLOGY
4446
from wlsdeploy.aliases.model_constants import USER
47+
from wlsdeploy.aliases.validation_codes import ValidationCodes
4548
from wlsdeploy.exception import exception_helper
4649
from wlsdeploy.logging.platform_logger import PlatformLogger
4750
from wlsdeploy.tool.create import rcudbinfo_helper
@@ -98,6 +101,17 @@ def validate_domain_info_section(self, model_dict):
98101
self._model_context.get_model_file(), class_name=self._class_name, method_name=_method_name)
99102

100103
domain_info_dict = dictionary_utils.get_dictionary_element(model_dict, DOMAIN_INFO)
104+
105+
# secure mode doesn't exist in older WLS versions.
106+
# valid start mode values were already checked in regular validation.
107+
server_start_mode = dictionary_utils.get_element(domain_info_dict, SERVER_START_MODE)
108+
if server_start_mode == 'secure':
109+
secure_location = LocationContext().append_location(SECURITY_CONFIGURATION)
110+
code, _message = self._aliases.is_valid_model_folder_name(secure_location, SECURE_MODE)
111+
if code != ValidationCodes.VALID:
112+
self._logger.severe('WLSDPLY-05314', server_start_mode, DOMAIN_INFO, SERVER_START_MODE,
113+
class_name=self._class_name, method_name=_method_name)
114+
101115
rcu_info_dict = dictionary_utils.get_dictionary_element(domain_info_dict, RCU_DB_INFO)
102116
self.__validate_rcu_db_info_section(rcu_info_dict)
103117

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2024, 2025, Oracle 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
from oracle.weblogic.deploy.create import RCURunner
@@ -23,6 +23,7 @@
2323
from wlsdeploy.aliases.model_constants import RCU_TEMP_TBLSPACE
2424
from wlsdeploy.aliases.model_constants import REMOTE_RESOURCE
2525
from wlsdeploy.aliases.model_constants import SERVER_GROUP_TARGETING_LIMITS
26+
from wlsdeploy.aliases.model_constants import SERVER_START_MODE
2627
from wlsdeploy.aliases.model_constants import STORE_TYPE_SSO
2728
from wlsdeploy.aliases.model_constants import WLS_POLICIES
2829
from wlsdeploy.aliases.model_constants import WLS_ROLES
@@ -74,6 +75,12 @@
7475
't3s'
7576
]
7677

78+
SERVER_START_MODES = [
79+
'dev',
80+
'prod',
81+
'secure'
82+
]
83+
7784
DEPRECATED_DB_TYPES = [
7885
RCURunner.ORACLE_DB_TYPE,
7986
RCURunner.ORACLE_ATP_DB_TYPE,
@@ -135,12 +142,21 @@ def _validate_attribute(self, attribute_name, attribute_value, valid_attr_infos,
135142
"""
136143
Extend this method to perform additional validation of the targeting limits attributes.
137144
"""
145+
_method_name = "_validate_attribute"
138146
ModelValidator._validate_attribute(self, attribute_name, attribute_value, valid_attr_infos,
139147
path_tokens_attr_keys, model_folder_path, validation_location)
140148

141149
if attribute_name in [SERVER_GROUP_TARGETING_LIMITS, DYNAMIC_CLUSTER_SERVER_GROUP_TARGETING_LIMITS]:
142150
self.__validate_server_group_targeting_limits(attribute_name, attribute_value, model_folder_path)
143151

152+
if attribute_name == SERVER_START_MODE:
153+
# None is returned if tokens remain, already validated depending on validation mode
154+
server_start_mode = self._resolve_value(attribute_value, SERVER_START_MODE)
155+
if server_start_mode and (server_start_mode not in SERVER_START_MODES):
156+
self._logger.severe(
157+
'WLSDPLY-05302', server_start_mode, DOMAIN_INFO, SERVER_START_MODE,
158+
', '.join(SERVER_START_MODES), class_name=_class_name, method_name=_method_name)
159+
144160
# Override
145161
def _validate_single_path_in_archive(self, path, attribute_name, model_folder_path):
146162
"""

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2017, 2025, Oracle 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

@@ -627,6 +627,17 @@ def _get_validation_value(self, model_dict, attribute_name):
627627
:return: the value to use for additional validation checks
628628
"""
629629
value = dictionary_utils.get_element(model_dict, attribute_name)
630+
return self._resolve_value(value, attribute_name)
631+
632+
def _resolve_value(self, value, attribute_name):
633+
"""
634+
Get the resolved value of the specified attribute, de-tokenizing as needed.
635+
If unresolved tokens remain in the value, None is returned to prevent further checks.
636+
Validation has already checked for unresolved variables, depending on validation mode.
637+
:param value: the value to be examined
638+
:param attribute_name: the name of the attribute to be examined, for logging
639+
:return: the value to use for additional validation checks
640+
"""
630641
if isinstance(value, (str, unicode)) and variables.has_tokens(value):
631642
value = variables.substitute_attribute(value, self._variable_properties, self._model_context,
632643
attribute_name=attribute_name)

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
@@ -689,6 +689,7 @@ WLSDPLY-05310={0} field {1} must be specified if {2} is specified
689689
WLSDPLY-05311=Prepended path {0} for {1} field {2} is an archive path, and no archive file is specified
690690
WLSDPLY-05312=Prepended path {0} for {1} field {2} is an archive path, and not found in any archive file
691691
WLSDPLY-05313=Value {0} is invalid for {1} {2} field {3}, must be one of {4}
692+
WLSDPLY-05314=Value {0} is invalid for {1} field {2}, secure mode is not supported in this WLS version
692693

693694
# oracle/weblogic/deploy/validate/PasswordValidator.java
694695
WLSDPLY-05400=Password validation failed because the username was not provided

0 commit comments

Comments
 (0)