1
1
"""
2
- Copyright (c) 2021, 2022 , Oracle Corporation and/or its affiliates.
2
+ Copyright (c) 2021, 2023 , Oracle Corporation and/or its affiliates.
3
3
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
"""
5
- import com .octetstring .vde .util .PasswordEncryptor as PasswordEncryptor
6
- import com .bea .security .xacml .cache .resource .ResourcePolicyIdUtil as ResourcePolicyIdUtil
7
5
from java .io import File
8
- from java .lang import String
9
- import java .util .regex .Pattern as Pattern
10
6
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
12
11
13
12
from wlsdeploy .aliases .model_constants import DESCRIPTION
14
13
from wlsdeploy .aliases .model_constants import GROUP
@@ -69,7 +68,8 @@ def create_default_init_file(self, security_mapping_nodes):
69
68
output_dir = File (self ._model_context .get_domain_home (), SECURITY_SUBDIR )
70
69
output_file = File (output_dir , DEFAULT_AUTH_INIT_FILE )
71
70
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 )
73
73
74
74
file_template_helper .append_file_from_resource (template_path , template_hash , output_file , self ._exception_type )
75
75
@@ -79,6 +79,7 @@ def _build_default_template_hash(self, mapping_section_nodes):
79
79
:param mapping_section_nodes: the security elements from the model
80
80
:return: the template hash dictionary
81
81
"""
82
+ _method_name = '_build_default_template_hash'
82
83
template_hash = dict ()
83
84
84
85
group_mappings = []
@@ -92,8 +93,12 @@ def _build_default_template_hash(self, mapping_section_nodes):
92
93
if USER in mapping_section_nodes .keys ():
93
94
user_mapping_nodes = mapping_section_nodes [USER ]
94
95
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 )
97
102
98
103
template_hash [GROUP_MAPPINGS ] = group_mappings
99
104
template_hash [USER_MAPPINGS ] = user_mappings
@@ -110,7 +115,10 @@ def _build_group_mapping_hash(self, group_mapping_section, name):
110
115
hash_entry [HASH_NAME ] = name
111
116
group_attributes = group_mapping_section
112
117
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 ] = ''
114
122
groups = dictionary_utils .get_element (group_attributes , GROUP_MEMBER_OF )
115
123
group_list = []
116
124
group_mappings = list ()
@@ -148,12 +156,16 @@ def _build_user_mapping_hash(self, user_mapping_section, name):
148
156
:param user_mapping_section: The security user section from the model
149
157
:param name: name of the user for the user section
150
158
:return: template hash map
159
+ :raises: CreateException if the user's password cannot be encoded
151
160
"""
152
161
hash_entry = dict ()
153
162
hash_entry [HASH_NAME ] = name
154
163
group_attributes = user_mapping_section
155
164
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 ] = ''
157
169
groups = dictionary_utils .get_element (group_attributes , GROUP_MEMBER_OF )
158
170
password = self ._get_required_attribute (user_mapping_section , PASSWORD , USER , name )
159
171
password = self ._aliases .decrypt_password (password )
@@ -175,17 +187,15 @@ def _build_user_mapping_hash(self, user_mapping_section, name):
175
187
return hash_entry
176
188
177
189
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'
183
191
try :
184
192
encrypted_pass = PasswordEncryptor .doSSHA256 (password )
185
193
encrypted_pass = "{ssha256}" + encrypted_pass
186
194
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
189
199
return encrypted_pass
190
200
191
201
def _get_required_attribute (self , dictionary , name , mapping_type , mapping_name ):
0 commit comments