Search in sources :

Example 26 with Meta

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

the class AverageUserTest method updateWithObject1.

@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject1() throws Exception {
    UserResource clone = getDeepCloneUsr(user);
    clone.setPreferredLanguage("en_US");
    clone.getPhoneNumbers().remove(0);
    // Means no change
    clone.setAddresses(null);
    // Means role will have to disappear
    clone.setRoles(new ArrayList<>());
    Group group = new Group();
    group.setValue("Dummy ID");
    // will be ignored: group membership changes MUST be applied via /Groups endpoint
    clone.setGroups(Collections.singletonList(group));
    logger.debug("Updating user {}", clone.getUserName());
    Response response = client.updateUser(clone, clone.getId(), null, "meta");
    assertEquals(response.getStatus(), OK.getStatusCode());
    user = response.readEntity(usrClass);
    assertNotNull(user.getPreferredLanguage());
    assertEquals(user.getPreferredLanguage(), clone.getPreferredLanguage());
    assertEquals(user.getPhoneNumbers().size(), clone.getPhoneNumbers().size());
    assertFalse(user.getAddresses().isEmpty());
    assertNull(user.getRoles());
    assertNull(user.getGroups());
    logger.debug("Updated user {}", user.getName().getGivenName());
    // Double check update did take update in the original source (eg. LDAP):
    String json = response.readEntity(String.class);
    response = client.getUserById(clone.getId(), null, "meta");
    // both json contents should be the same since meta attribute was removed and serialization involves UserResource class
    assertEquals(json, response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) Group(io.jans.scim.model.scim2.user.Group) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 27 with Meta

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

the class FidoU2fDeviceTest method updateWithObject.

@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject() throws Exception {
    logger.debug("Updating device to original attributes");
    Response response = client.updateDevice(device, device.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    FidoDeviceResource updated = response.readEntity(fidoClass);
    // Naively compare (property-to-property) the original and new object. It's feasible since all of them are strings
    for (String path : IntrospectUtil.allAttrs.get(fidoClass)) {
        String val = BeanUtils.getProperty(device, path);
        // Exclude metas since they diverge and skip if original attribute was null (when passing null for an update, server ignores)
        if (!path.startsWith("meta") && val != null)
            assertEquals(BeanUtils.getProperty(updated, path), val);
    }
    // Update an immutable attribute (originally null). Per spec, uninitialized immutable attributes can be set
    assertNull(updated.getDeviceData());
    updated.setDeviceData("Dummy device data");
    response = client.updateDevice(updated, updated.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    updated = response.readEntity(fidoClass);
    assertNotNull(updated.getDeviceData());
// NOTE: if you don't see device data attribute for this device in LDAP is because the attribute is marked as being
// ignored upon update (see io.jans.scim.model.fido.GluuCustomFidoDevice)
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 28 with Meta

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

the class BaseScimWebService method assignMetaInformation.

protected void assignMetaInformation(BaseScimResource resource) {
    // Generate some meta information (this replaces the info client passed in the request)
    String val = DateUtil.millisToISOString(System.currentTimeMillis());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(resource.getClass()));
    meta.setCreated(val);
    meta.setLastModified(val);
    // For version attritute: Service provider support for this attribute is optional and subject to the service provider's support for versioning
    // For location attribute: this will be set after current user creation in LDAP
    resource.setMeta(meta);
}
Also used : Meta(io.jans.scim.model.scim2.Meta)

Example 29 with Meta

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

the class FidoDeviceWebService method transferAttributesToFidoResource.

private void transferAttributesToFidoResource(GluuCustomFidoDevice fidoDevice, FidoDeviceResource res, String url, String userId) {
    res.setId(fidoDevice.getId());
    Meta meta = new Meta();
    meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
    String strDate = fidoDevice.getCreationDate();
    meta.setCreated(ldapBackend ? DateUtil.generalizedToISOStringDate(strDate) : (strDate + "Z"));
    meta.setLastModified(fidoDevice.getMetaLastModified());
    meta.setLocation(fidoDevice.getMetaLocation());
    if (meta.getLocation() == null)
        meta.setLocation(url + "/" + fidoDevice.getId());
    res.setMeta(meta);
    // Set values in order of appearance in FidoDeviceResource class
    res.setUserId(userId);
    res.setCreationDate(meta.getCreated());
    res.setApplication(fidoDevice.getApplication());
    res.setCounter(fidoDevice.getCounter());
    res.setDeviceData(fidoDevice.getDeviceData());
    res.setDeviceHashCode(fidoDevice.getDeviceHashCode());
    res.setDeviceKeyHandle(fidoDevice.getDeviceKeyHandle());
    res.setDeviceRegistrationConf(fidoDevice.getDeviceRegistrationConf());
    strDate = fidoDevice.getLastAccessTime();
    if (strDate != null) {
        res.setLastAccessTime(ldapBackend ? DateUtil.generalizedToISOStringDate(strDate) : (strDate + "Z"));
    }
    res.setStatus(fidoDevice.getStatus());
    res.setDisplayName(fidoDevice.getDisplayName());
    res.setDescription(fidoDevice.getDescription());
    res.setNickname(fidoDevice.getNickname());
}
Also used : Meta(io.jans.scim.model.scim2.Meta)

Example 30 with Meta

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

the class SchemaWebService method getSchemaInstance.

private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz, String urn) throws Exception {
    if (ScimResourceUtil.getDefaultSchemaUrn(clazz).equals(urn))
        // Process core attributes
        return getSchemaInstance(clazz);
    else {
        // process extension attributes
        SchemaResource resource = null;
        Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
        // Find the appropriate extension
        List<Extension> extensions = extService.getResourceExtensions(clazz);
        for (Extension extension : extensions) {
            if (extension.getUrn().equals(urn)) {
                Meta meta = new Meta();
                meta.setResourceType(ScimResourceUtil.getType(schemaCls));
                meta.setLocation(endpointUrl + "/" + urn);
                resource = new SchemaResource();
                resource.setId(urn);
                resource.setName(extension.getName());
                resource.setDescription(extension.getDescription());
                resource.setMeta(meta);
                List<SchemaAttribute> attribs = new ArrayList<>();
                for (ExtensionField field : extension.getFields().values()) {
                    SchemaAttribute schAttr = new SchemaAttribute();
                    schAttr.setName(field.getName());
                    schAttr.setMultiValued(field.isMultiValued());
                    schAttr.setDescription(field.getDescription());
                    schAttr.setRequired(false);
                    schAttr.setCanonicalValues(null);
                    schAttr.setCaseExact(false);
                    schAttr.setMutability(AttributeDefinition.Mutability.READ_WRITE.getName());
                    schAttr.setReturned(AttributeDefinition.Returned.DEFAULT.getName());
                    schAttr.setUniqueness(AttributeDefinition.Uniqueness.NONE.getName());
                    schAttr.setReferenceTypes(null);
                    AttributeDefinition.Type type = field.getAttributeDefinitionType();
                    schAttr.setType(type == null ? null : type.getName());
                    schAttr.setSubAttributes(null);
                    attribs.add(schAttr);
                }
                resource.setAttributes(attribs);
                break;
            }
        }
        return resource;
    }
}
Also used : Extension(io.jans.scim.model.scim2.extensions.Extension) Meta(io.jans.scim.model.scim2.Meta) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) ArrayList(java.util.ArrayList) AttributeDefinition(io.jans.scim.model.scim2.AttributeDefinition) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource)

Aggregations

Meta (org.gluu.oxtrust.model.scim2.Meta)20 ArrayList (java.util.ArrayList)9 Meta (io.jans.scim.model.scim2.Meta)8 DefaultValue (javax.ws.rs.DefaultValue)7 GET (javax.ws.rs.GET)7 HeaderParam (javax.ws.rs.HeaderParam)7 Produces (javax.ws.rs.Produces)7 URI (java.net.URI)5 Date (java.util.Date)4 Path (javax.ws.rs.Path)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ResourceType (org.gluu.oxtrust.model.scim2.provider.ResourceType)4 UserResource (io.jans.scim.model.scim2.user.UserResource)3 IOException (java.io.IOException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashSet (java.util.HashSet)3 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)3 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)3 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)3 GluuGroup (org.gluu.oxtrust.model.GluuGroup)3