11
11
from oracle .weblogic .deploy .validate .PasswordValidator import OLD_PASSWORD_ENCODING_MARKER
12
12
from oracle .weblogic .deploy .validate .PasswordValidator import PASSWORD_ENCODING_MARKER
13
13
14
+ from wlsdeploy .aliases .location_context import LocationContext
14
15
from wlsdeploy .aliases .model_constants import DESCRIPTION
16
+ from wlsdeploy .aliases .model_constants import DOMAIN_INFO
15
17
from wlsdeploy .aliases .model_constants import GROUP
16
18
from wlsdeploy .aliases .model_constants import GROUP_MEMBER_OF
17
19
from wlsdeploy .aliases .model_constants import PASSWORD
20
+ from wlsdeploy .aliases .model_constants import SECURITY
18
21
from wlsdeploy .aliases .model_constants import USER
19
22
from wlsdeploy .aliases .model_constants import USER_ATTRIBUTES
20
23
from wlsdeploy .exception import exception_helper
@@ -69,31 +72,33 @@ def __init__(self, model_context, aliases, exception_type, using_password_digest
69
72
self ._resource_escaper = ResourcePolicyIdUtil .getEscaper ()
70
73
self ._using_password_digest = using_password_digest
71
74
72
- def create_default_init_file (self , security_mapping_nodes ):
75
+ def create_default_init_file (self , security_mapping_nodes , admin_credentials ):
73
76
"""
74
77
Use the security information to write user/groups to the DefaultAuthenticatorInit.ldift file.
75
78
This file must exist before writing the data. Build a hash map from the model data and
76
79
append to the file using the template file for structure.
77
80
:param security_mapping_nodes: the Security elements from the model
81
+ :param admin_credentials: admin credentials from the DomainInfo section of the model
78
82
"""
79
83
_method_name = 'create_default_init_file'
80
84
81
85
output_dir = File (self ._model_context .get_domain_home (), SECURITY_SUBDIR )
82
86
init_file = File (output_dir , DEFAULT_AUTH_INIT_FILE )
83
87
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 )
85
89
template_path = TEMPLATE_PATH + '/' + DEFAULT_AUTH_INIT_FILE + file_template_helper .MUSTACHE_SUFFIX
86
90
87
91
self ._logger .info ('WLSDPLY-01900' , init_file ,
88
92
class_name = self ._class_name , method_name = _method_name )
89
93
90
94
file_template_helper .create_file_from_resource (template_path , template_hash , init_file , self ._exception_type )
91
95
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 ):
93
97
"""
94
98
Create a dictionary of substitution values to apply to the default authenticator template.
95
99
:param model_security_dict: the security elements from the model
96
100
:param init_file: java.io.File containing original LDIFT entries
101
+ :param admin_credentials: admin credentials from the DomainInfo section of the model
97
102
:return: the template hash dictionary
98
103
"""
99
104
_method_name = '_build_default_template_hash'
@@ -119,8 +124,9 @@ def _build_default_template_hash(self, model_security_dict, init_file):
119
124
user_mapping_nodes = model_security_dict [USER ]
120
125
for name in user_mapping_nodes :
121
126
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 )
124
130
users_hash .append (user_hash )
125
131
except CreateException , ce :
126
132
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
172
178
173
179
return hash_entry
174
180
175
- def _build_user_template_hash (self , user_mapping_section , name ):
181
+ def _build_user_template_hash (self , user_mapping_section , name , admin_credentials ):
176
182
"""
177
183
Build a template hash map from the security user data from the model.
178
184
This includes encoding the required password.
179
185
:param user_mapping_section: The security user section from the model
180
186
:param name: name of the user for the user section
187
+ :param admin_credentials: admin credentials from the DomainInfo section of the model
181
188
:return: template hash map
182
189
:raises: CreateException if the user's password cannot be encoded
183
190
"""
@@ -193,8 +200,7 @@ def _build_user_template_hash(self, user_mapping_section, name):
193
200
hash_entry [HASH_DESCRIPTION ] = ''
194
201
195
202
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 )
198
204
hash_entry [HASH_USER_PASSWORD ] = password_encoded
199
205
200
206
groups = dictionary_utils .get_element (group_attributes , GROUP_MEMBER_OF )
@@ -235,11 +241,12 @@ def _build_group_child_map(self, model_security_dict):
235
241
# Update existing users and groups from the original LDIFT file
236
242
#################################################################
237
243
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 ):
239
245
"""
240
246
Update the specified user if it existed in the original LDIFT file.
241
247
:param name: the name of the user
242
248
:param model_user_dictionary: the model dictionary for the user
249
+ :param admin_credentials: admin credentials from the DomainInfo section of the model
243
250
:param existing_entries: existing entries from the LDIFT file
244
251
:return: True if an existing user was updated, False otherwise
245
252
"""
@@ -251,9 +258,8 @@ def _update_existing_user(self, name, model_user_dictionary, existing_entries):
251
258
class_name = self ._class_name , method_name = _method_name )
252
259
253
260
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 )
257
263
258
264
model_description = dictionary_utils .get_element (model_user_dictionary , DESCRIPTION )
259
265
if model_description :
@@ -297,6 +303,32 @@ def _update_existing_group(self, name, model_group_dictionary, existing_entries)
297
303
return True
298
304
return False
299
305
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
+
300
332
def _encode_password (self , user , password ):
301
333
"""
302
334
Encode the specified password using the correct algorithm for the authenticator.
0 commit comments