Skip to content

Commit fcc85a4

Browse files
authored
Add option to update the rcu schema password after the population by … (#557)
* Add option to update the rcu schema password after the population by getDatabaseDefaults or in update case when the -updateRCUSchemaPassword flag is specified. * Fix create problem and remove commented out code * remove duplicate code line
1 parent 7634657 commit fcc85a4

File tree

8 files changed

+145
-3
lines changed

8 files changed

+145
-3
lines changed

core/src/main/python/create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
8282
CommandLineArgUtil.PASSPHRASE_SWITCH,
8383
CommandLineArgUtil.OPSS_WALLET_SWITCH,
84-
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE
84+
CommandLineArgUtil.OPSS_WALLET_PASSPHRASE,
85+
CommandLineArgUtil.UPDATE_RCU_SCHEMA_PASS_SWITCH
8586
]
8687

8788

core/src/main/python/update.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
# imports from local packages start here
2424
from wlsdeploy.aliases.aliases import Aliases
25+
from wlsdeploy.tool.util.alias_helper import AliasHelper
2526
from wlsdeploy.aliases.wlst_modes import WlstModes
2627
from wlsdeploy.exception import exception_helper
2728
from wlsdeploy.exception.expection_types import ExceptionType
@@ -35,6 +36,7 @@
3536
from wlsdeploy.tool.util import model_context_helper
3637
from wlsdeploy.tool.util import wlst_helper
3738
from wlsdeploy.tool.util.wlst_helper import WlstHelper
39+
from wlsdeploy.tool.util.rcu_helper import RCUHelper
3840
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
3941
from wlsdeploy.util import cla_helper
4042
from wlsdeploy.util import getcreds
@@ -45,6 +47,7 @@
4547
from wlsdeploy.util.weblogic_helper import WebLogicHelper
4648
from wlsdeploy.util import model as model_helper
4749

50+
4851
wlst_helper.wlst_functions = globals()
4952

5053
_program_name = UPDATE_DOMAIN
@@ -71,7 +74,8 @@
7174
CommandLineArgUtil.ADMIN_PASS_SWITCH,
7275
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
7376
CommandLineArgUtil.PASSPHRASE_SWITCH,
74-
CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH
77+
CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH,
78+
CommandLineArgUtil.UPDATE_RCU_SCHEMA_PASS_SWITCH
7579
]
7680

7781

@@ -184,7 +188,6 @@ def __process_encryption_args(optional_arg_map):
184188
optional_arg_map[CommandLineArgUtil.PASSPHRASE_SWITCH] = String(passphrase)
185189
return
186190

187-
188191
def __update(model, model_context, aliases):
189192
"""
190193
The method that does the heavy lifting for update.
@@ -291,6 +294,9 @@ def __update_offline(model, model_context, aliases):
291294
topology_updater.update()
292295

293296
model_deployer.deploy_model_offline(model, model_context, aliases, wlst_mode=__wlst_mode)
297+
if model_context.get_update_rcu_schema_pass() is True:
298+
rcu_helper = RCUHelper(model, model_context, aliases)
299+
rcu_helper.update_rcu_password()
294300

295301
try:
296302
__wlst_helper.update_domain()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
from wlsdeploy.tool.deploy import model_deployer
8585
from wlsdeploy.tool.util.archive_helper import ArchiveHelper
8686
from wlsdeploy.tool.util.library_helper import LibraryHelper
87+
from wlsdeploy.tool.util.rcu_helper import RCUHelper
8788
from wlsdeploy.tool.util.target_helper import TargetHelper
8889
from wlsdeploy.tool.util.targeting_types import TargetingType
8990
from wlsdeploy.tool.util.topology_helper import TopologyHelper
@@ -966,6 +967,10 @@ def __configure_fmw_infra_database(self):
966967
if self.wls_helper.is_database_defaults_supported():
967968
self.wlst_helper.get_database_defaults()
968969

970+
if self.model_context.get_update_rcu_schema_pass() is True:
971+
rcu_helper = RCUHelper(self.model, self.model_context, self.aliases, modifyBootStrapCredential=False)
972+
rcu_helper.update_rcu_password()
973+
969974
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
970975
return
971976

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
"""
2+
Copyright (c) 2010, Oracle Corporation and/or its affiliates. All rights reserved.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
6+
from wlsdeploy.aliases.model_constants import RCU_DB_INFO
7+
from wlsdeploy.aliases.model_constants import RCU_PREFIX
8+
from wlsdeploy.aliases.model_constants import RCU_SCHEMA_PASSWORD
9+
from wlsdeploy.aliases.model_constants import DRIVER_PARAMS_USER_PROPERTY
10+
from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS
11+
from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS_PROPERTIES
12+
from wlsdeploy.aliases.model_constants import JDBC_RESOURCE
13+
from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE
14+
from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED
15+
from wlsdeploy.tool.create.rcudbinfo_helper import RcuDbInfo
16+
from wlsdeploy.aliases.location_context import LocationContext
17+
from wlsdeploy.tool.deploy.deployer import Deployer
18+
from wlsdeploy.exception.expection_types import ExceptionType
19+
20+
from wlsdeploy.aliases.wlst_modes import WlstModes
21+
22+
class RCUHelper(Deployer):
23+
24+
def __init__(self, model, model_context, aliases, modifyBootStrapCredential=True):
25+
Deployer.__init__(self, model, model_context, aliases, wlst_mode=WlstModes.OFFLINE)
26+
self._exception_type = ExceptionType.DEPLOY
27+
self._modifyBootStrapCredential = modifyBootStrapCredential
28+
29+
def update_rcu_password(self):
30+
"""
31+
Update the password of each rcu schema and then update the bootstrap password
32+
"""
33+
34+
_method_name = 'update_rcu_password'
35+
36+
domain_info = self.model.get_model_domain_info()
37+
if RCU_DB_INFO in domain_info:
38+
rcu_db_info = RcuDbInfo(self.alias_helper, domain_info[RCU_DB_INFO])
39+
rcu_schema_pass = rcu_db_info.get_rcu_schema_password()
40+
rcu_prefix = rcu_db_info.get_rcu_prefix()
41+
42+
location = LocationContext()
43+
location.append_location(JDBC_SYSTEM_RESOURCE)
44+
45+
folder_path = self.alias_helper.get_wlst_list_path(location)
46+
self.wlst_helper.cd(folder_path)
47+
ds_names = self.wlst_helper.lsc()
48+
domain_typedef = self.model_context.get_domain_typedef()
49+
rcu_schemas = domain_typedef.get_rcu_schemas()
50+
if len(rcu_schemas) == 0:
51+
return
52+
schemas_len = len(rcu_schemas)
53+
54+
for i in range(0,schemas_len):
55+
rcu_schemas[i] = rcu_prefix + '_' + rcu_schemas[i]
56+
57+
for ds_name in ds_names:
58+
location = LocationContext()
59+
location.append_location(JDBC_SYSTEM_RESOURCE)
60+
token_name = self.alias_helper.get_name_token(location)
61+
location.add_name_token(token_name, ds_name)
62+
63+
location.append_location(JDBC_RESOURCE)
64+
location.append_location(JDBC_DRIVER_PARAMS)
65+
password_location = LocationContext(location)
66+
67+
wlst_path = self.alias_helper.get_wlst_attributes_path(location)
68+
self.wlst_helper.cd(wlst_path)
69+
70+
location.append_location(JDBC_DRIVER_PARAMS_PROPERTIES)
71+
token_name = self.alias_helper.get_name_token(location)
72+
if token_name is not None:
73+
location.add_name_token(token_name, DRIVER_PARAMS_USER_PROPERTY)
74+
wlst_path = self.alias_helper.get_wlst_attributes_path(location)
75+
self.wlst_helper.cd(wlst_path)
76+
ds_user = self.wlst_helper.get('Value')
77+
78+
if ds_user in rcu_schemas:
79+
wlst_path = self.alias_helper.get_wlst_attributes_path(password_location)
80+
self.wlst_helper.cd(wlst_path)
81+
wlst_name, wlst_value = \
82+
self.alias_helper.get_wlst_attribute_name_and_value(password_location, PASSWORD_ENCRYPTED,
83+
rcu_schema_pass, masked=True)
84+
self.wlst_helper.set(wlst_name, wlst_value, masked=True)
85+
86+
domain_home = self.model_context.get_domain_home()
87+
config_file = domain_home + '/config/fmwconfig/jps-config-jse.xml'
88+
opss_user = rcu_prefix + '_OPSS'
89+
if self._modifyBootStrapCredential:
90+
self.wlst_helper.modify_bootstrap_credentials(jps_configfile=config_file, username=opss_user, password=rcu_schema_pass)
91+
92+

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@ def get_database_defaults(self):
322322
raise pwe
323323
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name)
324324

325+
def modify_bootstrap_credentials(self, jps_configfile, username, password):
326+
"""
327+
modify the boot strap credentials in a JRF domain
328+
:raises: Exception for the specified tool type: if a WLST error occurs
329+
"""
330+
_method_name = 'modifyBootStrapCredentials'
331+
self.__logger.entering(class_name=self.__class_name, method_name=_method_name)
332+
333+
try:
334+
self.__load_global('modifyBootStrapCredential')(jps_configfile, username, password)
335+
except offlineWLSTException, e:
336+
pwe = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-00101',
337+
e.getLocalizedMessage(), error=e)
338+
self.__logger.throwing(pwe, class_name=self.__class_name, method_name=_method_name)
339+
raise pwe
340+
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name)
341+
325342
def set_server_groups(self, server, server_groups):
326343
"""
327344
Sets the database defaults indicated by RCU.

core/src/main/python/wlsdeploy/util/cla_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class CommandLineArgUtil(object):
7070
ATTRIBUTES_ONLY_SWITCH = '-attributes_only'
7171
FOLDERS_ONLY_SWITCH = '-folders_only'
7272
RECURSIVE_SWITCH = '-recursive'
73+
UPDATE_RCU_SCHEMA_PASS_SWITCH = '-updateRCUSchemaPassword'
7374
VALIDATION_METHOD = '-method'
7475
# overrides for the variable injector
7576
VARIABLE_INJECTOR_FILE_SWITCH = '-variable_injector_file'
@@ -395,6 +396,8 @@ def process_args(self, args, tool_type=TOOL_TYPE_DEFAULT):
395396
self._add_arg(key, True)
396397
elif self.is_recursive_switch(key):
397398
self._add_arg(key, True)
399+
elif self.is_update_rcu_schema_pass_switch(key):
400+
self._add_arg(key, True)
398401
elif self.is_variable_injector_file_key(key):
399402
idx += 1
400403
if idx < args_len:
@@ -1040,6 +1043,12 @@ def get_recursive_switch(self):
10401043
def is_recursive_switch(self, key):
10411044
return self.RECURSIVE_SWITCH == key
10421045

1046+
def is_update_rcu_schema_pass_switch(self, key):
1047+
return self.UPDATE_RCU_SCHEMA_PASS_SWITCH == key
1048+
1049+
def get_is_update_rcu_schema_pass_switch(self):
1050+
return self.UPDATE_RCU_SCHEMA_PASS_SWITCH
1051+
10431052
def _validate_target_mode_arg(self, value):
10441053
method_name = '_validate_target_mode_arg'
10451054

core/src/main/python/wlsdeploy/util/model_context.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(self, program_name, arg_map):
7272
self._folders_only = False
7373
self._opss_wallet_passphrase = None
7474
self._opss_wallet = None
75+
self._update_rcu_schema_pass = False
7576
self._validation_method = None
7677
self._rollback_if_restart_required = None
7778
self._domain_resource_file = None
@@ -168,6 +169,9 @@ def __init__(self, program_name, arg_map):
168169
if CommandLineArgUtil.OPSS_WALLET_SWITCH in arg_map:
169170
self._opss_wallet = arg_map[CommandLineArgUtil.OPSS_WALLET_SWITCH]
170171

172+
if CommandLineArgUtil.UPDATE_RCU_SCHEMA_PASS_SWITCH in arg_map:
173+
self._update_rcu_schema_pass = True
174+
171175
if CommandLineArgUtil.VALIDATION_METHOD in arg_map:
172176
self._validation_method = arg_map[CommandLineArgUtil.VALIDATION_METHOD]
173177

@@ -322,6 +326,12 @@ def get_opss_wallet_passphrase(self):
322326
"""
323327
return self._opss_wallet_passphrase
324328

329+
def get_update_rcu_schema_pass(self):
330+
"""
331+
Get the update rcu schema password flag
332+
"""
333+
return self._update_rcu_schema_pass
334+
325335
def get_validation_method(self):
326336
"""
327337
Get the validation method.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ WLSDPLY-00096=Unable to obtain the cmo or MBean proxy for the current location {
104104
WLSDPLY-0097=Look for MBean instance for location {0}.
105105
WLSDPLY-0098=Quoted WebLogic String
106106
WLSDPLY-0100=Failed to set attribute {0} in path {1} to value {2}: {3}
107+
WLSDPLY-00101=Failed to modify the bootstrap credentials : {0}
108+
107109

108110
###############################################################################
109111
# Util messages (1000 - 3999) #

0 commit comments

Comments
 (0)