11"""
2- Copyright (c) 2021, 2022 , Oracle Corporation and/or its affiliates.
2+ Copyright (c) 2021, 2023 , Oracle Corporation and/or its affiliates.
33Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44"""
5- import com .octetstring .vde .util .PasswordEncryptor as PasswordEncryptor
6- import com .bea .security .xacml .cache .resource .ResourcePolicyIdUtil as ResourcePolicyIdUtil
75from java .io import File
8- from java .lang import String
9- import java .util .regex .Pattern as Pattern
106
11- import oracle .weblogic .deploy .aliases .TypeUtils as TypeUtils
7+ from com .octetstring .vde .util import PasswordEncryptor
8+ from com .bea .security .xacml .cache .resource import ResourcePolicyIdUtil
9+ from oracle .weblogic .deploy .aliases import TypeUtils
10+ from oracle .weblogic .deploy .create import CreateException
1211
1312from wlsdeploy .aliases .model_constants import DESCRIPTION
1413from wlsdeploy .aliases .model_constants import GROUP
@@ -69,7 +68,8 @@ def create_default_init_file(self, security_mapping_nodes):
6968 output_dir = File (self ._model_context .get_domain_home (), SECURITY_SUBDIR )
7069 output_file = File (output_dir , DEFAULT_AUTH_INIT_FILE )
7170
72- self ._logger .info ('WLSDPLY-01900' , output_file , class_name = self ._class_name , method_name = _method_name )
71+ self ._logger .info ('WLSDPLY-01900' , output_file ,
72+ class_name = self ._class_name , method_name = _method_name )
7373
7474 file_template_helper .append_file_from_resource (template_path , template_hash , output_file , self ._exception_type )
7575
@@ -79,6 +79,7 @@ def _build_default_template_hash(self, mapping_section_nodes):
7979 :param mapping_section_nodes: the security elements from the model
8080 :return: the template hash dictionary
8181 """
82+ _method_name = '_build_default_template_hash'
8283 template_hash = dict ()
8384
8485 group_mappings = []
@@ -92,8 +93,12 @@ def _build_default_template_hash(self, mapping_section_nodes):
9293 if USER in mapping_section_nodes .keys ():
9394 user_mapping_nodes = mapping_section_nodes [USER ]
9495 for name in user_mapping_nodes :
95- mapping_hash = self ._build_user_mapping_hash (user_mapping_nodes [name ], name )
96- user_mappings .append (mapping_hash )
96+ try :
97+ mapping_hash = self ._build_user_mapping_hash (user_mapping_nodes [name ], name )
98+ user_mappings .append (mapping_hash )
99+ except CreateException , ce :
100+ self ._logger .warning ('WLSDPLY-01902' , name , ce .getLocalizedMessage (),
101+ error = ce , class_name = self ._class_name , method_name = _method_name )
97102
98103 template_hash [GROUP_MAPPINGS ] = group_mappings
99104 template_hash [USER_MAPPINGS ] = user_mappings
@@ -110,7 +115,10 @@ def _build_group_mapping_hash(self, group_mapping_section, name):
110115 hash_entry [HASH_NAME ] = name
111116 group_attributes = group_mapping_section
112117 description = dictionary_utils .get_element (group_attributes , DESCRIPTION )
113- hash_entry [HASH_DESCRIPTION ] = description
118+ if description is not None :
119+ hash_entry [HASH_DESCRIPTION ] = description
120+ else :
121+ hash_entry [HASH_DESCRIPTION ] = ''
114122 groups = dictionary_utils .get_element (group_attributes , GROUP_MEMBER_OF )
115123 group_list = []
116124 group_mappings = list ()
@@ -148,12 +156,16 @@ def _build_user_mapping_hash(self, user_mapping_section, name):
148156 :param user_mapping_section: The security user section from the model
149157 :param name: name of the user for the user section
150158 :return: template hash map
159+ :raises: CreateException if the user's password cannot be encoded
151160 """
152161 hash_entry = dict ()
153162 hash_entry [HASH_NAME ] = name
154163 group_attributes = user_mapping_section
155164 description = dictionary_utils .get_element (group_attributes , DESCRIPTION )
156- hash_entry [HASH_DESCRIPTION ] = description
165+ if description is not None :
166+ hash_entry [HASH_DESCRIPTION ] = description
167+ else :
168+ hash_entry [HASH_DESCRIPTION ] = ''
157169 groups = dictionary_utils .get_element (group_attributes , GROUP_MEMBER_OF )
158170 password = self ._get_required_attribute (user_mapping_section , PASSWORD , USER , name )
159171 password = self ._aliases .decrypt_password (password )
@@ -175,17 +187,15 @@ def _build_user_mapping_hash(self, user_mapping_section, name):
175187 return hash_entry
176188
177189 def _encode_password (self , user , password ):
178- pwd_pattern = '[\\ !a-zA-Z]{1,}'
179- matches = Pattern .matches (pwd_pattern , password )
180- if len (password ) < 8 or matches :
181- self ._logger .warning ('WLSDPLY-01902' , user )
182- return None
190+ _method_name = '_encode_password'
183191 try :
184192 encrypted_pass = PasswordEncryptor .doSSHA256 (password )
185193 encrypted_pass = "{ssha256}" + encrypted_pass
186194 except Exception , e :
187- self ._logger .warning ('WLSDPLY-01901' , user , e )
188- return None
195+ ex = exception_helper .create_create_exception ('WLSDPLY-01901' ,user , e .getLocalizedMessage (),
196+ error = e )
197+ self ._logger .throwing (ex , class_name = self ._class_name , method_name = _method_name )
198+ raise ex
189199 return encrypted_pass
190200
191201 def _get_required_attribute (self , dictionary , name , mapping_type , mapping_name ):
0 commit comments