Skip to content

Commit e11caeb

Browse files
committed
Correctly assign groups to parent groups in the Security section
1 parent 0ce243e commit e11caeb

File tree

5 files changed

+86
-22
lines changed

5 files changed

+86
-22
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 Corporation 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
@@ -26,6 +28,7 @@
2628
SECURITY_SUBDIR = 'security'
2729
GROUP_MAPPINGS = 'group'
2830
USER_MAPPINGS = 'user'
31+
EXISTING_ENTRIES = 'existingEntries'
2932

3033
# template hash constants
3134
HASH_NAME = 'name'
@@ -35,6 +38,12 @@
3538
HASH_USER_PASSWORD = 'password'
3639
HASH_ATTRIBUTES = 'userattr'
3740
HASH_ATTRIBUTE = 'attribute'
41+
HASH_EXISTING_LINES = 'existingLines'
42+
HASH_EXISTING_TEXT = 'existingText'
43+
HASH_CHILD_GROUPS = 'childGroups'
44+
HASH_CHILD_GROUP_NAME = 'childGroupName'
45+
46+
CN_REGEX = re.compile('^cn: (.+)$')
3847

3948

4049
class DefaultAuthenticatorHelper(object):
@@ -62,21 +71,22 @@ def create_default_init_file(self, security_mapping_nodes):
6271
"""
6372
_method_name = 'create_default_init_file'
6473

65-
template_hash = self._build_default_template_hash(security_mapping_nodes)
66-
template_path = TEMPLATE_PATH + '/' + DEFAULT_AUTH_INIT_FILE
67-
6874
output_dir = File(self._model_context.get_domain_home(), SECURITY_SUBDIR)
69-
output_file = File(output_dir, DEFAULT_AUTH_INIT_FILE)
75+
init_file = File(output_dir, DEFAULT_AUTH_INIT_FILE)
7076

71-
self._logger.info('WLSDPLY-01900', output_file,
77+
template_hash = self._build_default_template_hash(security_mapping_nodes, init_file)
78+
template_path = TEMPLATE_PATH + '/' + DEFAULT_AUTH_INIT_FILE
79+
80+
self._logger.info('WLSDPLY-01900', init_file,
7281
class_name=self._class_name, method_name=_method_name)
7382

74-
file_template_helper.append_file_from_resource(template_path, template_hash, output_file, self._exception_type)
83+
file_template_helper.create_file_from_resource(template_path, template_hash, init_file, self._exception_type)
7584

76-
def _build_default_template_hash(self, mapping_section_nodes):
85+
def _build_default_template_hash(self, mapping_section_nodes, init_file):
7786
"""
7887
Create a dictionary of substitution values to apply to the default authenticator template.
7988
:param mapping_section_nodes: the security elements from the model
89+
:param init_file: java.io.File containing original LDIFT entries
8090
:return: the template hash dictionary
8191
"""
8292
_method_name = '_build_default_template_hash'
@@ -90,6 +100,7 @@ def _build_default_template_hash(self, mapping_section_nodes):
90100
for name in group_mapping_nodes:
91101
mapping_hash = self._build_group_mapping_hash(group_mapping_nodes[name], name)
92102
group_mappings.append(mapping_hash)
103+
93104
if USER in mapping_section_nodes.keys():
94105
user_mapping_nodes = mapping_section_nodes[USER]
95106
for name in user_mapping_nodes:
@@ -100,10 +111,61 @@ def _build_default_template_hash(self, mapping_section_nodes):
100111
self._logger.warning('WLSDPLY-01902', name, ce.getLocalizedMessage(),
101112
error=ce, class_name=self._class_name, method_name=_method_name)
102113

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

137+
def _build_existing_entries_list(self, init_file, group_child_map):
138+
"""
139+
Create a list of existing group entries from the original LDIFT file.
140+
Each entry is a list of string declarations, and a list of any child groups.
141+
:param init_file: java.io.File containing original LDIFT entries
142+
:param group_child_map: a map of group names to child group names
143+
:return: the existing entries list
144+
"""
145+
init_reader = open(init_file.getPath(), 'r')
146+
init_lines = init_reader.readlines()
147+
init_reader.close()
148+
149+
existing_entry = None
150+
existing_entries = []
151+
for init_line in init_lines:
152+
line_text = init_line.strip()
153+
if len(line_text) == 0:
154+
existing_entry = None
155+
else:
156+
if existing_entry is None:
157+
existing_entry = {HASH_EXISTING_LINES: [], HASH_CHILD_GROUPS: []}
158+
existing_entries.append(existing_entry)
159+
existing_entry[HASH_EXISTING_LINES].append({HASH_EXISTING_TEXT: line_text})
160+
161+
match = re.match(CN_REGEX, line_text)
162+
if match:
163+
child_groups = dictionary_utils.get_element(group_child_map, match.group(1))
164+
if child_groups:
165+
existing_entry[HASH_CHILD_GROUPS] = child_groups
166+
167+
return existing_entries
168+
107169
def _build_group_mapping_hash(self, group_mapping_section, name):
108170
"""
109171
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
@@ -457,7 +457,7 @@ WLSDPLY-01840=Encryption failed: Unable to locate SerializedSystemIni
457457
WLSDPLY-01841=Encryption failed: Unable to initialize encryption service
458458

459459
# wlsdeploy/tool/util/default_authenticator_helper.py
460-
WLSDPLY-01900=Append to default authenticator initialization file {0}
460+
WLSDPLY-01900=Updating default authenticator initialization file {0}
461461
WLSDPLY-01901=Failed to encrypt password for user {0}: {1}
462462
WLSDPLY-01902=Unable to add user {0} due to an error: {1}
463463

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
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}}
15-
1624
dn: uid={{{name}}},ou=people,ou=@realm@,dc=@domain@
1725
description: {{{description}}}
1826
objectclass: inetOrgPerson
@@ -30,4 +38,5 @@ wlsMemberOf: cn={{{groupMemberOf}}},ou=groups,ou=@realm@,dc=@domain@
3038
{{#userattr}}
3139
{{{attribute}}}
3240
{{/userattr}}
33-
{{/user}}
41+
42+
{{/user}}

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

-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,3 @@ topology:
6262
- The processing of users, groups, and roles will only take place when using the [Create Domain Tool]({{< relref "/userguide/tools/create.md" >}}).
6363
- WebLogic global roles are only supported with WebLogic Server version 12.2.1 or greater.
6464
- WebLogic global roles are only updated for the WebLogic security XACML role mapping provider (for example, `XACMLRoleMapper`).
65-
- 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" >}}).

documentation/3.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)