How do I search for a user by attribute in my Authenticator

I have a client that wants to login specific users if their IP address is in a given name. Ie: If the user’s IP address is 10.0.0.1 then log them in as user Bob, no forms or other steps needed.

My thought was to store the user IP address in an IP attribute of the user. I have started building an Authenicator and I can get the incoming IP address, but I can’t seem to figure out the correct syntax to search the users attributes to find matching IP addresses. Then I still need to figure out how to return the user that has been authenticated.

Any help here would be greatly appreciated.

For any one looking I solved this with the following:

        List<UserModel> users = session
            .users()
            .searchForUserByUserAttributeStream(realm, "ip-login", "true")
            .filter( user -> {
                String ip = user.getFirstAttribute("ip");
                if (ip.contains(remoteIPAddressSearch)) return true;
                if (ip.contains(remoteIPBlockSearch)) return true;
                logger.infof("IP does not match %s", ip);
                return false;
            })
            .collect(Collectors.toList());
        if (users.size() > 0) {
            logger.infof("USERS %d, %s", users.size(), users.get(0).getFirstAttribute("ip"));
            context.getAuthenticationSession().setAuthenticatedUser(users.get(0));
            context.success();
        } else {
            logger.infof("NO Matching IP addresses");
        }

However, this didn’t solve my issue as the client often has LONG lists of IP addresses that don’t fit in the attribute column. Also its not very efficient, as we are first getting users that can login with IP and then checking the IP.