Search in sources :

Example 1 with Name

use of org.gluu.oxtrust.model.scim2.user.Name in project oxTrust by GluuFederation.

the class CopyUtils2 method copy.

/**
	 * Copy data from GluuCustomPerson object to ScimPerson object "Reda"
	 * 
	 * @param source
	 * @param destination
	 * @return
	 * @throws Exception
	 */
public User copy(GluuCustomPerson source, User destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new User();
    }
    log.trace(" setting ID ");
    if (source.getInum() != null) {
        destination.setId(source.getInum());
    }
    log.trace(" setting userName ");
    if (source.getUid() != null) {
        destination.setUserName(source.getUid());
    }
    log.trace(" setting ExternalID ");
    if (source.getAttribute("oxTrustExternalId") != null) {
        destination.setExternalId(source.getAttribute("oxTrustExternalId"));
    }
    log.trace(" setting givenname ");
    if (source.getGivenName() != null) {
        org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
        name.setGivenName(source.getGivenName());
        if (source.getSurname() != null)
            name.setFamilyName(source.getSurname());
        if (source.getAttribute("middleName") != null)
            name.setMiddleName(source.getAttribute("middleName"));
        /*
			if (source.getAttribute("oxTrustMiddleName") != null)
				name.setMiddleName(source.getAttribute("oxTrustMiddleName"));
			*/
        if (source.getAttribute("oxTrusthonorificPrefix") != null)
            name.setHonorificPrefix(source.getAttribute("oxTrusthonorificPrefix"));
        if (source.getAttribute("oxTrusthonorificSuffix") != null)
            name.setHonorificSuffix(source.getAttribute("oxTrusthonorificSuffix"));
        name.setFormatted(name.getFormatted());
        destination.setName(name);
    }
    log.trace(" getting displayname ");
    if (source.getDisplayName() != null) {
        destination.setDisplayName(source.getDisplayName());
    }
    log.trace(" getting nickname ");
    /*
		if (source.getAttribute("oxTrustNickName") != null) {
			destination.setNickName(source.getAttribute("oxTrustNickName"));
		}
		*/
    if (source.getAttribute("nickname") != null) {
        destination.setNickName(source.getAttribute("nickname"));
    }
    log.trace(" getting profileURL ");
    if (source.getAttribute("oxTrustProfileURL") != null) {
        destination.setProfileUrl(source.getAttribute("oxTrustProfileURL"));
    }
    log.trace(" getting emails ");
    // source = Utils.syncEmailReverse(source, true);
    if (source.getAttributeArray("oxTrustEmail") != null) {
        /*
			String[] emailArray = source.getAttributeArray("oxTrustEmail");
			List<Email> emails = new ArrayList<Email>();

			for (String emailStr : emailArray) {
				Email email = mapper.readValue(emailStr, Email.class);
				emails.add(email);
			}

			// List<Email> listOfEmails = mapper.readValue(source.getAttribute("oxTrustEmail"), new TypeReference<List<Email>>(){});
			// destination.setEmails(listOfEmails);
			*/
        List<Email> emails = getAttributeListValue(source, Email.class, "oxTrustEmail");
        destination.setEmails(emails);
    }
    log.trace(" getting addresses ");
    // getting addresses
    if (source.getAttribute("oxTrustAddresses") != null) {
        List<Address> addresses = getAttributeListValue(source, Address.class, "oxTrustAddresses");
        destination.setAddresses(addresses);
    }
    log.trace(" setting phoneNumber ");
    // getting user's PhoneNumber
    if (source.getAttribute("oxTrustPhoneValue") != null) {
        List<PhoneNumber> phoneNumbers = getAttributeListValue(source, PhoneNumber.class, "oxTrustPhoneValue");
        destination.setPhoneNumbers(phoneNumbers);
    }
    if ((source.getOxPPID()) != null) {
        destination.setPairwiseIdentitifers(source.getOxPPID());
    }
    log.trace(" getting ims ");
    // getting ims
    if (source.getAttribute("oxTrustImsValue") != null) {
        List<Im> ims = getAttributeListValue(source, Im.class, "oxTrustImsValue");
        destination.setIms(ims);
    }
    log.trace(" setting photos ");
    // getting photos
    if (source.getAttribute("oxTrustPhotos") != null) {
        List<Photo> photos = getAttributeListValue(source, Photo.class, "oxTrustPhotos");
        destination.setPhotos(photos);
    }
    log.trace(" setting userType ");
    if (source.getAttribute("oxTrustUserType") != null) {
        destination.setUserType(source.getAttribute("oxTrustUserType"));
    }
    log.trace(" setting title ");
    if (source.getAttribute("oxTrustTitle") != null) {
        destination.setTitle(source.getAttribute("oxTrustTitle"));
    }
    log.trace(" setting Locale ");
    /*
		if (source.getAttribute("oxTrustLocale") != null) {
			destination.setLocale(source.getAttribute("oxTrustLocale"));
		}
		*/
    if (source.getAttribute("locale") != null) {
        destination.setLocale(source.getAttribute("locale"));
    }
    log.trace(" setting preferredLanguage ");
    if (source.getPreferredLanguage() != null) {
        destination.setPreferredLanguage(source.getPreferredLanguage());
    }
    log.trace(" setting timeZone ");
    if (source.getTimezone() != null) {
        destination.setTimezone(source.getTimezone());
    }
    log.trace(" setting active ");
    if (source.getAttribute("oxTrustActive") != null) {
        destination.setActive(Boolean.parseBoolean(source.getAttribute("oxTrustActive")));
    }
    log.trace(" setting password ");
    destination.setPassword("Hidden for Privacy Reasons");
    // getting user groups
    log.trace(" setting  groups ");
    if (source.getMemberOf() != null) {
        List<String> listOfGroups = source.getMemberOf();
        List<GroupRef> groupRefList = new ArrayList<GroupRef>();
        for (String groupDN : listOfGroups) {
            GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
            GroupRef groupRef = new GroupRef();
            groupRef.setDisplay(gluuGroup.getDisplayName());
            groupRef.setValue(gluuGroup.getInum());
            String reference = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/" + gluuGroup.getInum();
            groupRef.setReference(reference);
            groupRefList.add(groupRef);
        }
        destination.setGroups(groupRefList);
    }
    // getting roles
    if (source.getAttribute("oxTrustRole") != null) {
        List<Role> roles = getAttributeListValue(source, Role.class, "oxTrustRole");
        destination.setRoles(roles);
    }
    log.trace(" getting entitlements ");
    // getting entitlements
    if (source.getAttribute("oxTrustEntitlements") != null) {
        List<Entitlement> entitlements = getAttributeListValue(source, Entitlement.class, "oxTrustEntitlements");
        destination.setEntitlements(entitlements);
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getAttribute("oxTrustx509Certificate") != null) {
        List<X509Certificate> x509Certificates = getAttributeListValue(source, X509Certificate.class, "oxTrustx509Certificate");
        destination.setX509Certificates(x509Certificates);
    }
    log.trace(" setting extensions ");
    // List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributesImpl(attributeService.getCustomAttributes());
    List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributes();
    if (scimCustomAttributes != null && !scimCustomAttributes.isEmpty()) {
        Map<String, Extension> extensionMap = new HashMap<String, Extension>();
        Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID);
        boolean hasExtension = false;
        outer: for (GluuCustomAttribute customAttribute : source.getCustomAttributes()) {
            for (GluuAttribute scimCustomAttribute : scimCustomAttributes) {
                if (customAttribute.getName().equals(scimCustomAttribute.getName())) {
                    hasExtension = true;
                    GluuAttributeDataType scimCustomAttributeDataType = scimCustomAttribute.getDataType();
                    if ((scimCustomAttribute.getOxMultivaluedAttribute() != null) && scimCustomAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
                        extensionBuilder.setFieldAsList(customAttribute.getName(), Arrays.asList(customAttribute.getValues()));
                    } else {
                        if (scimCustomAttributeDataType.equals(GluuAttributeDataType.STRING) || scimCustomAttributeDataType.equals(GluuAttributeDataType.PHOTO)) {
                            String value = ExtensionFieldType.STRING.fromString(customAttribute.getValue());
                            extensionBuilder.setField(customAttribute.getName(), value);
                        } else if (scimCustomAttributeDataType.equals(GluuAttributeDataType.DATE)) {
                            Date value = ExtensionFieldType.DATE_TIME.fromString(customAttribute.getValue());
                            extensionBuilder.setField(customAttribute.getName(), value);
                        } else if (scimCustomAttributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
                            BigDecimal value = ExtensionFieldType.DECIMAL.fromString(customAttribute.getValue());
                            extensionBuilder.setField(customAttribute.getName(), value);
                        }
                    }
                    continue outer;
                }
            }
        }
        if (hasExtension) {
            extensionMap.put(Constants.USER_EXT_SCHEMA_ID, extensionBuilder.build());
            destination.getSchemas().add(Constants.USER_EXT_SCHEMA_ID);
            destination.setExtensions(extensionMap);
        }
    }
    log.trace(" getting meta ");
    Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
    if (source.getAttribute("oxTrustMetaVersion") != null) {
        meta.setVersion(source.getAttribute("oxTrustMetaVersion"));
    }
    String location = source.getAttribute("oxTrustMetaLocation");
    if (location != null && !location.isEmpty()) {
        if (!location.startsWith("https://") && !location.startsWith("http://")) {
            location = appConfiguration.getBaseEndpoint() + location;
        }
    } else {
        location = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/" + source.getInum();
    }
    meta.setLocation(location);
    if (source.getAttribute("oxTrustMetaCreated") != null && !source.getAttribute("oxTrustMetaCreated").isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaCreated"), DateTimeZone.UTC);
            meta.setCreated(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            // For backward compatibility
            try {
                meta.setCreated(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaCreated")));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    if (source.getAttribute("oxTrustMetaLastModified") != null && !source.getAttribute("oxTrustMetaLastModified").isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaLastModified"), DateTimeZone.UTC);
            meta.setLastModified(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            // For backward compatibility
            try {
                meta.setLastModified(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaLastModified")));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    destination.setMeta(meta);
    return destination;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.Photo) DateTime(org.joda.time.DateTime) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttributeDataType(org.xdi.model.GluuAttributeDataType) GluuGroup(org.gluu.oxtrust.model.GluuGroup) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Date(java.util.Date) BigDecimal(java.math.BigDecimal) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) GluuAttribute(org.xdi.model.GluuAttribute) GluuUserRole(org.xdi.model.GluuUserRole) Role(org.gluu.oxtrust.model.scim2.Role) Extension(org.gluu.oxtrust.model.scim2.Extension) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Name

use of org.gluu.oxtrust.model.scim2.user.Name in project oxTrust by GluuFederation.

the class BaseScimWebService method search.

public <T> List<T> search(String dn, Class<T> entryClass, String filterString, int startIndex, int count, String sortBy, String sortOrder, VirtualListViewResponse vlvResponse, String attributesArray) throws Exception {
    log.info("----------");
    log.info(" ### RAW PARAMS ###");
    log.info(" filter string = " + filterString);
    log.info(" startIndex = " + startIndex);
    log.info(" count = " + count);
    log.info(" sortBy = " + sortBy);
    log.info(" sortOrder = " + sortOrder);
    log.info(" attributes = " + attributesArray);
    Filter filter = null;
    if (filterString == null || (filterString != null && filterString.isEmpty())) {
        filter = Filter.create("inum=*");
    } else {
        Class clazz = null;
        if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
            clazz = ScimPerson.class;
        } else if (entryClass.getName().equals(GluuGroup.class.getName())) {
            clazz = ScimGroup.class;
        }
        filter = scimFilterParserService.createFilter(filterString, clazz);
    }
    startIndex = (startIndex < 1) ? 1 : startIndex;
    count = (count < 1) ? DEFAULT_COUNT : count;
    count = (count > getMaxCount()) ? getMaxCount() : count;
    sortBy = (sortBy != null && !sortBy.isEmpty()) ? sortBy : "displayName";
    if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
        sortBy = getUserLdapAttributeName(sortBy);
    } else if (entryClass.getName().equals(GluuGroup.class.getName())) {
        sortBy = getGroupLdapAttributeName(sortBy);
    }
    SortOrder sortOrderEnum = null;
    if (sortOrder != null && !sortOrder.isEmpty()) {
        sortOrderEnum = SortOrder.getByValue(sortOrder);
    } else if (sortBy != null && (sortOrder == null || (sortOrder != null && sortOrder.isEmpty()))) {
        sortOrderEnum = SortOrder.ASCENDING;
    } else {
        sortOrderEnum = SortOrder.ASCENDING;
    }
    // String[] attributes = (attributesArray != null && !attributesArray.isEmpty()) ? mapper.readValue(attributesArray, String[].class) : null;
    String[] attributes = (attributesArray != null && !attributesArray.isEmpty()) ? attributesArray.split("\\,") : null;
    if (attributes != null && attributes.length > 0) {
        // Add the attributes which are returned by default
        List<String> attributesList = new ArrayList<String>(Arrays.asList(attributes));
        Set<String> attributesSet = new LinkedHashSet<String>();
        for (String attribute : attributesList) {
            if (attribute != null && !attribute.isEmpty()) {
                attribute = FilterUtil.stripScim1Schema(attribute);
                if (entryClass.getName().equals(GluuCustomPerson.class.getName()) && attribute.toLowerCase().startsWith("name.")) {
                    if (!attributesSet.contains("name.familyName")) {
                        attributesSet.add("name.familyName");
                        attributesSet.add("name.middleName");
                        attributesSet.add("name.givenName");
                        attributesSet.add("name.honorificPrefix");
                        attributesSet.add("name.honorificSuffix");
                    }
                } else {
                    attributesSet.add(attribute);
                }
            }
        }
        attributesSet.add("id");
        if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
            attributesSet.add("userName");
        }
        if (entryClass.getName().equals(GluuGroup.class.getName())) {
            attributesSet.add("displayName");
        }
        /*
			attributesSet.add("meta.created");
			attributesSet.add("meta.lastModified");
			attributesSet.add("meta.location");
			attributesSet.add("meta.version");
			*/
        attributes = attributesSet.toArray(new String[attributesSet.size()]);
        for (int i = 0; i < attributes.length; i++) {
            if (attributes[i] != null && !attributes[i].isEmpty()) {
                if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
                    attributes[i] = getUserLdapAttributeName(attributes[i].trim());
                } else if (entryClass.getName().equals(GluuGroup.class.getName())) {
                    attributes[i] = getGroupLdapAttributeName(attributes[i].trim());
                }
            }
        }
    }
    log.info(" ### CONVERTED PARAMS ###");
    log.info(" parsed filter = " + filter.toString());
    log.info(" startIndex = " + startIndex);
    log.info(" count = " + count);
    log.info(" sortBy = " + sortBy);
    log.info(" sortOrder = " + sortOrderEnum.getValue());
    log.info(" attributes = " + ((attributes != null && attributes.length > 0) ? new ObjectMapper().writeValueAsString(attributes) : null));
    // List<T> result = ldapEntryManager.findEntriesVirtualListView(dn, entryClass, filter, startIndex, count, sortBy, sortOrderEnum, vlvResponse, attributes);
    List<T> result = ldapEntryManager.findEntriesSearchSearchResult(dn, entryClass, filter, startIndex, count, getMaxCount(), sortBy, sortOrderEnum, vlvResponse, attributes);
    log.info(" ### RESULTS INFO ###");
    log.info(" totalResults = " + vlvResponse.getTotalResults());
    log.info(" itemsPerPage = " + vlvResponse.getItemsPerPage());
    log.info(" startIndex = " + vlvResponse.getStartIndex());
    log.info("----------");
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) SortOrder(org.xdi.ldap.model.SortOrder) GluuGroup(org.gluu.oxtrust.model.GluuGroup) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) DEFAULT_COUNT(org.gluu.oxtrust.model.scim2.Constants.DEFAULT_COUNT) Filter(com.unboundid.ldap.sdk.Filter) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with Name

use of org.gluu.oxtrust.model.scim2.user.Name in project oxTrust by GluuFederation.

the class UserExtensionsTest method createUserObject.

private User createUserObject() throws Exception {
    User user = new User();
    user.setUserName("userjson.add.username");
    String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
    user.setUserName(testUserName);
    user.setPassword("test");
    user.setDisplayName("Scim2DisplayName");
    Email email = new Email();
    email.setValue("scim@gluu.org");
    email.setType(org.gluu.oxtrust.model.scim2.Email.Type.WORK);
    email.setPrimary(true);
    user.getEmails().add(email);
    PhoneNumber phone = new PhoneNumber();
    phone.setType(org.gluu.oxtrust.model.scim2.PhoneNumber.Type.WORK);
    phone.setValue("654-6509-263");
    user.getPhoneNumbers().add(phone);
    org.gluu.oxtrust.model.scim2.Address address = new org.gluu.oxtrust.model.scim2.Address();
    address.setCountry("US");
    address.setStreetAddress("random street");
    address.setLocality("Austin");
    address.setPostalCode("65672");
    address.setRegion("TX");
    address.setPrimary(true);
    address.setType(org.gluu.oxtrust.model.scim2.Address.Type.WORK);
    address.setFormatted(address.getStreetAddress() + " " + address.getLocality() + " " + address.getPostalCode() + " " + address.getRegion() + " " + address.getCountry());
    user.getAddresses().add(address);
    user.setPreferredLanguage("US_en");
    org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
    name.setFamilyName("SCIM");
    name.setGivenName("SCIM");
    user.setName(name);
    // User Extensions
    Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID);
    extensionBuilder.setField("scimCustomFirst", "customFirstValue");
    // extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new
    // String[]{"2016-02-23T03:35:22Z", "2016-02-24T01:52:05Z"}));
    extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new Date[] { (new DateTime("1969-01-02")).toDate(), (new DateTime("2016-02-27")).toDate() }));
    extensionBuilder.setField("scimCustomThird", new BigDecimal(3000));
    user.addExtension(extensionBuilder.build());
    return user;
}
Also used : User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Date(java.util.Date) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Extension(org.gluu.oxtrust.model.scim2.Extension) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber)

Example 4 with Name

use of org.gluu.oxtrust.model.scim2.user.Name in project oxTrust by GluuFederation.

the class SchemaTypeUserSerializer method serialize.

@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(user, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (!(SchemaTypeMapping.getSchemaTypeInstance(rootNodeEntry.getKey()) instanceof UserExtensionSchema)) {
                if (rootNodeEntry.getValue() instanceof ObjectNode) {
                    if (rootNodeEntry.getKey().equalsIgnoreCase("name")) {
                        AttributeHolder attributeHolder = new AttributeHolder();
                        attributeHolder.setName(rootNodeEntry.getKey());
                        attributeHolder.setType("string");
                        attributeHolder.setDescription("Name object");
                        attributeHolder.setRequired(Boolean.FALSE);
                        List<AttributeHolder> nameAttributeHolders = new ArrayList<AttributeHolder>();
                        Iterator<Map.Entry<String, JsonNode>> nameIterator = rootNodeEntry.getValue().getFields();
                        while (nameIterator.hasNext()) {
                            Map.Entry<String, JsonNode> nameRootNodeEntry = nameIterator.next();
                            AttributeHolder nameAttributeHolder = new AttributeHolder();
                            nameAttributeHolder.setName(nameRootNodeEntry.getKey());
                            nameAttributeHolder.setType("string");
                            if (nameRootNodeEntry.getKey().equalsIgnoreCase("formatted")) {
                                nameAttributeHolder.setDescription("Formatted name on-the-fly for display. Using this in a query filter is not supported.");
                                nameAttributeHolder.setMutability("readOnly");
                            } else {
                                nameAttributeHolder.setDescription(nameRootNodeEntry.getKey());
                            }
                            if (nameRootNodeEntry.getKey().equalsIgnoreCase("givenName") || nameRootNodeEntry.getKey().equalsIgnoreCase("familyName")) {
                                nameAttributeHolder.setRequired(true);
                            } else {
                                nameAttributeHolder.setRequired(false);
                            }
                            nameAttributeHolders.add(nameAttributeHolder);
                        }
                        attributeHolder.setSubAttributes(nameAttributeHolders);
                        attributeHolders.add(attributeHolder);
                    }
                } else if (rootNodeEntry.getValue() instanceof ArrayNode) {
                    AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
                    arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getKey().equalsIgnoreCase("groups")) {
                        arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                        List<String> referenceTypes = new ArrayList<String>();
                        referenceTypes.add("Group");
                        arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                    } else {
                        arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
                    }
                    arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
                    arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
                    if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                        arrayNodeAttributeHolder.setUniqueness("server");
                        arrayNodeAttributeHolder.setType("string");
                        arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                        arrayNodeAttributeHolder.setReturned("always");
                    } else {
                        arrayNodeAttributeHolder.setType("complex");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("photos")) {
                        arrayNodeAttributeHolder.setType("reference");
                        List<String> referenceTypes = new ArrayList<String>();
                        referenceTypes.add("uri");
                        arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                    }
                    List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
                    Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
                    while (arrayNodeIterator.hasNext()) {
                        JsonNode jsonNode = arrayNodeIterator.next();
                        Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
                        while (arrayNodeMapIterator.hasNext()) {
                            Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
                            AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
                            if (rootNodeEntry.getKey().equalsIgnoreCase("groups") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
                                arrayNodeMapAttributeHolder.setName("$ref");
                            } else {
                                arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
                            }
                            arrayNodeMapAttributeHolder.setType("string");
                            arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
                            if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
                                arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
                            } else {
                                arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
                            }
                            if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsImageDataURI") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("valueAsURI")) {
                                arrayNodeMapAttributeHolder.setMutability("readOnly");
                                arrayNodeMapAttributeHolder.setType("reference");
                                List<String> referenceTypes = new ArrayList<String>();
                                referenceTypes.add("uri");
                                arrayNodeMapAttributeHolder.setReferenceTypes(referenceTypes);
                            }
                            arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
                        }
                        arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
                        attributeHolders.add(arrayNodeAttributeHolder);
                    }
                } else {
                    AttributeHolder attributeHolder = new AttributeHolder();
                    attributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getValue().isBoolean()) {
                        attributeHolder.setType("boolean");
                    } else {
                        attributeHolder.setType("string");
                    }
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                    if (rootNodeEntry.getKey().equalsIgnoreCase("userName") || rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                        attributeHolder.setRequired(Boolean.TRUE);
                    } else {
                        attributeHolder.setRequired(Boolean.FALSE);
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("userName")) {
                        attributeHolder.setUniqueness("server");
                        attributeHolder.setReturned("always");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("externalId") || rootNodeEntry.getKey().equalsIgnoreCase("password")) {
                        attributeHolder.setCaseExact(Boolean.TRUE);
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
                        attributeHolder.setMutability("readOnly");
                    }
                    attributeHolders.add(attributeHolder);
                }
            }
        }
        UserCoreSchema userCoreSchema = (UserCoreSchema) schemaType;
        userCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = userCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the User class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) IOException(java.io.IOException) UserExtensionSchema(org.gluu.oxtrust.model.scim2.schema.extension.UserExtensionSchema) Iterator(java.util.Iterator) UserCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.UserCoreSchema) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 5 with Name

use of org.gluu.oxtrust.model.scim2.user.Name in project oxTrust by GluuFederation.

the class SchemaWebService method getSchemaInstance.

private SchemaResource getSchemaInstance(Class<? extends BaseScimResource> clazz) throws Exception {
    SchemaResource resource;
    Class<? extends BaseScimResource> schemaCls = SchemaResource.class;
    Schema annotation = ScimResourceUtil.getSchemaAnnotation(clazz);
    if (!clazz.equals(schemaCls) && annotation != null) {
        Meta meta = new Meta();
        meta.setResourceType(ScimResourceUtil.getType(schemaCls));
        meta.setLocation(endpointUrl + "/" + annotation.id());
        resource = new SchemaResource();
        resource.setId(annotation.id());
        resource.setName(annotation.name());
        resource.setDescription(annotation.description());
        resource.setMeta(meta);
        List<SchemaAttribute> attribs = new ArrayList<SchemaAttribute>();
        // paths are, happily alphabetically sorted :)
        for (String path : IntrospectUtil.allAttrs.get(clazz)) {
            SchemaAttribute schAttr = new SchemaAttribute();
            Field f = IntrospectUtil.findFieldFromPath(clazz, path);
            Attribute attrAnnot = f.getAnnotation(Attribute.class);
            if (attrAnnot != null) {
                JsonProperty jsonAnnot = f.getAnnotation(JsonProperty.class);
                schAttr.setName(jsonAnnot == null ? f.getName() : jsonAnnot.value());
                schAttr.setType(attrAnnot.type().getName());
                schAttr.setMultiValued(!attrAnnot.multiValueClass().equals(NullType.class) || IntrospectUtil.isCollection(f.getType()));
                schAttr.setDescription(attrAnnot.description());
                schAttr.setRequired(attrAnnot.isRequired());
                schAttr.setCanonicalValues(attrAnnot.canonicalValues().length == 0 ? null : Arrays.asList(attrAnnot.canonicalValues()));
                schAttr.setCaseExact(attrAnnot.isCaseExact());
                schAttr.setMutability(attrAnnot.mutability().getName());
                schAttr.setReturned(attrAnnot.returned().getName());
                schAttr.setUniqueness(attrAnnot.uniqueness().getName());
                schAttr.setReferenceTypes(attrAnnot.referenceTypes().length == 0 ? null : Arrays.asList(attrAnnot.referenceTypes()));
                if (attrAnnot.type().equals(AttributeDefinition.Type.COMPLEX))
                    schAttr.setSubAttributes(new ArrayList<SchemaAttribute>());
                // root list
                List<SchemaAttribute> list = attribs;
                String[] parts = path.split("\\.");
                for (int i = 0; i < parts.length - 1; i++) {
                    // skip last part (real attribute name)
                    int j = list.indexOf(new SchemaAttribute(parts[i]));
                    list = list.get(j).getSubAttributes();
                }
                list.add(schAttr);
            }
        }
        resource.setAttributes(attribs);
    } else
        resource = null;
    return resource;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) JsonProperty(org.codehaus.jackson.annotate.JsonProperty) Attribute(org.gluu.oxtrust.model.scim2.annotations.Attribute) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) Schema(org.gluu.oxtrust.model.scim2.annotations.Schema) ExtensionField(org.gluu.oxtrust.model.scim2.extensions.ExtensionField) Field(java.lang.reflect.Field) NullType(javax.lang.model.type.NullType) SchemaAttribute(org.gluu.oxtrust.model.scim2.provider.schema.SchemaAttribute) SchemaResource(org.gluu.oxtrust.model.scim2.provider.schema.SchemaResource)

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