use of org.apache.syncope.common.rest.api.service.UserService in project testcases by coheigea.
the class SyncopeDeployer method deployUserData.
@SuppressWarnings("unchecked")
public void deployUserData() {
WebClient client = WebClient.create(address);
client = client.type("application/xml");
String authorizationHeader = "Basic " + Base64Utility.encode(("admin" + ":" + "password").getBytes());
client.header("Authorization", authorizationHeader);
client.accept("application/xml");
// Create the groups first
client = client.path("groups");
PagedResult<GroupTO> existingGroups = (PagedResult<GroupTO>) client.get(PagedResult.class);
GroupTO bossGroup = findOrCreateGroup("boss", existingGroups, client);
GroupTO employeeGroup = findOrCreateGroup("employee", existingGroups, client);
// Now create the users
client = client.replacePath("users");
PagedResult<UserTO> existingUsers = (PagedResult<UserTO>) client.get(PagedResult.class);
if (!doesUserAlreadyExist("alice", existingUsers.getResult())) {
UserTO user = new UserTO();
user.setUsername("alice");
user.setPassword("security");
user.setRealm("/");
MembershipTO membership = new MembershipTO();
membership.setGroupKey(employeeGroup.getKey());
// membership.setGroupName(employeeGroup.getName());
user.getMemberships().add(membership);
membership = new MembershipTO();
// membership.setGroupName(bossGroup.getName());
membership.setGroupKey(bossGroup.getKey());
user.getMemberships().add(membership);
client.post(user, ProvisioningResult.class);
}
if (!doesUserAlreadyExist("bob", existingUsers.getResult())) {
UserTO user = new UserTO();
user.setUsername("bob");
user.setPassword("security");
user.setRealm("/");
MembershipTO membership = new MembershipTO();
membership.setGroupKey(employeeGroup.getKey());
// membership.setGroupName(employeeGroup.getName());
user.getMemberships().add(membership);
client.post(user, ProvisioningResult.class);
}
client.close();
// Check via the client API that the users were created correctly
SyncopeClientFactoryBean clientFactory = new SyncopeClientFactoryBean().setAddress(address);
SyncopeClient syncopeClient = clientFactory.create("admin", "password");
UserService userService = syncopeClient.getService(UserService.class);
int count = userService.search(new AnyQuery.Builder().build()).getTotalCount();
Assert.assertEquals(2, count);
}
use of org.apache.syncope.common.rest.api.service.UserService in project syncope by apache.
the class UserSelfITCase method read.
@Test
public void read() {
UserService userService2 = clientFactory.create("rossini", ADMIN_PWD).getService(UserService.class);
try {
userService2.read("1417acbe-cbf6-4277-9372-e75e04f97000");
fail("This should not happen");
} catch (ForbiddenException e) {
assertNotNull(e);
}
Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create("rossini", ADMIN_PWD).self();
assertEquals("rossini", self.getRight().getUsername());
}
use of org.apache.syncope.common.rest.api.service.UserService in project syncope by apache.
the class UserRestClient method suspend.
public BulkActionResult suspend(final String etag, final String userKey, final List<StatusBean> statuses) {
StatusPatch statusPatch = StatusUtils.buildStatusPatch(statuses, false);
statusPatch.setKey(userKey);
statusPatch.setType(StatusPatchType.SUSPEND);
BulkActionResult result;
synchronized (this) {
result = new BulkActionResult();
Map<String, BulkActionResult.Status> res = result.getResults();
UserService service = getService(etag, UserService.class);
@SuppressWarnings("unchecked") ProvisioningResult<UserTO> provisions = (ProvisioningResult<UserTO>) service.status(statusPatch).readEntity(ProvisioningResult.class);
if (statusPatch.isOnSyncope()) {
res.put(StringUtils.capitalize(Constants.SYNCOPE), "suspended".equalsIgnoreCase(provisions.getEntity().getStatus()) ? BulkActionResult.Status.SUCCESS : BulkActionResult.Status.FAILURE);
}
for (PropagationStatus status : provisions.getPropagationStatuses()) {
res.put(status.getResource(), BulkActionResult.Status.valueOf(status.getStatus().name()));
}
resetClient(UserService.class);
}
return result;
}
use of org.apache.syncope.common.rest.api.service.UserService in project syncope by apache.
the class RESTITCase method ifMatch.
@Test
public void ifMatch() {
UserTO userTO = userService.create(UserITCase.getUniqueSampleTO("ifmatch@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertNotNull(userTO.getKey());
EntityTag etag = adminClient.getLatestEntityTag(userService);
assertNotNull(etag);
assertTrue(StringUtils.isNotBlank(etag.getValue()));
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "XX").build());
userTO = userService.update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertTrue(userTO.getUsername().endsWith("XX"));
EntityTag etag1 = adminClient.getLatestEntityTag(userService);
assertFalse(etag.getValue().equals(etag1.getValue()));
UserService ifMatchService = adminClient.ifMatch(adminClient.getService(UserService.class), etag);
userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "YY").build());
try {
ifMatchService.update(userPatch);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.ConcurrentModification, e.getType());
}
userTO = userService.read(userTO.getKey());
assertTrue(userTO.getUsername().endsWith("XX"));
}
use of org.apache.syncope.common.rest.api.service.UserService in project syncope by apache.
the class AuthenticationITCase method userSearch.
@Test
public void userSearch() {
UserTO userTO = UserITCase.getUniqueSampleTO("testusersearch@test.org");
userTO.getRoles().add("User reviewer");
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
// 1. user assigned to role 1, with search entitlement on realms /odd and /even: won't find anything with
// root realm
UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").getService(UserService.class);
PagedResult<UserTO> matchingUsers = userService2.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("key").query()).build());
assertNotNull(matchingUsers);
assertFalse(matchingUsers.getResult().isEmpty());
Set<String> matchingUserKeys = matchingUsers.getResult().stream().map(user -> user.getKey()).collect(Collectors.toSet());
assertTrue(matchingUserKeys.contains("1417acbe-cbf6-4277-9372-e75e04f97000"));
assertFalse(matchingUserKeys.contains("74cd8ece-715a-44a4-a736-e17b46c4e7e6"));
assertFalse(matchingUserKeys.contains("823074dc-d280-436d-a7dd-07399fae48ec"));
// 2. user assigned to role 4, with search entitlement on realm /even/two
UserService userService3 = clientFactory.create("puccini", ADMIN_PWD).getService(UserService.class);
matchingUsers = userService3.search(new AnyQuery.Builder().realm("/even/two").fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("loginDate").query()).build());
assertNotNull(matchingUsers);
assertTrue(matchingUsers.getResult().stream().allMatch(matching -> "/even/two".equals(matching.getRealm())));
}
Aggregations