Skip to content

Commit d5583ae

Browse files
committed
Merge branch 'jira-wdt-892-security-misc' into 'main'
Argument check for discover security providers; ActiveContextHandlerEntry list alias fix See merge request weblogic-cloud/weblogic-deploy-tooling!1707
2 parents 33b796f + 3518f12 commit d5583ae

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

core/src/main/python/discover.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,26 @@ def __validate_discover_passwords_and_security_data_args(model_context, argument
324324
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
325325
raise ex
326326

327-
if model_context.is_discover_passwords() and model_context.is_encrypt_discovered_passwords():
328-
# With -discover_passwords, we always need the WDT encryption passphrase and JDK8 or above.
327+
# check if any argument requires password discovery
328+
passwords_argument = None
329+
if model_context.is_discover_passwords():
330+
passwords_argument = CommandLineArgUtil.DISCOVER_PASSWORDS_SWITCH
331+
elif model_context.is_discover_security_provider_passwords():
332+
passwords_argument = CommandLineArgUtil.DISCOVER_SECURITY_PROVIDER_DATA_SWITCH + " " \
333+
+ model_context.get_discover_security_provider_data_types_label()
334+
335+
if passwords_argument and model_context.is_encrypt_discovered_passwords():
336+
# To discover encrypted passwords, we always need the WDT encryption passphrase and JDK8 or above.
329337
if not is_encryption_supported:
330338
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-06057',
331-
_program_name, CommandLineArgUtil.DISCOVER_PASSWORDS_SWITCH,
339+
_program_name, passwords_argument,
332340
System.getProperty('java.version'))
333341
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
334342
raise ex
335343

336344
if model_context.get_encryption_passphrase() is None:
337345
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, 'WLSDPLY-06051',
338-
_program_name, CommandLineArgUtil.DISCOVER_PASSWORDS_SWITCH,
346+
_program_name, passwords_argument,
339347
CommandLineArgUtil.PASSPHRASE_ENV_SWITCH,
340348
CommandLineArgUtil.PASSPHRASE_FILE_SWITCH,
341349
CommandLineArgUtil.PASSPHRASE_PROMPT_SWITCH)

core/src/main/python/wlsdeploy/util/model_context.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,15 @@ def _is_discover_security_provider_data_type(self, scope):
12841284
result = True
12851285
return result
12861286

1287+
def is_discover_security_provider_passwords(self):
1288+
# These security providers have model passwords
1289+
return self.is_discover_default_authenticator_data() or self.is_discover_default_credential_mapper_data()
1290+
1291+
def get_discover_security_provider_data_types_label(self):
1292+
# Result should only be used for display or logging
1293+
data_types = self._discover_security_provider_data or []
1294+
return ','.join(data_types)
1295+
12871296
def is_discover_opss_wallet(self):
12881297
return self._discover_opss_wallet
12891298

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
@@ -117,7 +117,7 @@
117117
"child_folders_type": "none",
118118
"folders": {},
119119
"attributes" : {
120-
"ActiveContextHandlerEntry": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "ActiveContextHandlerEntr${y:ies}", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ],
120+
"ActiveContextHandlerEntry": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "ActiveContextHandlerEntr${y:ies}", "wlst_path": "WP001", "default_value": null, "wlst_type": "${list:jarray}", "wlst_read_type": "delimited_string[semicolon]", "get_method": "${LSA:GET}", "preferred_model_type": "list" } ],
121121
"BeginMarker": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "BeginMarker", "wlst_path": "WP001", "default_value": "#### Audit Record Begin", "wlst_type": "string", "get_method": "${LSA:GET}"} ],
122122
"CompatibilityObjectName": [ {"version": "[10,)", "wlst_mode": "offline", "wlst_name": "CompatibilityObjectName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ],
123123
"Description": [ {"version": "[10,)", "wlst_mode": "online", "wlst_name": "Description", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "access": "IGNORED" } ],
Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
"""
2-
Copyright (c) 2020, 2023, Oracle and/or its affiliates.
2+
Copyright (c) 2020, 2024, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
44
"""
55
import unittest
66

7+
from wlsdeploy.aliases.model_constants import ALL
8+
from wlsdeploy.aliases.model_constants import DEFAULT_AUTHENTICATOR
9+
from wlsdeploy.aliases.model_constants import DEFAULT_CREDENTIAL_MAPPER
10+
from wlsdeploy.aliases.model_constants import XACML_AUTHORIZER
11+
from wlsdeploy.aliases.model_constants import XACML_ROLE_MAPPER
712
from wlsdeploy.util.cla_utils import CommandLineArgUtil
813
from wlsdeploy.util.model_context import ModelContext
914

1015

11-
class ClaHelperTest(unittest.TestCase):
16+
class ModelContextTest(unittest.TestCase):
17+
__program_name = 'ModelContextTest'
1218

1319
def test_copy_model_context(self):
14-
__program_name = 'model_context_test'
1520
__oracle_home = '/my/oracle/home'
1621
__model_file = 'my_model_file.yaml'
1722

1823
arg_map = dict()
1924
arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH] = __oracle_home
20-
model_context = ModelContext(__program_name, arg_map)
21-
self.assertEquals(model_context.get_program_name(), __program_name)
25+
model_context = ModelContext(self.__program_name, arg_map)
26+
self.assertEquals(model_context.get_program_name(), self.__program_name)
2227
self.assertEquals(model_context.get_oracle_home(), __oracle_home)
2328
self.assertEquals(model_context.get_model_file(), None)
2429

2530
arg_map = dict()
2631
arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = __model_file
2732
model_context_copy = model_context.copy(arg_map)
28-
self.assertEquals(model_context_copy.get_program_name(), __program_name)
33+
self.assertEquals(model_context_copy.get_program_name(), self.__program_name)
2934
self.assertEquals(model_context_copy.get_oracle_home(), __oracle_home)
3035
self.assertEquals(model_context_copy.get_model_file(), __model_file)
3136

3237
def test_password_is_tokenized(self):
33-
__program_name = 'model_context_test'
34-
3538
__no_token_value = 'Welcome1'
3639
__complex_no_token_value = 'Abc@@def@@ghi'
3740
__secret_value = '@@SECRET:foo:username@@'
3841
__env_value = '@@ENV:FOO@@'
3942
__complex_token_value = '@@SECRET:foo:@@ENV:BAR@@@@'
4043

41-
model_context = ModelContext(__program_name)
44+
model_context = ModelContext(self.__program_name)
4245
self.assertEquals(model_context.password_is_tokenized(None), False)
4346
self.assertEquals(model_context.password_is_tokenized(__no_token_value), False)
4447
self.assertEquals(model_context.password_is_tokenized(__complex_no_token_value), False)
@@ -47,3 +50,25 @@ def test_password_is_tokenized(self):
4750
self.assertEquals(model_context.password_is_tokenized(__env_value), True)
4851
self.assertEquals(model_context.password_is_tokenized(__secret_value), True)
4952
self.assertEquals(model_context.password_is_tokenized(__complex_token_value), True)
53+
54+
def test_discover_security_provider_data_scopes(self):
55+
# Some security provider types contain passwords, requiring extra configuration for discover
56+
self._try_security_provider_data_scope(True, DEFAULT_AUTHENTICATOR)
57+
self._try_security_provider_data_scope(True, DEFAULT_CREDENTIAL_MAPPER)
58+
self._try_security_provider_data_scope(True, ALL)
59+
self._try_security_provider_data_scope(False, XACML_AUTHORIZER, XACML_ROLE_MAPPER)
60+
self._try_security_provider_data_scope(True, XACML_AUTHORIZER, DEFAULT_CREDENTIAL_MAPPER)
61+
self._try_security_provider_data_scope(True, XACML_ROLE_MAPPER, DEFAULT_CREDENTIAL_MAPPER)
62+
63+
def _try_security_provider_data_scope(self, expected_result, *args):
64+
scopes_text = ','.join(list(args))
65+
arg_map = {
66+
CommandLineArgUtil.DISCOVER_SECURITY_PROVIDER_DATA_SWITCH: scopes_text
67+
}
68+
model_context = ModelContext(self.__program_name, arg_map)
69+
70+
test_text = "should not"
71+
if expected_result:
72+
test_text = "should"
73+
self.assertEquals(model_context.is_discover_security_provider_passwords(), expected_result,
74+
"Security provider data scope " + scopes_text + " " + test_text + " discover passwords")

0 commit comments

Comments
 (0)