Skip to content

Commit 111c089

Browse files
authored
Use a custom set method to handle pre-encrypting an attribute (#1132)
1 parent 6f95c93 commit 111c089

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

core/src/main/python/wlsdeploy/tool/create/creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, model, model_context, aliases, exception_type=ExceptionType.C
3636
self.model = Model(model)
3737
self.model_context = model_context
3838
self.wls_helper = WebLogicHelper(self.logger)
39-
self.attribute_setter = AttributeSetter(self.aliases, self.logger, exception_type)
39+
self.attribute_setter = AttributeSetter(self.model_context, self.aliases, exception_type)
4040
self.custom_folder_helper = CustomFolderHelper(self.aliases, self.logger, self.model_context, exception_type)
4141

4242
# Must be initialized by the subclass since only it has

core/src/main/python/wlsdeploy/tool/deploy/deployer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, model, model_context, aliases, wlst_mode=WlstModes.OFFLINE):
5252
self.logger = PlatformLogger('wlsdeploy.deploy')
5353
self.wls_helper = WebLogicHelper(self.logger)
5454
self.wlst_helper = WlstHelper(ExceptionType.DEPLOY)
55-
self.attribute_setter = AttributeSetter(self.aliases, self.logger, ExceptionType.DEPLOY, wlst_mode=wlst_mode)
55+
self.attribute_setter = AttributeSetter(model_context, self.aliases, ExceptionType.DEPLOY, wlst_mode=wlst_mode)
5656
self.topology_helper = TopologyHelper(self.aliases, ExceptionType.DEPLOY, self.logger)
5757

5858
self.archive_helper = None

core/src/main/python/wlsdeploy/tool/util/attribute_setter.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@
7373
from wlsdeploy.aliases.model_constants import XML_REGISTRY
7474
from wlsdeploy.aliases.wlst_modes import WlstModes
7575
from wlsdeploy.exception import exception_helper
76+
from wlsdeploy.logging.platform_logger import PlatformLogger
7677
from wlsdeploy.tool.util.wlst_helper import WlstHelper
7778
from wlsdeploy.util import model_helper
79+
from wlsdeploy.util.weblogic_helper import WebLogicHelper
7880

7981

8082
class AttributeSetter(object):
@@ -140,13 +142,15 @@ class AttributeSetter(object):
140142
]
141143

142144
_class_name = "AttributeSetter"
145+
__logger = PlatformLogger('wlsdeploy.tool.util')
143146

144-
def __init__(self, aliases, logger, exception_type, wlst_mode=WlstModes.OFFLINE):
145-
self.__logger = logger
147+
def __init__(self, model_context, aliases, exception_type, wlst_mode=WlstModes.OFFLINE):
148+
self.__model_context = model_context
146149
self.__exception_type = exception_type
147150
self.__wlst_mode = wlst_mode
148151
self.__aliases = aliases
149152
self.__wlst_helper = WlstHelper(exception_type)
153+
self.__weblogic_helper = WebLogicHelper(self.__logger)
150154

151155
#
152156
# public set_ methods for special attribute types, signature (self, location, key, value, wlst_value, ...)
@@ -594,7 +598,7 @@ def set_jvm_args(self, location, key, value, wlst_value):
594598
:param key: the attribute name
595599
:param value: the string value
596600
:param wlst_value: the existing value of the attribute from WLST
597-
:raises BundleAwareException of the specified type: if target is not found
601+
:raises BundleAwareException of the specified type: if an error occurs
598602
"""
599603
if value is None or len(value) == 0:
600604
result = value
@@ -618,7 +622,7 @@ def set_boolean(self, location, key, value, wlst_value):
618622
:param key: the attribute name
619623
:param value: the string value
620624
:param wlst_value: the existing value of the attribute from WLST
621-
:raises BundleAwareException of the specified type: if target is not found
625+
:raises BundleAwareException of the specified type: if an error occurs
622626
"""
623627
result = alias_utils.convert_to_type(BOOLEAN, value)
624628
result = result == 'true'
@@ -633,14 +637,29 @@ def set_with_ssl_enabled(self, location, key, value, wlst_value):
633637
:param key: the attribute name
634638
:param value: the new attribute value
635639
:param wlst_value: the existing value of the attribute from WLST
636-
:raises BundleAwareException of the specified type: if target is not found
640+
:raises BundleAwareException of the specified type: if an error occurs
637641
"""
638642
wlst_enabled_attribute = self.__aliases.get_wlst_attribute_name(location, ENABLED)
639643
was_enabled = self.__wlst_helper.get(wlst_enabled_attribute)
640644
self.set_attribute(location, ENABLED, True)
641645
self.set_attribute(location, key, value, wlst_merge_value=wlst_value)
642646
self.set_attribute(location, ENABLED, was_enabled)
643647

648+
def set_encrypted(self, location, key, value, wlst_value):
649+
"""
650+
Set the specified attribute with a pre-encrypted value in the current location.
651+
This is required when WLST does not encrypt a plain-text value during set() as it normally does.
652+
This can happen when offline WLST does not include an attribute in a hard-coded list of encrypted values.
653+
Currently, only OracleIdentityCloudIntegrator/ClientSecretEncrypted offline has this issue.
654+
:param location: the location
655+
:param key: the attribute name
656+
:param value: the new attribute value
657+
:param wlst_value: the existing value of the attribute from WLST
658+
:raises BundleAwareException of the specified type: if an error occurs
659+
"""
660+
encrypted_value = self.__weblogic_helper.encrypt(str(value), self.__model_context.get_domain_home())
661+
self.set_attribute(location, key, encrypted_value, wlst_merge_value=wlst_value)
662+
644663
#
645664
# public set_attribute convenience methods
646665
#

core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/SecurityConfiguration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@
607607
"ClientIdResourceAttribute": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ClientIdResourceAttribute", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ],
608608
"ClientIdTokenClaim": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ClientIdTokenClaim", "wlst_path": "WP001", "default_value": "client_id", "wlst_type": "string" } ],
609609
"ClientNameTokenClaim": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ClientNameTokenClaim", "wlst_path": "WP001", "default_value": "client_name", "wlst_type": "string" } ],
610-
"ClientSecretEncrypted": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ClientSecretEncrypted", "wlst_path": "WP001", "default_value": null, "wlst_type": "password" } ],
610+
"ClientSecretEncrypted": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ClientSecretEncrypted", "wlst_path": "WP001", "default_value": null, "wlst_type": "password", "set_method": "MBEAN.set_encrypted"} ],
611611
"ClientTenant": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ClientTenant", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ],
612612
"ConnectTimeout": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ConnectTimeout", "wlst_path": "WP001", "default_value": "${0:60}", "wlst_type": "integer" } ],
613613
"ControlFlag": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "ControlFlag", "wlst_path": "WP001", "default_value": "${__NULL__:REQUIRED}", "wlst_type": "string" } ],

core/src/test/python/alias_json_file_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from wlsdeploy.exception.expection_types import ExceptionType
5959
from wlsdeploy.tool.util.attribute_setter import AttributeSetter
6060
from wlsdeploy.util import dictionary_utils
61+
from wlsdeploy.util.model_context import ModelContext
6162

6263

6364
class ListTestCase(unittest.TestCase):
@@ -574,7 +575,8 @@ def _verify_attribute_set_method(self, folder_name, attribute_name, wlst_mode, a
574575
if len(set_method_value_components) == 2:
575576
invoker = set_method_value_components[1]
576577

577-
instance = AttributeSetter(aliases, None, ExceptionType.ALIAS, wlst_mode)
578+
model_context = ModelContext("test", {})
579+
instance = AttributeSetter(model_context, aliases, ExceptionType.ALIAS, wlst_mode)
578580
try:
579581
getattr(instance, invoker)
580582
except AttributeError:

0 commit comments

Comments
 (0)