1111from oracle .weblogic .deploy .validate .PasswordValidator import OLD_PASSWORD_ENCODING_MARKER
1212from oracle .weblogic .deploy .validate .PasswordValidator import PASSWORD_ENCODING_MARKER
1313
14+ from wlsdeploy .aliases .location_context import LocationContext
1415from wlsdeploy .aliases .model_constants import DESCRIPTION
16+ from wlsdeploy .aliases .model_constants import DOMAIN_INFO
1517from wlsdeploy .aliases .model_constants import GROUP
1618from wlsdeploy .aliases .model_constants import GROUP_MEMBER_OF
1719from wlsdeploy .aliases .model_constants import PASSWORD
20+ from wlsdeploy .aliases .model_constants import SECURITY
1821from wlsdeploy .aliases .model_constants import USER
1922from wlsdeploy .aliases .model_constants import USER_ATTRIBUTES
2023from 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.
0 commit comments