Let’s say I have 7 users in keycloak, 6 of them are enabled, 1 is disabled.
I now want to filter by their enabled status.
Keycloak documentation is… of limited use. But I do find a search function that accepts an enabled boolean: https://www.keycloak.org/docs-api/11.0/javadocs/org/keycloak/admin/client/resource/UsersResource.html#search-java.lang.String-java.lang.String-java.lang.String-java.lang.String-java.lang.Integer-java.lang.Integer-java.lang.Boolean-java.lang.Boolean-
It’s worth nothing that this enabled boolean does not show up in the API documentations under e.g.
Returns the number of users that match the given criteria.
( https://www.keycloak.org/docs-api/11.0/rest-api/index.html#_users_resource )
But let’s give it a try anyway:
private fun getBriefUserRepresentations(offset: Int, limit: Int, filter: KeycloakUserFilter): List<UserRepresentation> {
return realm.users().search(
filter.userName,
filter.firstName,
filter.lastName,
filter.email,
offset,
limit,
filter.isActive,
true
)
}
If I pass null as filter.isActive it gets ignored, as expected.
If I pass true, however, I get 0 results. I should be getting 6 because 6/7 users are enabled.
If I pass false, I get 8 results, I should be getting 1 because 1/7 users are disabled.
And yes, I did say that I only had 7 users set up… so where does that extra user come from?
Well it’s apparently a user that’s “enabled” and has the username service-account-<realm-name>…
So … what’s the correct way to search for the user enabled status?