LdapRoleCheckingRequest extends HttpServletRequestWrapper { List<String> getRoles() throws LDAPException { final SearchRequest searchRequest = new SearchRequest( roleBaseDN, ONE, "(uniqueMember=" + userDN + ")", CN); final SearchResult searchResult = ldapInterface.search(searchRequest); return searchResult.getSearchEntries() .stream() .flatMap(entry -> stream(entry.getAttributeValues("CN"))) .collect(toList()); } LdapRoleCheckingRequest(final HttpServletRequest request,
                                   final LDAPInterface ldapInterface,
                                   final String userDN,
                                   final LdapProperties ldapProperties); @Override boolean isUserInRole(String role);  }
@Test public void shouldReturnUserRoles() throws LDAPException { final HttpServletRequest mockRequest = mock(HttpServletRequest.class); final LDAPInterface ldap = someLdapInterfaceReturning("foo"); final LdapRoleCheckingRequest request = new LdapRoleCheckingRequest(mockRequest, ldap, "uid=test", someLdapProperties()); assertThat(request.getRoles()).contains("foo"); }