use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class QueryParamCreateUpdateTest method execAssertions.
private void execAssertions(UserResource user) {
// Verify "ALWAYS" attribs were retrieved
assertNotNull(user.getSchemas());
assertNotNull(user.getId());
// Verify no password was retrieved
assertNull(user.getPassword());
// Verify preferredLanguage is null (not provided in Json originally)
assertNull(user.getPreferredLanguage());
// Verify all others are present
assertNotNull(user.getUserName());
assertNotNull(user.getDisplayName());
assertNotNull(user.getNickName());
assertNotNull(user.getName().getGivenName());
// Verify cust attrs are there
CustomAttributes custAttrs = user.getCustomAttributes(USER_EXT_SCHEMA_ID);
assertNotNull(custAttrs.getValues("scimCustomSecond", Date.class));
assertNotNull(custAttrs.getValue("scimCustomThird", Integer.class));
// Verify e-mails were retrieved
assertNotNull(user.getEmails());
assertTrue(user.getEmails().stream().map(Email::getValue).map(Optional::ofNullable).allMatch(Optional::isPresent));
}
use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.
the class QueryParamCreateUpdateTest method update2.
@Test(dependsOnMethods = "update1")
public void update2() throws Exception {
UserResource cheapClone = getDeepCloneUsr(user);
cheapClone.setEmails(Collections.emptyList());
cheapClone.setAddresses(Collections.emptyList());
cheapClone.setPhoneNumbers(Collections.emptyList());
cheapClone.setIms(Collections.emptyList());
cheapClone.setRoles(Collections.emptyList());
cheapClone.setEntitlements(Collections.emptyList());
cheapClone.setX509Certificates(Collections.emptyList());
String exclude = "urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomFirst, urn:ietf:params:scim:schemas:core:2.0:User:active, " + "urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomSecond, externalId, userName, name, " + "urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomThird, userType, title, profileUrl";
Response response = client.updateUser(cheapClone, cheapClone.getId(), null, exclude);
assertEquals(response.getStatus(), OK.getStatusCode());
user = response.readEntity(usrClass);
assertNotNull(user.getDisplayName());
assertNotNull(user.getNickName());
// Verify excluded are not present
assertNull(user.getCustomAttributes(USER_EXT_SCHEMA_ID));
assertNull(user.getExternalId());
assertNull(user.getUserName());
assertNull(user.getName());
assertNull(user.getProfileUrl());
assertNull(user.getUserType());
assertNull(user.getTitle());
assertNull(user.getActive());
// Verify update took place really
assertNull(user.getEmails());
assertNull(user.getAddresses());
assertNull(user.getPhoneNumbers());
assertNull(user.getIms());
assertNull(user.getRoles());
assertNull(user.getEntitlements());
assertNull(user.getX509Certificates());
}
use of io.jans.scim.model.scim2.user.UserResource in project oxTrust by GluuFederation.
the class Scim2UserService method searchUsers.
public ListViewResponse<BaseScimResource> searchUsers(String filter, String sortBy, SortOrder sortOrder, int startIndex, int count, String url, int maxCount) throws Exception {
Filter ldapFilter = scimFilterParserService.createLdapFilter(filter, "inum=*", UserResource.class);
log.info("Executing search for users using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count);
ListViewResponse<GluuCustomPerson> list = ldapEntryManager.findListViewResponse(personService.getDnForPerson(null), GluuCustomPerson.class, ldapFilter, startIndex, count, maxCount, sortBy, sortOrder, null);
List<BaseScimResource> resources = new ArrayList<BaseScimResource>();
for (GluuCustomPerson person : list.getResult()) {
UserResource scimUsr = new UserResource();
transferAttributesToUserResource(person, scimUsr, url);
resources.add(scimUsr);
}
log.info("Found {} matching entries - returning {}", list.getTotalResults(), list.getResult().size());
ListViewResponse<BaseScimResource> result = new ListViewResponse<BaseScimResource>();
result.setResult(resources);
result.setTotalResults(list.getTotalResults());
return result;
}
use of io.jans.scim.model.scim2.user.UserResource in project oxTrust by GluuFederation.
the class BulkWebService method execute.
private Pair<Response, String> execute(Verb verb, BaseScimWebService ws, String data, String fragment) {
Response response = null;
String idCreated = null;
try {
if (ws == userWS)
switch(verb) {
case PUT:
UserResource user = mapper.readValue(data, UserResource.class);
response = userWS.updateUser(user, fragment, "id", null);
break;
case DELETE:
response = userWS.deleteUser(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = userWS.patchUser(pr, fragment, "id", null);
break;
case POST:
user = mapper.readValue(data, UserResource.class);
response = userWS.createUser(user, "id", null);
if (CREATED.getStatusCode() == response.getStatus()) {
user = mapper.readValue(response.getEntity().toString(), UserResource.class);
idCreated = user.getId();
}
break;
}
else if (ws == groupWS)
switch(verb) {
case PUT:
GroupResource group = mapper.readValue(data, GroupResource.class);
response = groupWS.updateGroup(group, fragment, "id", null);
break;
case DELETE:
response = groupWS.deleteGroup(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = groupWS.patchGroup(pr, fragment, "id", null);
break;
case POST:
group = mapper.readValue(data, GroupResource.class);
response = groupWS.createGroup(group, "id", null);
if (CREATED.getStatusCode() == response.getStatus()) {
group = mapper.readValue(response.getEntity().toString(), GroupResource.class);
idCreated = group.getId();
}
break;
}
else if (ws == fidoDeviceWS)
switch(verb) {
case PUT:
FidoDeviceResource dev = mapper.readValue(data, FidoDeviceResource.class);
response = fidoDeviceWS.updateDevice(dev, fragment, "id", null);
break;
case DELETE:
response = fidoDeviceWS.deleteDevice(fragment);
break;
case PATCH:
PatchRequest pr = mapper.readValue(data, PatchRequest.class);
response = fidoDeviceWS.patchDevice(pr, fragment, "id", null);
break;
case POST:
response = fidoDeviceWS.createDevice();
break;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return new Pair<Response, String>(response, idCreated);
}
use of io.jans.scim.model.scim2.user.UserResource in project oxTrust by GluuFederation.
the class UserWebService method getUserById.
@Path("{id}")
@GET
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Find user by id", notes = "Returns a user by id as path param (https://tools.ietf.org/html/rfc7644#section-3.4.1)", response = UserResource.class)
public Response getUserById(@PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
Response response;
try {
log.debug("Executing web service method. getUserById");
UserResource user = new UserResource();
// person is not null (check associated decorator method)
GluuCustomPerson person = personService.getPersonByInum(id);
scim2UserService.transferAttributesToUserResource(person, user, endpointUrl);
String json = resourceSerializer.serialize(user, attrsList, excludedAttrsList);
response = Response.ok(new URI(user.getMeta().getLocation())).entity(json).build();
} catch (Exception e) {
log.error("Failure at getUserById method", e);
response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
}
return response;
}
Aggregations