@@ -181,7 +181,7 @@ private String generateGroupSearchFilter(final String groupName, Long domainId)
181181 @ Override
182182 public LdapUser getUser (final String username , final LdapContext context , Long domainId ) throws NamingException , IOException {
183183 List <LdapUser > result = searchUsers (username , context , domainId , false );
184- if (result != null && result .size () == 1 ) {
184+ if (result .size () == 1 ) {
185185 return result .get (0 );
186186 } else {
187187 throw new NamingException ("No user found for username " + username );
@@ -349,20 +349,23 @@ private List<LdapUser> searchUsers(final String username, final LdapContext cont
349349 users .add (createUser (result , domainId ));
350350 }
351351 }
352- Control [] contextControls = context .getResponseControls ();
353- if (contextControls != null ) {
354- for (Control control : contextControls ) {
355- if (control instanceof PagedResultsResponseControl ) {
356- PagedResultsResponseControl prrc = (PagedResultsResponseControl ) control ;
357- cookie = prrc .getCookie ();
358- }
359- }
360- } else {
361- logger .info ("No controls were sent from the ldap server" );
362- }
352+ cookie = extractPagedResultsCookie (context .getResponseControls ());
363353 context .setRequestControls (new Control [] {new PagedResultsControl (pageSize , cookie , Control .CRITICAL )});
364354 } while (cookie != null );
365355
366356 return users ;
367357 }
358+
359+ private byte [] extractPagedResultsCookie (Control [] contextControls ) {
360+ if (contextControls == null ) {
361+ logger .info ("No controls were sent from the ldap server" );
362+ return null ;
363+ }
364+ for (Control control : contextControls ) {
365+ if (control instanceof PagedResultsResponseControl ) {
366+ return ((PagedResultsResponseControl ) control ).getCookie ();
367+ }
368+ }
369+ return null ;
370+ }
368371}
0 commit comments