class KeyCloakUserManager extends BaseKeyCloakManager implements UserManager,
                                                                        ContextualManager {

    @Override
    public SearchResponse<User> search(SearchRequest request) throws SecurityManagementException {
        final SearchRequest req = getSearchRequest(request);
        // First page must be 1.
        if (req.getPage() <= 0) {
            throw new RuntimeException("First page must be 1.");
        }
        final int page = req.getPage() - 1;
        final int pageSize = req.getPageSize();
        final List<User> users = new ArrayList<User>();
        final int[] numberOfFoundUsers = new int[]{0};
        final boolean[] hasNextPage = new boolean[]{false};
        consumeRealm(realmResource -> {
            final UsersResource usersResource = realmResource.users();
            final List<UserRepresentation> userRepresentations = usersResource.search(req.getSearchPattern(),
                                                                                      page * pageSize,
                                                                                      pageSize + 1);
            numberOfFoundUsers[0] = usersResource.search(req.getSearchPattern(),
                                                         1,
                                                         Integer.MAX_VALUE).size();
            if (userRepresentations != null && !userRepresentations.isEmpty()) {
                int x = 0;
                for (UserRepresentation userRepresentation : userRepresentations) {
                    if (x == req.getPageSize()) {
                        hasNextPage[0] = true;
                    } else {
                        final User user = createUser(userRepresentation);
                        users.add(user);
                        x++;
                    }
                }
            }
        });
        return new SearchResponseImpl<User>(users,
                                            page + 1,
                                            pageSize,
                                            numberOfFoundUsers[0],
                                            hasNextPage[0]);
    }

    public  KeyCloakUserManager();

}