Skip to content

Commit ff7a0eb

Browse files
Warn if custom security provider in compareModels model comparison (#897)
* Warn if custom security provider in compareModels model comparison * add in test yaml files
1 parent f7c34ab commit ff7a0eb

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

core/src/main/python/wlsdeploy/tool/compare/model_comparer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55

6+
from oracle.weblogic.deploy.aliases import AliasException
67
from oracle.weblogic.deploy.util import PyOrderedDict
78

89
from wlsdeploy.aliases import alias_utils
@@ -277,6 +278,16 @@ def _check_key(self, key, location):
277278
if (location is None) and (key == KUBERNETES):
278279
self._logger.info('WLSDPLY-05713', KUBERNETES, class_name=self._class_name, method_name=_method_name)
279280
return False
281+
try:
282+
if (location is not None) and (not self._aliases.is_artificial_type_folder(location)) and \
283+
(self._aliases.requires_artificial_type_subfolder_handling(location)):
284+
providers = self._aliases.get_model_subfolder_names(location)
285+
if key not in providers:
286+
self._logger.warning('WLSDPLY-05716', key,
287+
class_name=self._class_name, method_name=_method_name)
288+
return False
289+
except AliasException:
290+
return True
280291
return True
281292

282293
def _finalize_folder(self, current_folder, past_folder, change_folder, location):

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
@@ -498,6 +498,8 @@ WLSDPLY-05712=Unrecognized token {0} in path {1}
498498
WLSDPLY-05713=Model section {0} will not be compared
499499
WLSDPLY-05714={0} is unchanged, but required if other changes are present
500500
WLSDPLY-05715=There are {0} attributes that only exist in the previous model, see {1}
501+
WLSDPLY-05716=Model Security Configuration section contains a custom security provider {0}. The compare model cannot compare \
502+
a custom security provider and the section will not be included in the diffed model.
501503

502504
# prepare_model.py
503505
WLSDPLY-05801=Error in prepare model {0}

core/src/test/python/compare_model_test.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,54 @@ def testCompareModelFull(self):
122122

123123
self.assertEqual(return_code, 0)
124124

125+
def testCompareModelSecurityConfiguration(self):
126+
_method_name = 'testCompareModelSecurityConfiguration'
127+
128+
_new_model_file = self._resources_dir + '/compare/model-a-old.yaml'
129+
_old_model_file = self._resources_dir + '/compare/model-a-new.yaml'
130+
_temp_dir = os.path.join(tempfile.gettempdir(), _method_name)
131+
132+
if os.path.exists(_temp_dir):
133+
shutil.rmtree(_temp_dir)
134+
135+
os.mkdir(_temp_dir)
136+
137+
mw_home = os.environ['MW_HOME']
138+
args_map = {
139+
'-oracle_home': mw_home,
140+
'-output_dir' : _temp_dir,
141+
'-domain_type' : 'WLS',
142+
'-trailing_arguments': [ _new_model_file, _old_model_file ]
143+
}
144+
145+
try:
146+
model_context = ModelContext('CompareModelTestCase', args_map)
147+
obj = ModelFileDiffer(_new_model_file, _old_model_file, model_context, _temp_dir)
148+
return_code = obj.compare()
149+
self.assertEqual(return_code, 0)
150+
151+
yaml_result = _temp_dir + os.sep + 'diffed_model.yaml'
152+
json_result = _temp_dir + os.sep + 'diffed_model.json'
153+
stdout_result = obj.get_compare_msgs()
154+
model_dictionary = FileToPython(yaml_result).parse()
155+
self.assertEqual(model_dictionary.has_key('topology'), True)
156+
self.assertEqual(model_dictionary['topology'].has_key('SecurityConfiguration'), True)
157+
self.assertEqual(model_dictionary['topology']['SecurityConfiguration'].has_key('Realm'), True)
158+
self.assertEqual(model_dictionary['topology']['SecurityConfiguration']['Realm'].has_key('myrealm'), True)
159+
self.assertEqual(model_dictionary['topology']['SecurityConfiguration']['Realm']['myrealm'].has_key('Auditor'), False)
160+
self.assertEqual(model_dictionary['topology']['SecurityConfiguration']['Realm']['myrealm'].has_key('AuthenticationProvider'), True)
161+
162+
except (CompareException, PyWLSTException), te:
163+
return_code = 2
164+
self._logger.severe('WLSDPLY-05709',
165+
te.getLocalizedMessage(), error=te,
166+
class_name=self._program_name, method_name=_method_name)
167+
168+
if os.path.exists(_temp_dir):
169+
shutil.rmtree(_temp_dir)
170+
171+
self.assertEqual(return_code, 0)
172+
125173
def testCompareModelInvalidModel(self):
126174
_method_name = 'testCompareModelInvalidModel'
127175

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2021, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
# Test to check omit of custom provider from diffed model. But known providers should be in changes.
4+
topology:
5+
SecurityConfiguration:
6+
Realm:
7+
myrealm:
8+
Auditor:
9+
CustomAudit:
10+
myorg.audit.providers.ECCustomAudit:
11+
ControlFlag: REQUIRED
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2021, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
# Test to check omit of custom provider from diffed model. But known providers should be in changes.
4+
topology:
5+
SecurityConfiguration:
6+
Realm:
7+
myrealm:
8+
Auditor:
9+
CustomAudit:
10+
myorg.audit.providers.ECCustomAudit:
11+
ControlFlag: OPTIONAL
12+
AuthenticationProvider:
13+
DefaultIdentityAsserter:
14+
DefaultIdentityAsserter:
15+
DefaultUserNameMapperAttributeType: CN
16+
ActiveType: [ 'AuthenticatedUser', 'X.509' ]
17+
DefaultUserNameMapperAttributeDelimiter: ','
18+
UseDefaultUserNameMapper: true

0 commit comments

Comments
 (0)