Skip to content

Commit

Permalink
Fix permission attributes - no error should occur in case they are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzheboka committed Sep 4, 2024
1 parent 08c323f commit b85cde6
Showing 1 changed file with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,9 @@ public List<AccessIdRepresentationModel> searchGroupsByName(final String name)
if (!CN.equals(getGroupNameAttribute())) {
orFilter.or(new WhitespaceWildcardsFilter(CN, name));
}
final AndFilter andFilter2 = new AndFilter();
andFilter2.and(new NotPresentFilter(getUserPermissionsAttribute()));

andFilter.and(orFilter);
andFilter2.and(andFilter);
final AndFilter andFilter2 = getPermissionsNotPresentAndFilter(andFilter);

LOGGER.debug("Using filter '{}' for LDAP query.", andFilter);

Expand Down Expand Up @@ -261,6 +260,9 @@ public Map<String, List<String>> searchAccessIdForGroupsAndPermissionsByDn(List<

public List<AccessIdRepresentationModel> searchPermissionsByName(final String name)
throws InvalidArgumentException {
if (permissionsAreEmpty()) {
return Collections.emptyList();
}
isInitOrFail();
testMinSearchForLength(name);

Expand Down Expand Up @@ -323,10 +325,8 @@ public List<AccessIdRepresentationModel> searchGroupsAccessIdIsMemberOf(final St
orFilter.or(new EqualsFilter(getGroupsOfUserName(), accessId));
}
orFilter.or(new EqualsFilter(getGroupsOfUserName(), dn));
final AndFilter andFilter2 = new AndFilter();
andFilter2.and(new NotPresentFilter(getUserPermissionsAttribute()));
andFilter.and(orFilter);
andFilter2.and(andFilter);
final AndFilter andFilter2 = getPermissionsNotPresentAndFilter(andFilter);

String[] userAttributesToReturn = {getUserIdAttribute(), getGroupNameAttribute()};
if (LOGGER.isDebugEnabled()) {
Expand All @@ -346,6 +346,9 @@ public List<AccessIdRepresentationModel> searchGroupsAccessIdIsMemberOf(final St

public List<AccessIdRepresentationModel> searchPermissionsAccessIdHas(final String accessId)
throws InvalidArgumentException, InvalidNameException {
if (permissionsAreEmpty()) {
return Collections.emptyList();
}
isInitOrFail();
testMinSearchForLength(accessId);

Expand Down Expand Up @@ -449,6 +452,9 @@ private List<String> searchDnForUserAccessId(String accessId) {
}

private List<String> searchDnForPermissionAccessId(String accessId) {
if (permissionsAreEmpty()) {
return Collections.emptyList();
}
final AndFilter andFilter = new AndFilter();
andFilter.and(
new EqualsFilter(getPermissionSearchFilterName(), getPermissionSearchFilterValue()));
Expand Down Expand Up @@ -889,6 +895,22 @@ private Set<String> getPermissionIdsFromContext(final DirContextOperations conte
return permissions;
}

private boolean permissionsAreEmpty() {
return getUserPermissionsAttribute().isEmpty() || getPermissionSearchFilterName().isEmpty();
}

private AndFilter getPermissionsNotPresentAndFilter(AndFilter andFilter) {
final AndFilter andFilter2;
if (!getUserPermissionsAttribute().isEmpty()) {
andFilter2 = new AndFilter();
andFilter2.and(new NotPresentFilter(getUserPermissionsAttribute()));
andFilter2.and(andFilter);
} else {
andFilter2 = andFilter;
}
return andFilter2;
}

/** Context Mapper for user entries. */
class GroupContextMapper extends AbstractContextMapper<AccessIdRepresentationModel> {

Expand Down Expand Up @@ -967,7 +989,8 @@ public AccessIdRepresentationModel doMapFromContext(final DirContextOperations c
String firstName = context.getStringAttribute(getUserFirstnameAttribute());
String lastName = context.getStringAttribute(getUserLastnameAttribute());
accessId.setName(String.format("%s, %s", lastName, firstName));
} else if (context.getStringAttribute(getUserPermissionsAttribute()) == null) {
} else if (getUserPermissionsAttribute().isEmpty()
|| context.getStringAttribute(getUserPermissionsAttribute()) == null) {
if (useDnForGroups()) {
accessId.setAccessId(getDnFromContext(context)); // fully qualified dn
} else {
Expand Down

0 comments on commit b85cde6

Please sign in to comment.