Skip to content

Commit d9a6fb8

Browse files
authored
Encrypt and decrypt password elements in RCU DB info (#357)
* JIRA WDT-262 - Expose decrypt method in alias_helper * JIRA WDT-262 - Encrypt model and variables using aliases instead of static list * JIRA WDT-262 - Encrypt model and variables using aliases instead of static list * JIRA WDT-262 - Encrypt model and variables using aliases instead of static list * JIRA WDT-262 - Encrypt model and variables using aliases instead of static list * JIRA WDT-262 - Use RCU DB info object to decrypt password fields as needed * JIRA WDT-262 - Allow boolean and default values for useATP field; move model checks into RCU DB helper
1 parent 2598d74 commit d9a6fb8

File tree

12 files changed

+429
-347
lines changed

12 files changed

+429
-347
lines changed

core/src/main/python/create.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030
from wlsdeploy.aliases import model_constants
3131
from wlsdeploy.aliases.wlst_modes import WlstModes
3232
from wlsdeploy.exception import exception_helper
33+
from wlsdeploy.exception.expection_types import ExceptionType
3334
from wlsdeploy.logging.platform_logger import PlatformLogger
35+
from wlsdeploy.tool.create.rcudbinfo_helper import RcuDbInfo
3436
from wlsdeploy.tool.create.domain_creator import DomainCreator
3537
from wlsdeploy.tool.create.domain_typedef import DomainTypedef
3638
from wlsdeploy.tool.create.domain_typedef import CREATE_DOMAIN
3739
from wlsdeploy.tool.util import filter_helper
40+
from wlsdeploy.tool.util.alias_helper import AliasHelper
3841
from wlsdeploy.tool.validate.validator import Validator
3942
from wlsdeploy.util import getcreds
4043
from wlsdeploy.util import tool_exit
@@ -332,15 +335,15 @@ def validate_model(model_dictionary, model_context, aliases):
332335
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
333336

334337

335-
def validateRCUArgsAndModel(model_context, model):
338+
def validateRCUArgsAndModel(model_context, model, alias_helper):
336339
has_atpdbinfo = 0
337340
domain_info = model[model_constants.DOMAIN_INFO]
338341
if domain_info is not None:
339342
if model_constants.RCU_DB_INFO in domain_info:
340-
rcu_db_info = domain_info[model_constants.RCU_DB_INFO]
341-
has_tns_admin = atp_helper.has_tns_admin(rcu_db_info)
342-
has_regular_db = atp_helper.is_regular_db(rcu_db_info)
343-
has_atpdbinfo = atp_helper.has_atpdbinfo(rcu_db_info)
343+
rcu_db_info = RcuDbInfo(alias_helper, domain_info[model_constants.RCU_DB_INFO])
344+
has_tns_admin = rcu_db_info.has_tns_admin()
345+
has_regular_db = rcu_db_info.is_regular_db()
346+
has_atpdbinfo = rcu_db_info.has_atpdbinfo()
344347

345348
if model_context.get_archive_file_name() and not has_regular_db:
346349
System.setProperty('oracle.jdbc.fanEnabled', 'false')
@@ -424,14 +427,15 @@ def main(args):
424427
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
425428

426429
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
430+
alias_helper = AliasHelper(aliases, __logger, ExceptionType.CREATE)
427431
validate_model(model, model_context, aliases)
428432

429433
if filter_helper.apply_filters(model, "create"):
430434
# if any filters were applied, re-validate the model
431435
validate_model(model, model_context, aliases)
432436
try:
433437

434-
has_atp = validateRCUArgsAndModel(model_context, model)
438+
has_atp = validateRCUArgsAndModel(model_context, model, alias_helper)
435439
# check if there is an atpwallet and extract in the domain dir
436440
# it is to support non JRF domain but user wants to use ATP database
437441
archive_file_name = model_context.get_archive_file_name()
@@ -446,7 +450,10 @@ def main(args):
446450
creator.create()
447451

448452
if has_atp:
449-
atp_helper.fix_jps_config(model, model_context)
453+
rcu_properties_map = model[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO]
454+
rcu_db_info = RcuDbInfo(alias_helper, rcu_properties_map)
455+
atp_helper.fix_jps_config(rcu_db_info, model_context)
456+
450457
except WLSDeployArchiveIOException, ex:
451458
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
452459
class_name=_class_name, method_name=_method_name)

core/src/main/python/encrypt.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
55
The main module for the WLSDeploy tool to encrypt passwords.
@@ -21,9 +21,13 @@
2121
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
2222

2323
# imports from local packages start here
24+
from wlsdeploy.aliases.aliases import Aliases
25+
from wlsdeploy.aliases.wlst_modes import WlstModes
2426
from wlsdeploy.exception import exception_helper
27+
from wlsdeploy.exception.expection_types import ExceptionType
2528
from wlsdeploy.logging.platform_logger import PlatformLogger
2629
from wlsdeploy.tool.encrypt import encryption_utils
30+
from wlsdeploy.tool.util.alias_helper import AliasHelper
2731
from wlsdeploy.util import getcreds
2832
from wlsdeploy.util import variables as variable_helper
2933
from wlsdeploy.util import wlst_helper
@@ -70,7 +74,7 @@ def __process_args(args):
7074
# Prompt for the password to encrypt if the -manual switch was specified
7175
#
7276
if CommandLineArgUtil.ENCRYPT_MANUAL_SWITCH in optional_arg_map and \
73-
CommandLineArgUtil.ONE_PASS_SWITCH not in optional_arg_map:
77+
CommandLineArgUtil.ONE_PASS_SWITCH not in optional_arg_map:
7478
try:
7579
pwd = getcreds.getpass('WLSDPLY-04200')
7680
except IOException, ioe:
@@ -101,6 +105,7 @@ def __verify_required_args_present(required_arg_map):
101105
raise ex
102106
return
103107

108+
104109
def __validate_mode_args(optional_arg_map):
105110
"""
106111
Verify that either the model_file or the manual switch was specified.
@@ -179,10 +184,13 @@ def __encrypt_model_and_variables(model_context):
179184
class_name=_class_name, method_name=_method_name)
180185
return CommandLineArgUtil.PROG_ERROR_EXIT_CODE
181186

187+
aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE)
188+
alias_helper = AliasHelper(aliases, __logger, ExceptionType.ENCRYPTION)
189+
182190
try:
183191
passphrase = model_context.get_encryption_passphrase()
184192
model_change_count, variable_change_count = \
185-
encryption_utils.encrypt_model_dictionary(passphrase, model, variables)
193+
encryption_utils.encrypt_model_dictionary(passphrase, model, alias_helper, variables)
186194
except EncryptionException, ee:
187195
__logger.severe('WLSDPLY-04208', _program_name, ee.getLocalizedMessage(), error=ee,
188196
class_name=_class_name, method_name=_method_name)
@@ -268,6 +276,7 @@ def main(args):
268276
__logger.exiting(class_name=_class_name, method_name=_method_name, result=exit_code)
269277
sys.exit(exit_code)
270278

279+
271280
if __name__ == "main":
272281
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
273282
main(sys.argv)

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
401401
data_type = attribute_info[WLST_TYPE]
402402
if data_type == 'password':
403403
try:
404-
wlst_attribute_value = self.__decrypt_password(model_attribute_value)
404+
wlst_attribute_value = self.decrypt_password(model_attribute_value)
405405
except EncryptionException, ee:
406406
ex = exception_helper.create_alias_exception('WLSDPLY-08402', model_attribute_name,
407407
location.get_folder_path(),
@@ -1130,21 +1130,15 @@ def get_ignore_attribute_names(self):
11301130
"""
11311131
return self._alias_entries.IGNORE_FOR_MODEL_LIST
11321132

1133-
####################################################################################
1134-
#
1135-
# Private methods, private inner classes and static methods only, beyond here please
1136-
#
1137-
####################################################################################
1138-
1139-
def __decrypt_password(self, text):
1133+
def decrypt_password(self, text):
11401134
"""
1141-
Internal method to determine if the provided password text needs to be decrypted
1135+
Encrypt the specified password if encryption is used and the password is encrypted.
11421136
:param text: the text to check and decrypt, if needed
11431137
:return: the clear text
11441138
:raises EncryptionException: if an error occurs while decrypting the password
11451139
"""
11461140
if text is None or len(str(text)) == 0 or \
1147-
(self._model_context and not self._model_context.is_using_encryption()) or\
1141+
(self._model_context and not self._model_context.is_using_encryption()) or \
11481142
not EncryptionUtils.isEncryptedString(text):
11491143

11501144
rtnval = text
@@ -1156,6 +1150,12 @@ def __decrypt_password(self, text):
11561150

11571151
return rtnval
11581152

1153+
####################################################################################
1154+
#
1155+
# Private methods, private inner classes and static methods only, beyond here please
1156+
#
1157+
####################################################################################
1158+
11591159
def __is_model_attribute_read_only(self, location, attribute_info):
11601160
"""
11611161
Is the model attribute read-only?

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

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,11 @@ def unzip_atp_wallet(wallet_file, location):
8888
zis.close()
8989
fis.close()
9090

91-
def fix_jps_config(model, model_context):
92-
#print model[model_constants.DOMAIN_INFO][model_constants.ATP_DB_INFO]
93-
tns_admin = model[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO][
94-
model_constants.DRIVER_PARAMS_NET_TNS_ADMIN]
95-
keystore_password = model[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO][
96-
model_constants.DRIVER_PARAMS_KEYSTOREPWD_PROPERTY]
9791

98-
truststore_password = model[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO][
99-
model_constants.DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY]
92+
def fix_jps_config(rcu_db_info, model_context):
93+
tns_admin = rcu_db_info.get_atp_tns_admin()
94+
keystore_password = rcu_db_info.get_keystore_password()
95+
truststore_password = rcu_db_info.get_truststore_password()
10096

10197
jsp_config = model_context.get_domain_home() + '/config/fmwconfig/jps-config.xml'
10298
jsp_config_jse = model_context.get_domain_home() + '/config/fmwconfig/jps-config-jse.xml'
@@ -155,33 +151,6 @@ def format_connect_string(connect_string):
155151

156152
return connect_string
157153

158-
# has_tns_admin is used to find the extract location if it is already extracted by the user
159-
# its an optional field, so insufficient to determine whether it has atp
160-
161-
162-
def has_tns_admin(rcu_db_info):
163-
return model_constants.DRIVER_PARAMS_NET_TNS_ADMIN in rcu_db_info
164-
165-
166-
def has_atpdbinfo(rcu_db_info):
167-
is_atp = 0
168-
if model_constants.USE_ATP in rcu_db_info:
169-
if rcu_db_info[model_constants.USE_ATP] == 'true' or rcu_db_info[model_constants.USE_ATP] == 1:
170-
is_atp = 1
171-
return is_atp
172-
# return model_constants.USE_ATP in rcu_db_info
173-
# return model_constants.ATP_TNS_ENTRY in rcu_db_info
174-
175-
176-
def is_regular_db(rcu_db_info):
177-
is_regular = 0
178-
if model_constants.USE_ATP in rcu_db_info:
179-
if rcu_db_info[model_constants.USE_ATP] is 'false' or rcu_db_info[model_constants.USE_ATP] is 0:
180-
is_regular = 1
181-
if model_constants.RCU_DB_CONN in rcu_db_info:
182-
is_regular = 1
183-
return is_regular
184-
185154

186155
def extract_walletzip(model, model_context, archive_file, atp_zipentry):
187156
domain_parent = model_context.get_domain_parent_dir()

0 commit comments

Comments
 (0)