use of org.apache.syncope.ext.scimv2.api.data.Member in project syncope by apache.
the class SCIMITCase method createGroup.
@Test
public void createGroup() {
assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
String displayName = UUID.randomUUID().toString();
SCIMGroup group = new SCIMGroup(null, null, displayName);
group.getMembers().add(new Member("1417acbe-cbf6-4277-9372-e75e04f97000", null, null));
assertNull(group.getId());
assertEquals(displayName, group.getDisplayName());
Response response = webClient().path("Groups").post(group);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
group = response.readEntity(SCIMGroup.class);
assertNotNull(group.getId());
assertTrue(response.getLocation().toASCIIString().endsWith(group.getId()));
assertEquals(1, group.getMembers().size());
assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", group.getMembers().get(0).getValue());
response = webClient().path("Users").path("1417acbe-cbf6-4277-9372-e75e04f97000").get();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
SCIMUser user = response.readEntity(SCIMUser.class);
assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", user.getId());
response = webClient().path("Groups").post(group);
assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());
SCIMError error = response.readEntity(SCIMError.class);
assertEquals(Response.Status.CONFLICT.getStatusCode(), error.getStatus());
assertEquals(ErrorType.uniqueness, error.getScimType());
}
use of org.apache.syncope.ext.scimv2.api.data.Member in project syncope by apache.
the class SCIMITCase method replaceGroup.
@Test
public void replaceGroup() {
assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
SCIMGroup group = new SCIMGroup(null, null, UUID.randomUUID().toString());
group.getMembers().add(new Member("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee", null, null));
Response response = webClient().path("Groups").post(group);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
group = response.readEntity(SCIMGroup.class);
assertNotNull(group.getId());
assertEquals(1, group.getMembers().size());
assertEquals("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee", group.getMembers().get(0).getValue());
group.setDisplayName("other" + group.getId());
group.getMembers().add(new Member("c9b2dec2-00a7-4855-97c0-d854842b4b24", null, null));
response = webClient().path("Groups").path(group.getId()).put(group);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
group = response.readEntity(SCIMGroup.class);
assertTrue(group.getDisplayName().startsWith("other"));
assertEquals(2, group.getMembers().size());
group.getMembers().clear();
group.getMembers().add(new Member("c9b2dec2-00a7-4855-97c0-d854842b4b24", null, null));
response = webClient().path("Groups").path(group.getId()).put(group);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
group = response.readEntity(SCIMGroup.class);
assertEquals(1, group.getMembers().size());
assertEquals("c9b2dec2-00a7-4855-97c0-d854842b4b24", group.getMembers().get(0).getValue());
}
use of org.apache.syncope.ext.scimv2.api.data.Member in project syncope by apache.
the class GroupServiceImpl method create.
@Override
public Response create(final SCIMGroup group) {
// first create group, no members assigned
ProvisioningResult<GroupTO> result = groupLogic().create(binder().toGroupTO(group), false);
// then assign members
for (Member member : group.getMembers()) {
UserPatch patch = new UserPatch();
patch.setKey(member.getValue());
patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(result.getEntity().getKey()).build());
try {
userLogic().update(patch, false);
} catch (Exception e) {
LOG.error("While setting membership of {} to {}", result.getEntity().getKey(), member.getValue(), e);
}
}
return createResponse(result.getEntity().getKey(), binder().toSCIMGroup(result.getEntity(), uriInfo.getAbsolutePathBuilder().path(result.getEntity().getKey()).build().toASCIIString(), Collections.<String>emptyList(), Collections.<String>emptyList()));
}
use of org.apache.syncope.ext.scimv2.api.data.Member in project syncope by apache.
the class GroupServiceImpl method replace.
@Override
public Response replace(final String id, final SCIMGroup group) {
if (!id.equals(group.getId())) {
throw new BadRequestException(ErrorType.invalidPath, "Expected " + id + ", found " + group.getId());
}
ResponseBuilder builder = checkETag(Resource.Group, id);
if (builder != null) {
return builder.build();
}
// save current group members
Set<String> beforeMembers = new HashSet<>();
MembershipCond membCond = new MembershipCond();
membCond.setGroup(id);
SearchCond searchCond = SearchCond.getLeafCond(membCond);
int count = userLogic().search(searchCond, 1, 1, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getLeft();
for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
beforeMembers.addAll(userLogic().search(searchCond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getRight().stream().map(EntityTO::getKey).collect(Collectors.toSet()));
}
// update group, don't change members
ProvisioningResult<GroupTO> result = groupLogic().update(AnyOperations.diff(binder().toGroupTO(group), groupLogic().read(id), false), false);
// assign new members
Set<String> afterMembers = new HashSet<>();
group.getMembers().forEach(member -> {
afterMembers.add(member.getValue());
if (!beforeMembers.contains(member.getValue())) {
UserPatch patch = new UserPatch();
patch.setKey(member.getValue());
patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(result.getEntity().getKey()).build());
try {
userLogic().update(patch, false);
} catch (Exception e) {
LOG.error("While setting membership of {} to {}", result.getEntity().getKey(), member.getValue(), e);
}
}
});
// remove unconfirmed members
beforeMembers.stream().filter(member -> !afterMembers.contains(member)).forEach(user -> {
UserPatch patch = new UserPatch();
patch.setKey(user);
patch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.DELETE).group(result.getEntity().getKey()).build());
try {
userLogic().update(patch, false);
} catch (Exception e) {
LOG.error("While removing membership of {} from {}", result.getEntity().getKey(), user, e);
}
});
return updateResponse(result.getEntity().getKey(), binder().toSCIMGroup(result.getEntity(), uriInfo.getAbsolutePathBuilder().path(result.getEntity().getKey()).build().toASCIIString(), Collections.<String>emptyList(), Collections.<String>emptyList()));
}
use of org.apache.syncope.ext.scimv2.api.data.Member in project syncope by apache.
the class SCIMDataBinder method toSCIMGroup.
public SCIMGroup toSCIMGroup(final GroupTO groupTO, final String location, final List<String> attributes, final List<String> excludedAttributes) {
SCIMGroup group = new SCIMGroup(groupTO.getKey(), new Meta(Resource.Group, groupTO.getCreationDate(), groupTO.getLastChangeDate() == null ? groupTO.getCreationDate() : groupTO.getLastChangeDate(), groupTO.getETagValue(), location), output(attributes, excludedAttributes, "displayName", groupTO.getName()));
MembershipCond membCond = new MembershipCond();
membCond.setGroup(groupTO.getKey());
SearchCond searchCond = SearchCond.getLeafCond(membCond);
if (output(attributes, excludedAttributes, "members")) {
int count = userLogic.search(searchCond, 1, 1, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getLeft();
for (int page = 1; page <= (count / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
List<UserTO> users = userLogic.search(searchCond, page, AnyDAO.DEFAULT_PAGE_SIZE, Collections.<OrderByClause>emptyList(), SyncopeConstants.ROOT_REALM, false).getRight();
users.forEach(userTO -> {
group.getMembers().add(new Member(userTO.getKey(), StringUtils.substringBefore(location, "/Groups") + "/Users/" + userTO.getKey(), userTO.getUsername()));
});
}
}
return group;
}
Aggregations