Skip to content

Commit b6da6e8

Browse files
rakillenrobertpatrick
authored andcommitted
Correctly assign groups to parent groups in the Security section - WDT 4.0
1 parent 0a0890d commit b6da6e8

File tree

5 files changed

+86
-21
lines changed

5 files changed

+86
-21
lines changed

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

+70-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
2-
Copyright (c) 2021, 2023, Oracle and/or its affiliates.
2+
Copyright (c) 2021, 2024, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5+
import re
6+
57
from java.io import File
68

79
from com.octetstring.vde.util import PasswordEncryptor
@@ -25,6 +27,7 @@
2527
SECURITY_SUBDIR = 'security'
2628
GROUP_MAPPINGS = 'group'
2729
USER_MAPPINGS = 'user'
30+
EXISTING_ENTRIES = 'existingEntries'
2831

2932
# template hash constants
3033
HASH_NAME = 'name'
@@ -34,6 +37,12 @@
3437
HASH_USER_PASSWORD = 'password'
3538
HASH_ATTRIBUTES = 'userattr'
3639
HASH_ATTRIBUTE = 'attribute'
40+
HASH_EXISTING_LINES = 'existingLines'
41+
HASH_EXISTING_TEXT = 'existingText'
42+
HASH_CHILD_GROUPS = 'childGroups'
43+
HASH_CHILD_GROUP_NAME = 'childGroupName'
44+
45+
CN_REGEX = re.compile('^cn: (.+)$')
3746

3847

3948
class DefaultAuthenticatorHelper(object):
@@ -61,21 +70,22 @@ def create_default_init_file(self, security_mapping_nodes):
6170
"""
6271
_method_name = 'create_default_init_file'
6372

64-
template_hash = self._build_default_template_hash(security_mapping_nodes)
65-
template_path = TEMPLATE_PATH + '/' + DEFAULT_AUTH_INIT_FILE + file_template_helper.MUSTACHE_SUFFIX
66-
6773
output_dir = File(self._model_context.get_domain_home(), SECURITY_SUBDIR)
68-
output_file = File(output_dir, DEFAULT_AUTH_INIT_FILE)
74+
init_file = File(output_dir, DEFAULT_AUTH_INIT_FILE)
6975

70-
self._logger.info('WLSDPLY-01900', output_file,
76+
template_hash = self._build_default_template_hash(security_mapping_nodes, init_file)
77+
template_path = TEMPLATE_PATH + '/' + DEFAULT_AUTH_INIT_FILE + file_template_helper.MUSTACHE_SUFFIX
78+
79+
self._logger.info('WLSDPLY-01900', init_file,
7180
class_name=self._class_name, method_name=_method_name)
7281

73-
file_template_helper.append_file_from_resource(template_path, template_hash, output_file, self._exception_type)
82+
file_template_helper.create_file_from_resource(template_path, template_hash, init_file, self._exception_type)
7483

75-
def _build_default_template_hash(self, mapping_section_nodes):
84+
def _build_default_template_hash(self, mapping_section_nodes, init_file):
7685
"""
7786
Create a dictionary of substitution values to apply to the default authenticator template.
7887
:param mapping_section_nodes: the security elements from the model
88+
:param init_file: java.io.File containing original LDIFT entries
7989
:return: the template hash dictionary
8090
"""
8191
_method_name = '_build_default_template_hash'
@@ -89,6 +99,7 @@ def _build_default_template_hash(self, mapping_section_nodes):
8999
for name in group_mapping_nodes:
90100
mapping_hash = self._build_group_mapping_hash(group_mapping_nodes[name], name)
91101
group_mappings.append(mapping_hash)
102+
92103
if USER in mapping_section_nodes.keys():
93104
user_mapping_nodes = mapping_section_nodes[USER]
94105
for name in user_mapping_nodes:
@@ -99,10 +110,61 @@ def _build_default_template_hash(self, mapping_section_nodes):
99110
self._logger.warning('WLSDPLY-01902', name, ce.getLocalizedMessage(),
100111
error=ce, class_name=self._class_name, method_name=_method_name)
101112

113+
# build a map of group names to group children
114+
group_child_map = {}
115+
for group_mapping in group_mappings:
116+
group_name = group_mapping[HASH_NAME]
117+
member_of_groups = group_mapping[HASH_GROUPS]
118+
for member_of_group in member_of_groups:
119+
member_of_name = member_of_group[HASH_GROUP]
120+
if not dictionary_utils.get_element(group_child_map, member_of_name):
121+
group_child_map[member_of_name] = []
122+
group_child_map[member_of_name].append({HASH_CHILD_GROUP_NAME: group_name})
123+
124+
# assign group child names to groups
125+
for group_mapping in group_mappings:
126+
group_name = group_mapping[HASH_NAME]
127+
child_groups = dictionary_utils.get_element(group_child_map, group_name)
128+
if child_groups:
129+
group_mapping[HASH_CHILD_GROUPS] = child_groups
130+
102131
template_hash[GROUP_MAPPINGS] = group_mappings
103132
template_hash[USER_MAPPINGS] = user_mappings
133+
template_hash[EXISTING_ENTRIES] = self._build_existing_entries_list(init_file, group_child_map)
104134
return template_hash
105135

136+
def _build_existing_entries_list(self, init_file, group_child_map):
137+
"""
138+
Create a list of existing group entries from the original LDIFT file.
139+
Each entry is a list of string declarations, and a list of any child groups.
140+
:param init_file: java.io.File containing original LDIFT entries
141+
:param group_child_map: a map of group names to child group names
142+
:return: the existing entries list
143+
"""
144+
init_reader = open(init_file.getPath(), 'r')
145+
init_lines = init_reader.readlines()
146+
init_reader.close()
147+
148+
existing_entry = None
149+
existing_entries = []
150+
for init_line in init_lines:
151+
line_text = init_line.strip()
152+
if len(line_text) == 0:
153+
existing_entry = None
154+
else:
155+
if existing_entry is None:
156+
existing_entry = {HASH_EXISTING_LINES: [], HASH_CHILD_GROUPS: []}
157+
existing_entries.append(existing_entry)
158+
existing_entry[HASH_EXISTING_LINES].append({HASH_EXISTING_TEXT: line_text})
159+
160+
match = re.match(CN_REGEX, line_text)
161+
if match:
162+
child_groups = dictionary_utils.get_element(group_child_map, match.group(1))
163+
if child_groups:
164+
existing_entry[HASH_CHILD_GROUPS] = child_groups
165+
166+
return existing_entries
167+
106168
def _build_group_mapping_hash(self, group_mapping_section, name):
107169
"""
108170
Build a template hash for the specified mapping element from the model.

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ WLSDPLY-01840=Encryption failed: Unable to locate SerializedSystemIni
495495
WLSDPLY-01841=Encryption failed: Unable to initialize encryption service
496496

497497
# wlsdeploy/tool/util/default_authenticator_helper.py
498-
WLSDPLY-01900=Append to default authenticator initialization file {0}
498+
WLSDPLY-01900=Updating default authenticator initialization file {0}
499499
WLSDPLY-01901=Failed to encrypt password for user {0}: {1}
500500
WLSDPLY-01902=Unable to add user {0} due to an error: {1}
501501

core/src/main/resources/oracle/weblogic/deploy/security/DefaultAuthenticatorInit.ldift.mustache

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
{{#group}}
1+
{{#existingEntries}}
2+
{{#existingLines}}
3+
{{{existingText}}}
4+
{{/existingLines}}
5+
{{#childGroups}}
6+
uniquemember: cn={{{childGroupName}}},ou=groups,ou=@realm@,dc=@domain@
7+
{{/childGroups}}
28

9+
{{/existingEntries}}
10+
{{#group}}
311
dn: cn={{{name}}},ou=groups,ou=@realm@,dc=@domain@
412
memberURL: ldap:///ou=people,ou=@realm@,dc=@domain@??sub?(&(objectclass=person)(wlsMemberOf=cn={{{name}}},ou=groups,ou=@realm@,dc=@domain@))
513
description: {{{description}}}
614
objectclass: top
715
objectclass: groupOfURLs
816
objectclass: groupOfUniqueNames
917
cn: {{{name}}}
10-
{{#groups}}
11-
uniquemember: cn={{{groupMemberOf}}},ou=groups,ou=@realm@,dc=@domain@
12-
{{/groups}}
18+
{{#childGroups}}
19+
uniquemember: cn={{{childGroupName}}},ou=groups,ou=@realm@,dc=@domain@
20+
{{/childGroups}}
21+
1322
{{/group}}
1423
{{#user}}
1524

@@ -30,4 +39,5 @@ wlsMemberOf: cn={{{groupMemberOf}}},ou=groups,ou=@realm@,dc=@domain@
3039
{{#userattr}}
3140
{{{attribute}}}
3241
{{/userattr}}
33-
{{/user}}
42+
43+
{{/user}}

documentation/4.0/content/samples/usersgroups-model.md

-1
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,4 @@ Don't forget that the values of these fields may need to be enclosed in quotes i
104104
- The processing of users, groups, and roles will only take place when using the [Create Domain Tool]({{< relref "/userguide/tools/create.md" >}}).
105105
- WebLogic global roles are only supported with WebLogic Server version 12.2.1 or greater.
106106
- WebLogic global roles are only updated for the WebLogic security XACML role mapping provider (for example, `XACMLRoleMapper`).
107-
- The user and group processing is not complete, currently, users cannot be assigned to groups. Users created using the `Security` section are automatically added to the `Administrators` group and are not added to the groups specified. For information about a patch for this issue, see [Known issues]({{< relref "/release-notes#assigning-security-groups-to-users" >}}).
108107
- Currently, WDT does not support modifying the default WebLogic authorization policies.

documentation/4.0/content/userguide/limitations/limitations.md

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ java.lang.IllegalArgumentException: In production mode, it's not allowed to set
3737
```
3838
**ACTION**: Contact Oracle Support to obtain the patch for bug number 30874677 for your WebLogic Server version before running the tool.
3939

40-
#### Assigning security groups to users
41-
42-
**ISSUE**: For WLS versions prior to 14.1.1, there is a problem setting the `GroupMemberOf` attribute in the `topology/Security/User` folder. The value is not persisted correctly, and the assignment will not be present when the domain is started.
43-
44-
**ACTION**: Contact Oracle Support to obtain the patch for bug number 30319071 for your WebLogic Server version before running the tool.
45-
4640
#### Problems setting `RotateLogOnStartup` attribute
4741

4842
**ISSUE**: For existing WLS versions, there is a problem setting the `RotateLogOnStartup` attribute in various log file folders. The value is not persisted correctly, and the assignment will not be present when the domain is started.

0 commit comments

Comments
 (0)