- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
add isPerson check to query for AD #11843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -75,23 +75,15 @@ protected LdapUser createUser(final SearchResult result, Long domainId) throws N | |||||
| } | ||||||
|  | ||||||
| private String generateSearchFilter(final String username, Long domainId) { | ||||||
| final StringBuilder userObjectFilter = new StringBuilder(); | ||||||
| userObjectFilter.append("(objectClass="); | ||||||
| userObjectFilter.append(_ldapConfiguration.getUserObject(domainId)); | ||||||
| userObjectFilter.append(")"); | ||||||
| final StringBuilder userObjectFilter = getUserObjectFilter(domainId); | ||||||
|  | ||||||
| final StringBuilder usernameFilter = new StringBuilder(); | ||||||
| usernameFilter.append("("); | ||||||
| usernameFilter.append(_ldapConfiguration.getUsernameAttribute(domainId)); | ||||||
| usernameFilter.append("="); | ||||||
| usernameFilter.append((username == null ? "*" : LdapUtils.escapeLDAPSearchFilter(username))); | ||||||
| usernameFilter.append(")"); | ||||||
| final StringBuilder usernameFilter = getUsernameFilter(username, domainId); | ||||||
|  | ||||||
| String memberOfAttribute = getMemberOfAttribute(domainId); | ||||||
| StringBuilder ldapGroupsFilter = new StringBuilder(); | ||||||
| // this should get the trustmaps for this domain | ||||||
| List<String> ldapGroups = getMappedLdapGroups(domainId); | ||||||
| if (null != ldapGroups && ldapGroups.size() > 0) { | ||||||
| if (!ldapGroups.isEmpty()) { | ||||||
| ldapGroupsFilter.append("(|"); | ||||||
| for (String ldapGroup : ldapGroups) { | ||||||
| ldapGroupsFilter.append(getMemberOfGroupString(ldapGroup, memberOfAttribute)); | ||||||
|  | @@ -104,21 +96,35 @@ private String generateSearchFilter(final String username, Long domainId) { | |||||
| if (null != pricipleGroup) { | ||||||
| principleGroupFilter.append(getMemberOfGroupString(pricipleGroup, memberOfAttribute)); | ||||||
| } | ||||||
| final StringBuilder result = new StringBuilder(); | ||||||
| result.append("(&"); | ||||||
| result.append(userObjectFilter); | ||||||
| result.append(usernameFilter); | ||||||
| result.append(ldapGroupsFilter); | ||||||
| result.append(principleGroupFilter); | ||||||
| result.append(")"); | ||||||
|  | ||||||
| String returnString = result.toString(); | ||||||
| if (logger.isTraceEnabled()) { | ||||||
| logger.trace("constructed ldap query: " + returnString); | ||||||
| } | ||||||
|  | ||||||
| String returnString = "(&" + | ||||||
| userObjectFilter + | ||||||
| usernameFilter + | ||||||
| ldapGroupsFilter + | ||||||
| principleGroupFilter + | ||||||
| ")"; | ||||||
| logger.trace("constructed ldap query: {}", returnString); | ||||||
| return returnString; | ||||||
| } | ||||||
|  | ||||||
| private StringBuilder getUsernameFilter(String username, Long domainId) { | ||||||
| final StringBuilder usernameFilter = new StringBuilder(); | ||||||
| usernameFilter.append("("); | ||||||
| usernameFilter.append(_ldapConfiguration.getUsernameAttribute(domainId)); | ||||||
| usernameFilter.append("="); | ||||||
| usernameFilter.append((username == null ? "*" : LdapUtils.escapeLDAPSearchFilter(username))); | ||||||
| usernameFilter.append(")"); | ||||||
| return usernameFilter; | ||||||
| } | ||||||
|  | ||||||
| StringBuilder getUserObjectFilter(Long domainId) { | ||||||
| final StringBuilder userObjectFilter = new StringBuilder(); | ||||||
| userObjectFilter.append("(objectClass="); | ||||||
| userObjectFilter.append(_ldapConfiguration.getUserObject(domainId)); | ||||||
| userObjectFilter.append(")"); | ||||||
| return userObjectFilter; | ||||||
| } | ||||||
|  | ||||||
| private List<String> getMappedLdapGroups(Long domainId) { | ||||||
| List <String> ldapGroups = new ArrayList<>(); | ||||||
| // first get the trustmaps | ||||||
|  | @@ -134,37 +140,31 @@ private List<String> getMappedLdapGroups(Long domainId) { | |||||
| private String getMemberOfGroupString(String group, String memberOfAttribute) { | ||||||
| final StringBuilder memberOfFilter = new StringBuilder(); | ||||||
| if (null != group) { | ||||||
| if(logger.isDebugEnabled()) { | ||||||
| logger.debug("adding search filter for '" + group + | ||||||
| "', using '" + memberOfAttribute + "'"); | ||||||
| } | ||||||
| memberOfFilter.append("(" + memberOfAttribute + "="); | ||||||
| memberOfFilter.append(group); | ||||||
| memberOfFilter.append(")"); | ||||||
| logger.debug("adding search filter for '{}', using '{}'", group, memberOfAttribute); | ||||||
| memberOfFilter.append("(") | ||||||
| .append(memberOfAttribute) | ||||||
| .append("=") | ||||||
| .append(group) | ||||||
| .append(")"); | ||||||
| } | ||||||
| return memberOfFilter.toString(); | ||||||
| } | ||||||
|  | ||||||
| private String generateGroupSearchFilter(final String groupName, Long domainId) { | ||||||
| final StringBuilder groupObjectFilter = new StringBuilder(); | ||||||
| groupObjectFilter.append("(objectClass="); | ||||||
| groupObjectFilter.append(_ldapConfiguration.getGroupObject(domainId)); | ||||||
| groupObjectFilter.append(")"); | ||||||
|  | ||||||
| final StringBuilder groupNameFilter = new StringBuilder(); | ||||||
| groupNameFilter.append("("); | ||||||
| groupNameFilter.append(_ldapConfiguration.getCommonNameAttribute()); | ||||||
| groupNameFilter.append("="); | ||||||
| groupNameFilter.append((groupName == null ? "*" : LdapUtils.escapeLDAPSearchFilter(groupName))); | ||||||
| groupNameFilter.append(")"); | ||||||
|  | ||||||
| final StringBuilder result = new StringBuilder(); | ||||||
| result.append("(&"); | ||||||
| result.append(groupObjectFilter); | ||||||
| result.append(groupNameFilter); | ||||||
| result.append(")"); | ||||||
|  | ||||||
| return result.toString(); | ||||||
| String groupObjectFilter = "(objectClass=" + | ||||||
| _ldapConfiguration.getGroupObject(domainId) + | ||||||
| ")"; | ||||||
|  | ||||||
| String groupNameFilter = "(" + | ||||||
| _ldapConfiguration.getCommonNameAttribute() + | ||||||
| "=" + | ||||||
| (groupName == null ? "*" : LdapUtils.escapeLDAPSearchFilter(groupName)) + | ||||||
| ")"; | ||||||
|  | ||||||
| return "(&" + | ||||||
| groupObjectFilter + | ||||||
| groupNameFilter + | ||||||
| ")"; | ||||||
| } | ||||||
|  | ||||||
| @Override | ||||||
|  | @@ -186,17 +186,9 @@ public LdapUser getUser(final String username, final String type, final String n | |||||
| basedn = _ldapConfiguration.getBaseDn(domainId); | ||||||
| } | ||||||
|  | ||||||
| final StringBuilder userObjectFilter = new StringBuilder(); | ||||||
| userObjectFilter.append("(objectClass="); | ||||||
| userObjectFilter.append(_ldapConfiguration.getUserObject(domainId)); | ||||||
| userObjectFilter.append(")"); | ||||||
| final StringBuilder userObjectFilter = getUserObjectFilter(domainId); | ||||||
|  | ||||||
| final StringBuilder usernameFilter = new StringBuilder(); | ||||||
| usernameFilter.append("("); | ||||||
| usernameFilter.append(_ldapConfiguration.getUsernameAttribute(domainId)); | ||||||
| usernameFilter.append("="); | ||||||
| usernameFilter.append((username == null ? "*" : LdapUtils.escapeLDAPSearchFilter(username))); | ||||||
| usernameFilter.append(")"); | ||||||
| final StringBuilder usernameFilter = getUsernameFilter(username, domainId); | ||||||
|  | ||||||
| final StringBuilder memberOfFilter = new StringBuilder(); | ||||||
| if ("GROUP".equals(type)) { | ||||||
|  | @@ -205,18 +197,17 @@ public LdapUser getUser(final String username, final String type, final String n | |||||
| memberOfFilter.append(")"); | ||||||
| } | ||||||
|  | ||||||
| final StringBuilder searchQuery = new StringBuilder(); | ||||||
| searchQuery.append("(&"); | ||||||
| searchQuery.append(userObjectFilter); | ||||||
| searchQuery.append(usernameFilter); | ||||||
| searchQuery.append(memberOfFilter); | ||||||
| searchQuery.append(")"); | ||||||
| String searchQuery = "(&" + | ||||||
| userObjectFilter + | ||||||
| usernameFilter + | ||||||
| memberOfFilter + | ||||||
| ")"; | ||||||
|  | ||||||
| return searchUser(basedn, searchQuery.toString(), context, domainId); | ||||||
| return searchUser(basedn, searchQuery, context, domainId); | ||||||
| } | ||||||
|  | ||||||
| protected String getMemberOfAttribute(final Long domainId) { | ||||||
| return _ldapConfiguration.getUserMemberOfAttribute(domainId); | ||||||
| return LdapConfiguration.getUserMemberOfAttribute(domainId); | ||||||
| 
     | ||||||
| return LdapConfiguration.getUserMemberOfAttribute(domainId); | |
| return _ldapConfiguration.getUserMemberOfAttribute(domainId); | 
    
      
    
      Copilot
AI
    
    
    
      Oct 23, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing IOException from the throws clause is a breaking change to the method signature. If any calling code explicitly catches IOException from this method, it will cause compilation errors. Verify that all callers have been updated accordingly, or consider whether this exception should remain for backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be marked with
@Overrideannotation since it overrides the parent class method inOpenLdapUserManagerImpl. Adding the annotation makes the inheritance relationship explicit and allows the compiler to verify the override.