use of org.gluu.oxtrust.model.scim2.user.Name in project oxTrust by GluuFederation.
the class IntrospectUtil method traverseClassForNames.
private static void traverseClassForNames(Class clazz, String prefix, List<Field> extraFields, boolean prune) throws Exception {
List<Field> fields = new ArrayList<Field>();
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
fields.addAll(extraFields);
for (Field f : fields) {
Attribute attrAnnot = f.getAnnotation(Attribute.class);
if (attrAnnot != null) {
String name = f.getName();
if (prefix.length() > 0)
name = prefix + "." + name;
switch(attrAnnot.returned()) {
case ALWAYS:
alwaysAttrsNames.add(name);
break;
case DEFAULT:
defaultAttrsNames.add(name);
break;
case NEVER:
neverAttrsNames.add(name);
break;
case REQUEST:
requestAttrsNames.add(name);
break;
}
if (attrAnnot.isRequired())
requiredAttrsNames.add(name);
if (attrAnnot.canonicalValues().length > 0)
canonicalizedAttrsNames.add(name);
Validator vAnnot = f.getAnnotation(Validator.class);
if (vAnnot != null)
validableAttrsNames.add(name);
if (!prune && attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX)) {
// Use <T> parameter of Collection if present
Class cls = attrAnnot.multiValueClass();
if (cls.equals(NullType.class))
cls = f.getType();
if (// Prevent infinite loop
clazz.equals(cls))
prune = true;
traverseClassForNames(cls.equals(NullType.class) ? f.getType() : cls, name, new ArrayList<Field>(), prune);
}
}
}
}
use of org.gluu.oxtrust.model.scim2.user.Name in project oxTrust by GluuFederation.
the class Scim2UserService method transferAttributesToUserResource.
public void transferAttributesToUserResource(GluuCustomPerson person, UserResource res, String url) {
log.debug("transferAttributesToUserResource");
res.setId(person.getInum());
res.setExternalId(person.getAttribute("oxTrustExternalId"));
Meta meta = new Meta();
meta.setResourceType(ScimResourceUtil.getType(res.getClass()));
meta.setCreated(person.getAttribute("oxTrustMetaCreated"));
if (meta.getCreated() == null) {
Date tmpDate = person.getCreationDate();
meta.setCreated(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
}
meta.setLastModified(person.getAttribute("oxTrustMetaLastModified"));
if (meta.getLastModified() == null) {
Date tmpDate = person.getUpdatedAt();
meta.setLastModified(tmpDate == null ? null : ISODateTimeFormat.dateTime().withZoneUTC().print(tmpDate.getTime()));
}
meta.setLocation(person.getAttribute("oxTrustMetaLocation"));
if (meta.getLocation() == null)
meta.setLocation(url + "/" + person.getInum());
res.setMeta(meta);
// Set values in order of appearance in UserResource class
res.setUserName(person.getUid());
Name name = new Name();
name.setGivenName(person.getGivenName());
name.setFamilyName(person.getSurname());
name.setMiddleName(person.getAttribute("middleName"));
name.setHonorificPrefix(person.getAttribute("oxTrusthonorificPrefix"));
name.setHonorificSuffix(person.getAttribute("oxTrusthonorificSuffix"));
String formatted = person.getAttribute("oxTrustNameFormatted");
if (// recomputes the formatted name if absent in LDAP
formatted == null)
name.computeFormattedName();
else
name.setFormatted(formatted);
res.setName(name);
res.setDisplayName(person.getDisplayName());
res.setNickName(person.getAttribute("nickname"));
res.setProfileUrl(person.getAttribute("oxTrustProfileURL"));
res.setTitle(person.getAttribute("oxTrustTitle"));
res.setUserType(person.getAttribute("oxTrustUserType"));
res.setPreferredLanguage(person.getPreferredLanguage());
res.setLocale(person.getAttribute("locale"));
res.setTimezone(person.getTimezone());
res.setActive(Boolean.valueOf(person.getAttribute("oxTrustActive")) || GluuBoolean.getByValue(person.getAttribute("gluuStatus")).isBooleanValue());
res.setPassword(person.getUserPassword());
res.setEmails(getAttributeListValue(person, Email.class, "oxTrustEmail"));
res.setPhoneNumbers(getAttributeListValue(person, PhoneNumber.class, "oxTrustPhoneValue"));
res.setIms(getAttributeListValue(person, InstantMessagingAddress.class, "oxTrustImsValue"));
res.setPhotos(getAttributeListValue(person, Photo.class, "oxTrustPhotos"));
res.setAddresses(getAttributeListValue(person, Address.class, "oxTrustAddresses"));
List<String> listOfGroups = person.getMemberOf();
if (listOfGroups != null && listOfGroups.size() > 0) {
List<Group> groupList = new ArrayList<Group>();
for (String groupDN : listOfGroups) {
try {
GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
Group group = new Group();
group.setValue(gluuGroup.getInum());
String reference = groupWS.getEndpointUrl() + "/" + gluuGroup.getInum();
group.setRef(reference);
group.setDisplay(gluuGroup.getDisplayName());
// Only support direct membership: see section 4.1.2 of RFC 7644
group.setType(Group.Type.DIRECT);
groupList.add(group);
} catch (Exception e) {
log.warn("transferAttributesToUserResource. Group with dn {} could not be added to User Resource. {}", groupDN, person.getUid());
log.error(e.getMessage(), e);
}
}
if (groupList.size() > 0)
res.setGroups(groupList);
}
res.setEntitlements(getAttributeListValue(person, Entitlement.class, "oxTrustEntitlements"));
res.setRoles(getAttributeListValue(person, Role.class, "oxTrustRole"));
res.setX509Certificates(getAttributeListValue(person, X509Certificate.class, "oxTrustx509Certificate"));
res.setPairwiseIdentitifers(person.getOxPPID());
transferExtendedAttributesToResource(person, res);
}
Aggregations