Skip to content

Commit

Permalink
add method for bulk updating users to add required action
Browse files Browse the repository at this point in the history
  • Loading branch information
dasniko committed Dec 3, 2024
1 parent 634df8e commit 7818fdd
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dasniko.keycloak.resource.admin;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
Expand Down Expand Up @@ -42,4 +44,23 @@ public Response getListOfUsers() {
return Response.ok(userList).build();
}

@PUT
@Path("users/required-action")
@Consumes(MediaType.APPLICATION_JSON)
public Response buldAddRequiredAction(Map<String, String> payload) {
// do the authorization with the existing admin permissions
final UserPermissionEvaluator userPermissionEvaluator = auth.users();
userPermissionEvaluator.requireManage();

// search users and iterate over the result to add the required action
if (payload.containsKey("action")) {
session.users()
.searchForUserStream(realm, Map.of(UserModel.SEARCH, payload.getOrDefault("search", "*")))
.filter(userModel -> userModel.getServiceAccountClientLink() == null)
.forEach(user -> user.addRequiredAction(payload.get("action")));
}

return Response.noContent().build();
}

}

0 comments on commit 7818fdd

Please sign in to comment.