Captain-P-Goldfish / SCIM-SDK

a scim implementation as described in RFC7643 and RFC7644
https://github.com/Captain-P-Goldfish/SCIM/wiki
BSD 3-Clause "New" or "Revised" License
122 stars 38 forks source link

Patch Request for Group does not remove Member #54

Closed csbrogi closed 4 years ago

csbrogi commented 4 years ago

A PATCH Request on a Group does not remove the member Sample

**PATCH** request Url: https://keycloa/auth/realms/Demo/scim/v2/Groups/e0d1016a-26dc-446f-8dab-2fd29aa4f779
Parameters : {
  "schemas":["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
  "Operations":[
     {"op":"Remove","path":"members[value eq \"fb945029-265c-4c41-9ada-459f013ed126\"]"}
  ]
}

A Fix could be:


private GroupModel groupToModel(KeycloakSession keycloakSession, Group group, GroupModel groupModel)
  {
    RealmModel realmModel = keycloakSession.getContext().getRealm();
    group.getDisplayName().ifPresent(groupModel::setName);
    if (group.getExternalId().isPresent())
    {
      groupModel.setSingleAttribute(AttributeNames.RFC7643.EXTERNAL_ID, group.getExternalId().get());
    }
    List<Member> groupMembers = group.getMembers();
    keycloakSession.users().getGroupMembers(realmModel, groupModel).stream().forEach(modelMember -> {
      boolean found = false;
      for ( Member groupMember : groupMembers )
      {
        if (groupMember.getType().isPresent() && groupMember.getType().get().equalsIgnoreCase("User"))
        {
          if (groupMember.getValue().get().equals(modelMember.getId()))
          {
            found = false;
          }
        }
      }
      if (!found)
      {
        modelMember.leaveGroup(groupModel);
      }
    });
Captain-P-Goldfish commented 4 years ago

fixed