Skip to content

Commit b06264b

Browse files
Wdt 462 security configuration defaults (#721)
* WDT remove SecurityConfiguration defaults from model * Clean up SecurityConfiguration for online
1 parent b6a19d0 commit b06264b

File tree

9 files changed

+188
-28
lines changed

9 files changed

+188
-28
lines changed

core/src/main/python/wlsdeploy/aliases/alias_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
DEFAULT_NAME_VALUE = 'default_name_value'
1515
FLATTENED_FOLDER_DATA = 'flattened_folder_data'
1616
FOLDERS = 'folders'
17+
FOLDER_ORDER = 'folder_order'
1718
FOLDER_PARAMS = 'folder_params'
1819
GET_MBEAN_TYPE = 'get_mbean_type'
1920
GET_METHOD = 'get_method'

core/src/main/python/wlsdeploy/aliases/alias_entries.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from wlsdeploy.aliases.alias_constants import CONTAINS
1919
from wlsdeploy.aliases.alias_constants import DEFAULT_NAME_VALUE
2020
from wlsdeploy.aliases.alias_constants import FLATTENED_FOLDER_DATA
21+
from wlsdeploy.aliases.alias_constants import FOLDER_ORDER
2122
from wlsdeploy.aliases.alias_constants import FOLDER_PARAMS
2223
from wlsdeploy.aliases.alias_constants import FOLDERS
2324
from wlsdeploy.aliases.alias_constants import GET_MBEAN_TYPE
@@ -903,6 +904,47 @@ def is_model_location_valid(self, location):
903904
return False
904905
return True
905906

907+
def get_folders_in_order_for_location(self, location):
908+
"""
909+
Find the folders that are ordered (greater than zero) at the specified location and
910+
return the list in order of the
911+
:param location:
912+
:return:
913+
"""
914+
_method_name = 'get_folders_in_order_for_location'
915+
holder = dict()
916+
for subfolder in self.get_model_subfolder_names_for_location(location):
917+
result = self.get_folder_order_for_location(location, subfolder)
918+
if result > 0:
919+
if result in holder:
920+
ex = exception_helper.create_alias_exception('WLSDPLY-08137', subfolder, holder[result])
921+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
922+
raise ex
923+
holder[result] = subfolder
924+
925+
result = list()
926+
keys = holder.keys()
927+
keys.sort()
928+
for key in keys:
929+
result.append(holder[key])
930+
931+
return result
932+
933+
def get_folder_order_for_location(self, parent_location, subfolder_name):
934+
"""
935+
Get the order for the subfolder named under the provided location.
936+
:param parent_location: location of the subfolder
937+
:param subfolder_name: name of the subfolder
938+
:return: folder order of the subfolder or 0 if not ordered
939+
"""
940+
location = LocationContext(parent_location)
941+
location.append_location(subfolder_name)
942+
folder_dict = self.__get_dictionary_for_location(location, False)
943+
result = 0
944+
if FOLDER_ORDER in folder_dict:
945+
result = int(folder_dict[FOLDER_ORDER])
946+
return result
947+
906948
def get_folder_short_name_for_location(self, location):
907949
"""
908950
Retrieve the shortened name for the model folder at the provided location.
@@ -1176,6 +1218,9 @@ def __apply_wlst_context_changes(self, path_name, alias_dict, parent_dict):
11761218
if SHORT_NAME in alias_dict:
11771219
result[SHORT_NAME] = alias_dict[SHORT_NAME]
11781220

1221+
if FOLDER_ORDER in alias_dict:
1222+
result[FOLDER_ORDER] = alias_dict[FOLDER_ORDER]
1223+
11791224
if WLST_PATHS in alias_dict:
11801225
wlst_paths = alias_dict[WLST_PATHS]
11811226
result_wlst_paths = dict()

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,19 @@ def supports_multiple_mbean_instances(self, location):
307307
except AliasException, ae:
308308
self._raise_exception(ae, _method_name, 'WLSDPLY-19008', str(location), ae.getLocalizedMessage())
309309

310+
def get_subfolders_in_order(self, location):
311+
"""
312+
Return the sub-folder names that have an order in the order defined.
313+
:param location: location of the ordered sub-folders
314+
:return: list of sub-folder names in order
315+
"""
316+
_method_name = 'get_subfolders_in_order'
317+
try:
318+
return self._alias_entries.get_folders_in_order_for_location(location)
319+
except AliasException, ae:
320+
self._raise_exception(ae, _method_name, 'WLSDPLY-19044',
321+
location.get_folder_path(), ae.getLocalizedMessage())
322+
310323
def requires_artificial_type_subfolder_handling(self, location):
311324
"""
312325
Does the location folder specified both support multiple MBean instances of the parent node type

core/src/main/python/wlsdeploy/tool/discover/discoverer.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def _discover_subfolder_with_single_name(self, model_subfolder_name, location, n
386386
_logger.exiting(class_name=_class_name, method_name=_method_name)
387387
return result
388388

389-
def _discover_artificial_folder(self, model_subfolder_type, location, name_token):
389+
def _discover_artificial_folder(self, model_subfolder_type, location, name_token, check_order=False):
390390
"""
391391
Discover the subfolder that has an artificial connection; the subfolder contains multiple different types
392392
under one MBean. The model must contain the subfolder type, the artificial type that specifies which it is,
@@ -395,13 +395,17 @@ def _discover_artificial_folder(self, model_subfolder_type, location, name_token
395395
:param model_subfolder_type: type of the model subfolder
396396
:param location: context containing the current location information
397397
:param name_token: for use in the location to contain the folder name
398+
:param check_order: if true, check the subfolders for order
398399
:return: dictionary containing the discovered folder attributes
399400
"""
400401
_method_name = '_discover_artifical_folder'
401402
_logger.entering(model_subfolder_type, str(location), name_token, class_name=_class_name,
402403
method_name=_method_name)
403404
subfolder_result = OrderedDict()
404405
names = self._find_names_in_folder(location)
406+
required_order = self._aliases.get_subfolders_in_order(location)
407+
attr_map = dict()
408+
default_list = list()
405409
if names is not None:
406410
for name in names:
407411
massaged = self._inspect_artificial_folder_name(name, location)
@@ -411,6 +415,9 @@ def _discover_artificial_folder(self, model_subfolder_type, location, name_token
411415
if self._aliases.is_custom_folder_allowed(location):
412416
_logger.fine('WLSDPLY-06148', model_subfolder_type, massaged, location.get_folder_path(),
413417
class_name=_class_name, method_name=_method_name)
418+
# doesn't matter how many parameters, it is automatically a non-default name
419+
default_list.append(massaged)
420+
attr_map[massaged] = 0
414421
subfolder_result.update(
415422
self._custom_folder.discover_custom_mbean(location, model_subfolder_type, massaged))
416423
else:
@@ -423,8 +430,23 @@ def _discover_artificial_folder(self, model_subfolder_type, location, name_token
423430
subfolder_result[massaged] = OrderedDict()
424431
subfolder_result[massaged][artificial] = OrderedDict()
425432
self._populate_model_parameters(subfolder_result[massaged][artificial], location)
433+
default_list.append(artificial)
434+
attr_map[artificial] = len(subfolder_result[massaged][artificial])
426435
location.pop_location()
427436
location.remove_name_token(name_token)
437+
438+
# check to see if the order and number of the subfolder list is same as required order
439+
is_default = False
440+
if check_order and len(required_order) == len(default_list):
441+
is_default = True
442+
idx = 0
443+
while idx < len(required_order):
444+
if required_order[idx] != default_list[idx] or attr_map[default_list[idx]] > 0:
445+
is_default = False
446+
break
447+
idx += 1
448+
if is_default:
449+
subfolder_result = None
428450
_logger.exiting(class_name=_class_name, method_name=_method_name, result=subfolder_result)
429451
return subfolder_result
430452

@@ -458,12 +480,13 @@ def _discover_subfolder_with_names(self, model_subfolder_name, location, name_to
458480
_logger.exiting(class_name=_class_name, method_name=_method_name)
459481
return subfolder_result
460482

461-
def _discover_subfolder(self, model_subfolder_name, location, result=None):
483+
def _discover_subfolder(self, model_subfolder_name, location, result=None, check_order=False):
462484
"""
463485
Discover the subfolder indicated by the model subfolder name. Append the model subfolder to the
464486
current location context, and pop that location before return
465487
:param model_subfolder_name: Name of the model subfolder
466488
:param location: context containing the current subfolder information
489+
:param check_order: does the folder need to be checked for order
467490
:return: discovered dictionary
468491
"""
469492
_method_name = '_discover_subfolder'
@@ -485,22 +508,29 @@ def _discover_subfolder(self, model_subfolder_name, location, result=None):
485508
subfolder_result = self._discover_subfolder_with_single_name(model_subfolder_name, location,
486509
name_token)
487510
elif self._aliases.requires_artificial_type_subfolder_handling(location):
488-
subfolder_result = self._discover_artificial_folder(model_subfolder_name, location, name_token)
511+
subfolder_result = self._discover_artificial_folder(
512+
model_subfolder_name, location, name_token, check_order)
489513
else:
490514
subfolder_result = self._discover_subfolder_with_names(model_subfolder_name, location,
491515
name_token)
492516
else:
493517
subfolder_result = self._discover_subfolder_singleton(model_subfolder_name, location)
494-
add_to_model_if_not_empty(result, model_subfolder_name, subfolder_result)
518+
# this is a really special case. Empty means not-default it is empty
519+
if self._aliases.requires_artificial_type_subfolder_handling(location):
520+
if subfolder_result is not None:
521+
add_to_model(result, model_subfolder_name, subfolder_result)
522+
else:
523+
add_to_model_if_not_empty(result, model_subfolder_name, subfolder_result)
495524
location.pop_location()
496525
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
497526
return result
498527

499-
def _discover_subfolders(self, result, location):
528+
def _discover_subfolders(self, result, location, check_order=False):
500529
"""
501530
Discover the rest of the mbean hierarchy at the current location.
502531
:param result: dictionary where to store the discovered subfolders
503532
:param location: context containing current location information
533+
:param check_order: True if artificial folder has an order to check
504534
:return: populated dictionary
505535
"""
506536
_method_name = '_discover_subfolders'
@@ -511,7 +541,7 @@ def _discover_subfolders(self, result, location):
511541
model_subfolder_name = self._get_model_name(location, wlst_subfolder)
512542
# will return a None if subfolder not in current wls version
513543
if model_subfolder_name is not None:
514-
result = self._discover_subfolder(model_subfolder_name, location, result)
544+
result = self._discover_subfolder(model_subfolder_name, location, result, check_order)
515545
_logger.finest('WLSDPLY-06114', str(location), class_name=_class_name, method_name=_method_name)
516546
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
517547
return result
@@ -790,6 +820,15 @@ def add_to_model_if_not_empty(dictionary, entry_name, entry_value):
790820
return False
791821

792822

823+
def add_to_model(dictionary, entry_name, entry_value):
824+
"""
825+
Add this to the model even if empty
826+
:param dictionary: to add the value
827+
:param entry_name: name of the key
828+
:param entry_value: dictionary to add
829+
"""
830+
dictionary[entry_name] = entry_value
831+
793832
def convert_to_absolute_path(relative_to, file_name):
794833
"""
795834
Transform the path by joining the relative_to before the file_name and converting the resulting path name to

core/src/main/python/wlsdeploy/tool/discover/topology_discoverer.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from wlsdeploy.tool.discover.discoverer import Discoverer
2525
from wlsdeploy.tool.util.variable_injector import VARIABLE_SEP
2626
from wlsdeploy.tool.util.wlst_helper import WlstHelper
27+
from wlsdeploy.util import dictionary_utils
2728
from wlsdeploy.util import string_utils
2829
from wlsdeploy.util import variables
2930

@@ -323,14 +324,43 @@ def discover_security_configuration(self):
323324
location.add_name_token(self._aliases.get_name_token(location), security_configuration)
324325
self._populate_model_parameters(result, location)
325326
self._massage_security_credential(result, location)
326-
try:
327-
self._discover_subfolders(result, location)
328-
except DiscoverException, de:
329-
_logger.warning('WLSDPLY-06200', self._wls_version, de.getLocalizedMessage(),
330-
class_name=_class_name, method_name=_method_name)
331-
result = OrderedDict()
332-
_logger.exiting(class_name=_class_name, method_name=_method_name)
333-
return model_top_folder_name, result
327+
location.append_location(model_constants.REALM)
328+
result[model_constants.REALM] = OrderedDict()
329+
realms = self._find_names_in_folder(location)
330+
for realm in realms:
331+
name_token = self._aliases.get_name_token(location)
332+
location.add_name_token(name_token, realm)
333+
result[model_constants.REALM][realm] = OrderedDict()
334+
self._populate_model_parameters(result[model_constants.REALM][realm], location)
335+
if realm == 'myrealm':
336+
check_order=True
337+
else:
338+
check_order=False
339+
try:
340+
self._discover_subfolders(result[model_constants.REALM][realm], location, check_order)
341+
location.remove_name_token(name_token)
342+
except DiscoverException, de:
343+
_logger.warning('WLSDPLY-06200', self._wls_version, de.getLocalizedMessage(),
344+
class_name=_class_name, method_name=_method_name)
345+
result = OrderedDict()
346+
347+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=model_top_folder_name)
348+
return model_top_folder_name, self._slim_security_config(result)
349+
350+
def _slim_security_config(self, sc_dict):
351+
"""
352+
Check the default realm 'myrealm' for any customization. Remove the parts of the SecurityConfiguration that
353+
are defaulted to the way installed by the WLS template. If the entire SecurityConfiguration is the default,
354+
remove the SecurityConfiguration section.
355+
:param sc_dict: SecurityConfiguration section of model
356+
:return: converted_dictionary with defaults removed
357+
"""
358+
realm_dict = dictionary_utils.get_dictionary_element(sc_dict, model_constants.REALM)
359+
if 'myrealm' in realm_dict and dictionary_utils.is_empty_dictionary_element(realm_dict, 'myrealm'):
360+
del sc_dict[model_constants.REALM]['myrealm']
361+
if dictionary_utils.is_empty_dictionary_element(sc_dict, model_constants.REALM):
362+
del sc_dict[model_constants.REALM]
363+
return sc_dict
334364

335365
def get_embedded_ldap_configuration(self):
336366
"""

0 commit comments

Comments
 (0)