Search in sources :

Example 11 with Name

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);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) Attribute(org.gluu.oxtrust.model.scim2.annotations.Attribute) Validator(org.gluu.oxtrust.model.scim2.annotations.Validator)

Example 12 with Name

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);
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.user.Group) Email(org.gluu.oxtrust.model.scim2.user.Email) Address(org.gluu.oxtrust.model.scim2.user.Address) InstantMessagingAddress(org.gluu.oxtrust.model.scim2.user.InstantMessagingAddress) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.user.Photo) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Date(java.util.Date) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) WebApplicationException(javax.ws.rs.WebApplicationException) X509Certificate(org.gluu.oxtrust.model.scim2.user.X509Certificate) Name(org.gluu.oxtrust.model.scim2.user.Name) Role(org.gluu.oxtrust.model.scim2.user.Role) PhoneNumber(org.gluu.oxtrust.model.scim2.user.PhoneNumber) Entitlement(org.gluu.oxtrust.model.scim2.user.Entitlement) InstantMessagingAddress(org.gluu.oxtrust.model.scim2.user.InstantMessagingAddress)

Aggregations

ArrayList (java.util.ArrayList)6 Date (java.util.Date)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 User (org.gluu.oxtrust.model.scim2.User)4 Field (java.lang.reflect.Field)3 BigDecimal (java.math.BigDecimal)3 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)3 Email (org.gluu.oxtrust.model.scim2.Email)3 Extension (org.gluu.oxtrust.model.scim2.Extension)3 Meta (org.gluu.oxtrust.model.scim2.Meta)3 PhoneNumber (org.gluu.oxtrust.model.scim2.PhoneNumber)3 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)3 Filter (com.unboundid.ldap.sdk.Filter)2 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 Address (org.gluu.oxtrust.model.scim2.Address)2 DEFAULT_COUNT (org.gluu.oxtrust.model.scim2.Constants.DEFAULT_COUNT)2 Entitlement (org.gluu.oxtrust.model.scim2.Entitlement)2 GroupRef (org.gluu.oxtrust.model.scim2.GroupRef)2