[
https://issues.apache.org/jira/browse/KNOX-3485?focusedWorklogId=1044716&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1044716
]
ASF GitHub Bot logged work on KNOX-3485:
----------------------------------------
Author: ASF GitHub Bot
Created on: 30/Sep/26 03:18
Start Date: 30/Sep/26 03:18
Worklog Time Spent: 10m
Work Description: handavid commented on code in PR #1428:
URL: https://github.com/apache/knox/pull/1428#discussion_r4140493230
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/ldap/interceptor/LDAPRolesLookupInterceptor.java:
##########
@@ -78,21 +80,80 @@ public EntryFilteringCursor search(SearchOperationContext
ctx) throws LdapExcept
throw new LdapException(e);
}
- if (!entries.isEmpty()) {
- for (Entry entry : entries) {
- try {
+ final List<Entry> roleEntries = new ArrayList<>();
+ final List<Entry> resultEntries = new ArrayList<>(entries.size());
+ for (Entry entry : entries) {
+ try {
+ if (LdapUtils.isGroupEntry(entry)) {
+ roleEntries.addAll(translateGroupEntry(entry));
+ } else {
final String username =
LdapUtils.extractUsernameFromEntry(entry, "uid", "cn");
final Set<String> groups = fetchGroups(entry);
final Collection<String> roles =
rolesLookupService.lookupRoles(username, groups);
modifyEntry(entry, roles);
- } catch (Exception e) {
- LOG.ldapRolesLookupFailed("Error while updating entry with
roles lookup results", e);
- throw new LdapException(e);
+ resultEntries.add(entry);
+ }
+ } catch (Exception e) {
+ LOG.ldapRolesLookupFailed(entry.getDn().getName(), e);
+ throw new LdapException(e);
+ }
+ }
+ resultEntries.addAll(deduplicate(roleEntries));
+
+ return new EntryFilteringCursorImpl(new ListCursor<>(resultEntries),
ctx, ctx.getSession().getDirectoryService().getSchemaManager());
+ }
+
+ private Collection<? extends Entry> deduplicate(List<Entry> roleEntries)
throws LdapException {
+ Map<Dn, Entry> dedup = new HashMap<>();
+ for (Entry entry : roleEntries) {
+ Dn dn = entry.getDn();
+ if (!dedup.containsKey(dn)) {
+ dedup.put(dn, entry);
+ } else {
+ combineGroupEntry(dedup.get(dn), entry);
+ }
+ }
+ return dedup.values();
+ }
+
+ private void combineGroupEntry(Entry entry1, Entry entry2) throws
LdapException {
Review Comment:
updated to create a blank entry instead of cloning. then both members and
uniqueMembers are added as members of the new entry.
##########
gateway-server/src/main/java/org/apache/knox/gateway/services/ldap/backend/FilterMappingVisitor.java:
##########
@@ -68,6 +74,17 @@ private Object handleLeafNode(LeafNode leafNode) {
leafNode.setAttributeType(schemaManager.getAttributeType(userIdentifierAttribute));
}
+ // Map the dn-valued attributes from the proxy base dn to remote base
dn
+ if
(DN_VALUED_ATTRIBUTES.contains(currentAttribute.toLowerCase(Locale.ROOT))) {
Review Comment:
fixed
Issue Time Tracking
-------------------
Worklog Id: (was: 1044716)
Time Spent: 40m (was: 0.5h)
> LDAP Proxy should apply role mapping to Group entries
> -----------------------------------------------------
>
> Key: KNOX-3485
> URL: https://issues.apache.org/jira/browse/KNOX-3485
> Project: Apache Knox
> Issue Type: Improvement
> Components: Server
> Affects Versions: 3.1.0
> Reporter: David Han
> Assignee: David Han
> Priority: Major
> Fix For: 3.1.0
>
> Time Spent: 40m
> Remaining Estimate: 0h
>
> The LDAPRolesLookupInterceptor only transforms the memberOf attribute in user
> entries. This interceptor should also replace group entries with their
> corresponding mapped role entries.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)