Skip to content

Commit 86c5304

Browse files
rakillenrobertpatrick
authored andcommitted
Overwrite admin password if admin user is included in Security folder
1 parent 696d371 commit 86c5304

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,14 @@ def __create_security_folder(self):
590590
self.logger.entering(class_name=self.__class_name, method_name=_method_name)
591591
security_folder = dictionary_utils.get_dictionary_element(self._topology, SECURITY)
592592
if security_folder is not None:
593+
admin_credentials = {
594+
'user': dictionary_utils.get_element(self._domain_info, ADMIN_USERNAME),
595+
'password': dictionary_utils.get_element(self._domain_info, ADMIN_PASSWORD)
596+
}
593597
using_password_digests = self.security_provider_creator.is_default_authenticator_password_digest_enabled()
594598
helper = DefaultAuthenticatorHelper(self.model_context, self.aliases, ExceptionType.CREATE,
595599
using_password_digests)
596-
helper.create_default_init_file(security_folder)
600+
helper.create_default_init_file(security_folder, admin_credentials)
597601
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
598602

599603
def __create_log_filters(self, location):

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

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
from oracle.weblogic.deploy.validate.PasswordValidator import OLD_PASSWORD_ENCODING_MARKER
1212
from oracle.weblogic.deploy.validate.PasswordValidator import PASSWORD_ENCODING_MARKER
1313

14+
from wlsdeploy.aliases.location_context import LocationContext
1415
from wlsdeploy.aliases.model_constants import DESCRIPTION
16+
from wlsdeploy.aliases.model_constants import DOMAIN_INFO
1517
from wlsdeploy.aliases.model_constants import GROUP
1618
from wlsdeploy.aliases.model_constants import GROUP_MEMBER_OF
1719
from wlsdeploy.aliases.model_constants import PASSWORD
20+
from wlsdeploy.aliases.model_constants import SECURITY
1821
from wlsdeploy.aliases.model_constants import USER
1922
from wlsdeploy.aliases.model_constants import USER_ATTRIBUTES
2023
from wlsdeploy.exception import exception_helper
@@ -69,31 +72,33 @@ def __init__(self, model_context, aliases, exception_type, using_password_digest
6972
self._resource_escaper = ResourcePolicyIdUtil.getEscaper()
7073
self._using_password_digest = using_password_digest
7174

72-
def create_default_init_file(self, security_mapping_nodes):
75+
def create_default_init_file(self, security_mapping_nodes, admin_credentials):
7376
"""
7477
Use the security information to write user/groups to the DefaultAuthenticatorInit.ldift file.
7578
This file must exist before writing the data. Build a hash map from the model data and
7679
append to the file using the template file for structure.
7780
:param security_mapping_nodes: the Security elements from the model
81+
:param admin_credentials: admin credentials from the DomainInfo section of the model
7882
"""
7983
_method_name = 'create_default_init_file'
8084

8185
output_dir = File(self._model_context.get_domain_home(), SECURITY_SUBDIR)
8286
init_file = File(output_dir, DEFAULT_AUTH_INIT_FILE)
8387

84-
template_hash = self._build_default_template_hash(security_mapping_nodes, init_file)
88+
template_hash = self._build_default_template_hash(security_mapping_nodes, admin_credentials, init_file)
8589
template_path = TEMPLATE_PATH + '/' + DEFAULT_AUTH_INIT_FILE + file_template_helper.MUSTACHE_SUFFIX
8690

8791
self._logger.info('WLSDPLY-01900', init_file,
8892
class_name=self._class_name, method_name=_method_name)
8993

9094
file_template_helper.create_file_from_resource(template_path, template_hash, init_file, self._exception_type)
9195

92-
def _build_default_template_hash(self, model_security_dict, init_file):
96+
def _build_default_template_hash(self, model_security_dict, admin_credentials, init_file):
9397
"""
9498
Create a dictionary of substitution values to apply to the default authenticator template.
9599
:param model_security_dict: the security elements from the model
96100
:param init_file: java.io.File containing original LDIFT entries
101+
:param admin_credentials: admin credentials from the DomainInfo section of the model
97102
:return: the template hash dictionary
98103
"""
99104
_method_name = '_build_default_template_hash'
@@ -119,8 +124,9 @@ def _build_default_template_hash(self, model_security_dict, init_file):
119124
user_mapping_nodes = model_security_dict[USER]
120125
for name in user_mapping_nodes:
121126
try:
122-
if not self._update_existing_user(name, user_mapping_nodes[name], existing_entries):
123-
user_hash = self._build_user_template_hash(user_mapping_nodes[name], name)
127+
if not self._update_existing_user(name, user_mapping_nodes[name], admin_credentials,
128+
existing_entries):
129+
user_hash = self._build_user_template_hash(user_mapping_nodes[name], name, admin_credentials)
124130
users_hash.append(user_hash)
125131
except CreateException, ce:
126132
self._logger.warning('WLSDPLY-01902', name, ce.getLocalizedMessage(),
@@ -172,12 +178,13 @@ def _build_group_template_hash(self, group_mapping_section, name, group_child_ma
172178

173179
return hash_entry
174180

175-
def _build_user_template_hash(self, user_mapping_section, name):
181+
def _build_user_template_hash(self, user_mapping_section, name, admin_credentials):
176182
"""
177183
Build a template hash map from the security user data from the model.
178184
This includes encoding the required password.
179185
:param user_mapping_section: The security user section from the model
180186
:param name: name of the user for the user section
187+
:param admin_credentials: admin credentials from the DomainInfo section of the model
181188
:return: template hash map
182189
:raises: CreateException if the user's password cannot be encoded
183190
"""
@@ -193,8 +200,7 @@ def _build_user_template_hash(self, user_mapping_section, name):
193200
hash_entry[HASH_DESCRIPTION] = ''
194201

195202
password = self._get_required_attribute(user_mapping_section, PASSWORD, USER, name)
196-
password = self._aliases.decrypt_password(password)
197-
password_encoded = self._encode_password(name, password)
203+
password_encoded = self._get_encoded_user_password(password, name, admin_credentials)
198204
hash_entry[HASH_USER_PASSWORD] = password_encoded
199205

200206
groups = dictionary_utils.get_element(group_attributes, GROUP_MEMBER_OF)
@@ -235,11 +241,12 @@ def _build_group_child_map(self, model_security_dict):
235241
# Update existing users and groups from the original LDIFT file
236242
#################################################################
237243

238-
def _update_existing_user(self, name, model_user_dictionary, existing_entries):
244+
def _update_existing_user(self, name, model_user_dictionary, admin_credentials, existing_entries):
239245
"""
240246
Update the specified user if it existed in the original LDIFT file.
241247
:param name: the name of the user
242248
:param model_user_dictionary: the model dictionary for the user
249+
:param admin_credentials: admin credentials from the DomainInfo section of the model
243250
:param existing_entries: existing entries from the LDIFT file
244251
:return: True if an existing user was updated, False otherwise
245252
"""
@@ -251,9 +258,8 @@ def _update_existing_user(self, name, model_user_dictionary, existing_entries):
251258
class_name=self._class_name, method_name=_method_name)
252259

253260
model_password = dictionary_utils.get_element(model_user_dictionary, PASSWORD)
254-
model_password = self._aliases.decrypt_password(model_password)
255-
model_password = self._encode_password(name, model_password)
256-
existing_user.update_single_field(LDIFT_PASSWORD, model_password)
261+
password_encoded = self._get_encoded_user_password(model_password, name, admin_credentials)
262+
existing_user.update_single_field(LDIFT_PASSWORD, password_encoded)
257263

258264
model_description = dictionary_utils.get_element(model_user_dictionary, DESCRIPTION)
259265
if model_description:
@@ -297,6 +303,32 @@ def _update_existing_group(self, name, model_group_dictionary, existing_entries)
297303
return True
298304
return False
299305

306+
def _get_encoded_user_password(self, model_password, user_name, admin_credentials):
307+
"""
308+
Encode the model password for use in the template hash.
309+
If the username matches the admin user from the DomainInfo section, override the password value.
310+
:param model_password: the password from the model
311+
:param user_name: the username from the model
312+
:param admin_credentials: the admin credentials from DomainInfo
313+
:return: the encoded password value
314+
"""
315+
_method_name = '_get_encoded_user_password'
316+
317+
admin_user = dictionary_utils.get_element(admin_credentials, 'user')
318+
if user_name == admin_user:
319+
admin_password = dictionary_utils.get_element(admin_credentials, 'password')
320+
if admin_password:
321+
model_password = admin_password
322+
security_location = LocationContext().append_location(SECURITY)
323+
security_location.add_name_token(self._aliases.get_name_token(security_location), 'X')
324+
security_location.append_location(USER)
325+
security_path = self._aliases.get_model_folder_path(security_location)
326+
self._logger.notification('WLSDPLY-01905', user_name, DOMAIN_INFO, security_path,
327+
class_name=self._class_name, method_name=_method_name)
328+
329+
model_password = self._aliases.decrypt_password(model_password)
330+
return self._encode_password(user_name, model_password)
331+
300332
def _encode_password(self, user, password):
301333
"""
302334
Encode the specified password using the correct algorithm for the authenticator.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ def validate_user_passwords(self, model_dict):
267267
self._logger.notification('WLSDPLY-05208', user_name,
268268
class_name=self._class_name, method_name=_method_name)
269269
except ValidateException, ex:
270-
_logger.severe('WLSDPLY-05204', user_name, ex.getLocalizedMessage(),
271-
error=ex, class_name=self._class_name, method_name=_method_name)
270+
self._logger.severe('WLSDPLY-05204', user_name, ex.getLocalizedMessage(),
271+
error=ex, class_name=self._class_name, method_name=_method_name)
272272

273273
if found_errors:
274274
ce = exception_helper.create_validate_exception('WLSDPLY-05205')

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
@@ -517,6 +517,8 @@ WLSDPLY-01901=Failed to encrypt password for user {0}: {1}
517517
WLSDPLY-01902=Unable to add user {0} due to an error: {1}
518518
WLSDPLY-01903=Updating existing user {0}
519519
WLSDPLY-01904=Updating existing group {0}
520+
WLSDPLY-01905=The password for admin user {0} in the {1} section of the model was applied to the matching entry \
521+
in the {2} section
520522

521523
# wlsdeploy/util/weblogic_policies_helper.py
522524
WLSDPLY-02000=Unable to initialize WebLogicPolicyHelper because WebLogic Home is not set

core/src/test/python/wlsdeploy/tool/util/default_authenticator_helper_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_create_init_file(self):
5151

5252
ldift_name = 'DefaultAuthenticatorInit.ldift'
5353
source_ldift = File(self.MODELS_DIR, ldift_name)
54-
template_hash = helper._build_default_template_hash(security_dict, source_ldift)
54+
template_hash = helper._build_default_template_hash(security_dict, {}, source_ldift)
5555

5656
template_file_name = ldift_name + file_template_helper.MUSTACHE_SUFFIX
5757
template_path = os.path.join(self.SECURITY_RESOURCES_DIR, template_file_name)

0 commit comments

Comments
 (0)