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));
}
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)
}
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);
}
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());
}
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;
}
}
Aggregations