@@ -512,6 +512,7 @@ List<String> lookupGroup(SearchResult result, DirContext c,
512
512
List <String > doGetGroups (String user , int goUpHierarchy )
513
513
throws NamingException {
514
514
DirContext c = getDirContext ();
515
+ List <String > groups = new ArrayList <>();
515
516
516
517
// Search for the user. We'll only ever need to look at the first result
517
518
NamingEnumeration <SearchResult > results = c .search (userbaseDN ,
@@ -520,11 +521,10 @@ List<String> doGetGroups(String user, int goUpHierarchy)
520
521
if (!results .hasMoreElements ()) {
521
522
LOG .debug ("doGetGroups({}) returned no groups because the " +
522
523
"user is not found." , user );
523
- return new ArrayList <>() ;
524
+ return groups ;
524
525
}
525
526
SearchResult result = results .nextElement ();
526
527
527
- List <String > groups = null ;
528
528
if (useOneQuery ) {
529
529
try {
530
530
/**
@@ -538,7 +538,6 @@ List<String> doGetGroups(String user, int goUpHierarchy)
538
538
memberOfAttr + "' attribute." +
539
539
"Returned user object: " + result .toString ());
540
540
}
541
- groups = new ArrayList <>();
542
541
NamingEnumeration groupEnumeration = groupDNAttr .getAll ();
543
542
while (groupEnumeration .hasMore ()) {
544
543
String groupDN = groupEnumeration .next ().toString ();
@@ -547,14 +546,12 @@ List<String> doGetGroups(String user, int goUpHierarchy)
547
546
} catch (NamingException e ) {
548
547
// If the first lookup failed, fall back to the typical scenario.
549
548
// In order to force the fallback, we need to reset groups collection.
550
- if (groups != null ) {
551
- groups .clear ();
552
- }
549
+ groups .clear ();
553
550
LOG .info ("Failed to get groups from the first lookup. Initiating " +
554
551
"the second LDAP query using the user's DN." , e );
555
552
}
556
553
}
557
- if (groups == null || groups .isEmpty () || goUpHierarchy > 0 ) {
554
+ if (groups .isEmpty () || goUpHierarchy > 0 ) {
558
555
groups = lookupGroup (result , c , goUpHierarchy );
559
556
}
560
557
LOG .debug ("doGetGroups({}) returned {}" , user , groups );
0 commit comments