Search in sources :

Example 26 with UserResource

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));
}
Also used : CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) Optional(java.util.Optional) Date(java.util.Date)

Example 27 with UserResource

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());
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 28 with UserResource

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;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Filter(org.gluu.search.filter.Filter) ListViewResponse(org.gluu.persist.model.ListViewResponse) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) ArrayList(java.util.ArrayList) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource)

Example 29 with UserResource

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);
}
Also used : Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.bulk.BulkResponse) FidoDeviceResource(org.gluu.oxtrust.model.scim2.fido.FidoDeviceResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) PatchRequest(org.gluu.oxtrust.model.scim2.patch.PatchRequest) GroupResource(org.gluu.oxtrust.model.scim2.group.GroupResource) Pair(org.xdi.util.Pair)

Example 30 with UserResource

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;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Aggregations

UserResource (io.jans.scim.model.scim2.user.UserResource)49 Response (javax.ws.rs.core.Response)47 Test (org.testng.annotations.Test)37 UserBaseTest (io.jans.scim2.client.UserBaseTest)34 ListResponse (io.jans.scim.model.scim2.ListResponse)21 SearchRequest (io.jans.scim.model.scim2.SearchRequest)14 Parameters (org.testng.annotations.Parameters)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 Path (javax.ws.rs.Path)7 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)6 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)6 SkipTest (io.jans.scim2.listener.SkipTest)6 URI (java.net.URI)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 Status (javax.ws.rs.core.Response.Status)6 BeforeTest (org.testng.annotations.BeforeTest)6 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)5 GroupResource (io.jans.scim.model.scim2.group.GroupResource)5 PatchRequest (io.jans.scim.model.scim2.patch.PatchRequest)5