Search in sources :

Example 1 with Type

use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.

the class Scim2UserService method transferExtendedAttributesToPerson.

/**
 * Takes all extended attributes found in the SCIM resource and copies them to a
 * ScimCustomPerson This method is called after validations take place (see
 * associated decorator for User Service), so all inputs are OK and can go
 * straight to LDAP with no runtime surprises
 *
 * @param resource
 *            A SCIM resource used as origin of data
 * @param person
 *            a ScimCustomPerson used as destination
 */
private void transferExtendedAttributesToPerson(BaseScimResource resource, ScimCustomPerson person) {
    try {
        // Gets all the extended attributes for this resource
        Map<String, Object> extendedAttrs = resource.getCustomAttributes();
        // Iterates over all extensions this type of resource might have
        for (Extension extension : extService.getResourceExtensions(resource.getClass())) {
            Object val = extendedAttrs.get(extension.getUrn());
            if (val != null) {
                // Obtains the attribute/value(s) pairs in the current extension
                Map<String, Object> attrsMap = IntrospectUtil.strObjMap(val);
                for (String attribute : attrsMap.keySet()) {
                    Object value = attrsMap.get(attribute);
                    if (value == null) {
                        // Attribute was unassigned in this resource: drop it from destination too
                        log.debug("transferExtendedAttributesToPerson. Flushing attribute {}", attribute);
                        person.setAttribute(attribute, (String) null);
                    } else {
                        ExtensionField field = extension.getFields().get(attribute);
                        if (field.isMultiValued()) {
                            person.setCustomAttribute(attribute, extService.getAttributeValues(field, (Collection) value, ldapBackend));
                        } else {
                            person.setCustomAttribute(attribute, extService.getAttributeValue(field, value, ldapBackend));
                        }
                        log.debug("transferExtendedAttributesToPerson. Setting attribute '{}' with values {}", attribute, person.getTypedAttribute(attribute).getDisplayValue());
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Extension(io.jans.scim.model.scim2.extensions.Extension) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) Collection(java.util.Collection) WebApplicationException(javax.ws.rs.WebApplicationException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 2 with Type

use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.

the class Scim2UserService method transferExtendedAttributesToResource.

private void transferExtendedAttributesToResource(ScimCustomPerson person, BaseScimResource resource) {
    log.debug("transferExtendedAttributesToResource of type {}", ScimResourceUtil.getType(resource.getClass()));
    // Gets the list of extensions associated to the resource passed. In practice,
    // this will be at most a singleton list
    List<Extension> extensions = extService.getResourceExtensions(resource.getClass());
    // resource
    for (Extension extension : extensions) {
        Map<String, ExtensionField> fields = extension.getFields();
        // Create empty map to store the values of the extended attributes found for
        // current extension in object person
        Map<String, Object> map = new HashMap<>();
        log.debug("transferExtendedAttributesToResource. Revising attributes of extension '{}'", extension.getUrn());
        // Iterate over every attribute part of this extension
        for (String attr : fields.keySet()) {
            // Gets the values associated to this attribute that were found in LDAP
            String[] values = person.getAttributes(attr);
            if (values != null) {
                log.debug("transferExtendedAttributesToResource. Copying to resource the value(s) for attribute '{}'", attr);
                ExtensionField field = fields.get(attr);
                List<Object> convertedValues = extService.convertValues(field, values, ldapBackend);
                if (convertedValues.size() > 0) {
                    map.put(attr, field.isMultiValued() ? convertedValues : convertedValues.get(0));
                }
            }
        }
        // Stores all extended attributes (with their values) in the resource object
        if (map.size() > 0) {
            resource.addCustomAttributes(extension.getUrn(), map);
        }
    }
    for (String urn : resource.getCustomAttributes().keySet()) {
        resource.getSchemas().add(urn);
    }
}
Also used : Extension(io.jans.scim.model.scim2.extensions.Extension) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) HashMap(java.util.HashMap)

Example 3 with Type

use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.

the class SearchResourcesWebService method getListResponseTree.

/**
 * Returns a JsonNode with the response obtained from sending a POST to a search method given the SearchRequest passed
 * @param index Determines the concrete search method to be executed: (0 - user; 1 - group; 2 - fido device)
 * @param searchRequest
 * @return
 */
private JsonNode getListResponseTree(int index, SearchRequest searchRequest) {
    try {
        log.debug("getListResponseTree. Resource type is: {}", ScimResourceUtil.getType(resourceClasses[index]));
        Response r = null;
        switch(index) {
            case 0:
                r = userWS.searchUsersPost(searchRequest);
                break;
            case 1:
                r = groupWS.searchGroupsPost(searchRequest);
                break;
            case 2:
                r = fidoWS.searchDevicesPost(searchRequest, null);
                break;
            case 3:
                r = fido2WS.searchF2DevicesPost(searchRequest, null);
                break;
        }
        if (r.getStatus() != OK.getStatusCode())
            throw new Exception("Intermediate POST search returned " + r.getStatus());
        // readEntity does not work here since data is not backed by an input stream, so we just get the raw entity
        String jsonStr = r.getEntity().toString();
        return mapper.readTree(jsonStr);
    } catch (Exception e) {
        log.error("Error in getListResponseTree {}", e.getMessage());
        log.error(e.getMessage(), e);
        return null;
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse)

Example 4 with Type

use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.

the class SimpleSearchUserTest method searchNoMatches.

@Test(dependsOnMethods = "create", groups = "search")
public void searchNoMatches() {
    String nowIsoDateTimeString = Instant.ofEpochMilli(System.currentTimeMillis()).toString();
    SearchRequest sr = new SearchRequest();
    sr.setFilter(String.format("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomThird eq 1 and displayName eq \"%s\" " + "and addresses[postalCode ne null or type eq null] and meta.lastModified gt \"%s\"", "test", nowIsoDateTimeString));
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    assertNull(listResponse.getResources());
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 5 with Type

use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.

the class PatchValueFilterUserTest method objectPatch.

@Test(dependsOnMethods = "patch")
public void objectPatch() {
    PatchRequest request = new PatchRequest();
    request.setOperations(new ArrayList<>());
    PatchOperation del = new PatchOperation();
    del.setOperation("remove");
    del.setPath("emails[type sw \"hobby\"]");
    request.getOperations().add(del);
    del = new PatchOperation();
    del.setOperation("remove");
    del.setPath("phoneNumbers[primary pr or value co \" \"].type");
    request.getOperations().add(del);
    del = new PatchOperation();
    del.setOperation("remove");
    del.setPath("addresses[region eq \"somewhere\" and primary ne true].locality");
    request.getOperations().add(del);
    Response response = client.patchUser(request, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    user = response.readEntity(usrClass);
    assertNull(user.getEmails());
    assertTrue(user.getPhoneNumbers().stream().allMatch(ph -> ph.getType() == null));
    // No change in addresses
    assertEquals(user.getAddresses().size(), 1);
    assertNull(user.getAddresses().get(0).getLocality());
}
Also used : Response(javax.ws.rs.core.Response) UserBaseTest(io.jans.scim2.client.UserBaseTest) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) Email(io.jans.scim.model.scim2.user.Email) Address(io.jans.scim.model.scim2.user.Address) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) Parameters(org.testng.annotations.Parameters) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) Collections(java.util.Collections) Status(javax.ws.rs.core.Response.Status) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Aggregations

Extension (io.jans.scim.model.scim2.extensions.Extension)6 ListResponse (io.jans.scim.model.scim2.ListResponse)5 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)5 Response (javax.ws.rs.core.Response)5 UserBaseTest (io.jans.scim2.client.UserBaseTest)4 Test (org.testng.annotations.Test)4 SCIMException (io.jans.scim.model.exception.SCIMException)3 Attribute (io.jans.scim.model.scim2.annotations.Attribute)3 UserResource (io.jans.scim.model.scim2.user.UserResource)3 Parameters (org.testng.annotations.Parameters)3 Type (io.jans.scim.model.scim2.AttributeDefinition.Type)2 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)2 SearchRequest (io.jans.scim.model.scim2.SearchRequest)2 CompValueType (io.jans.scim.service.antlr.scimFilter.enums.CompValueType)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NullType (javax.lang.model.type.NullType)2 Status (javax.ws.rs.core.Response.Status)2 Type (org.gluu.oxtrust.model.scim2.AttributeDefinition.Type)2 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)2