Search in sources :

Example 6 with Name

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

the class IntrospectUtil method findFieldFromPath.

/**
 * Inspects a class to search for a field that corresponds to the path passed using dot notation. Every piece of the
 * path (separated by the a dot '.') is expected to have a field with the same name in the class inspected. When such
 * a field is found, the remainder of the path is processed using the class associated to the field, until the path is
 * fully consumed.
 * <p>This method starts from an initial class and visits ascendingly the class hierarchy with a route determined
 * by the components found in the path parameter.</p>
 * @param initcls Class to start the search from
 * @param path A string denoting a path to a target attribute. Examples of valid paths can be: displayName, name.givenName,
 *            addresses.locality
 * @return A Field that represents the terminal portion of the path, for instance "locality" field for "addresses.locality".
 * If no such field is found (because at some point, there was no route to go), null is returned.
 */
public static Field findFieldFromPath(Class<?> initcls, String path) {
    Class cls = initcls;
    Field f = null;
    for (String prop : path.split("\\.")) {
        f = findField(cls, prop);
        if (f != null) {
            cls = f.getType();
            if (isCollection(cls)) {
                Attribute attrAnnot = f.getAnnotation(Attribute.class);
                if (attrAnnot != null)
                    cls = attrAnnot.multiValueClass();
            }
        } else
            break;
    }
    return f;
}
Also used : Field(java.lang.reflect.Field) Attribute(org.gluu.oxtrust.model.scim2.annotations.Attribute)

Example 7 with Name

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

the class ResourceValidator method validateExtendedAttributes.

/**
 * Inspects the resource passed in the constructor and for every extended attribute (see {@link BaseScimResource#getCustomAttributes()},
 * the attribute's value is checked to see if it complies with the data type it is supposed to belong to. This
 * information is obtained from the list of <code>Extension</code>s passed in the constructor (every {@link ExtensionField}
 * has an associated {@link ExtensionField#getType() type}.
 * <p>When an attribute is {@link ExtensionField#isMultiValued() multi-valued}, every single item inside the collection
 * is validated.</p>
 * @throws SCIMException When any of the validations do not pass or an attribute seems not to be part of a known schema.
 */
public void validateExtendedAttributes() throws SCIMException {
    // Note: throughout this method, we always ignore presence of nulls
    // Gets all extended attributes (see the @JsonAnySetter annotation in BaseScimResource)
    Map<String, Object> extendedAttributes = resource.getCustomAttributes();
    // Iterate over every extension of the resource object (in practice it will be just one at most)
    for (String schema : extendedAttributes.keySet()) {
        // Validate if the schema referenced in the extended attributes is contained in the valid set of extension
        Extension extension = null;
        for (Extension ext : extensions) if (ext.getUrn().equals(schema)) {
            extension = ext;
            break;
        }
        if (extension != null) {
            log.debug("validateExtendedAttributes. Revising attributes under schema {}", schema);
            try {
                // Obtains a generic map consisting of all name/value(s) pairs associated to this schema
                Map<String, Object> attrsMap = IntrospectUtil.strObjMap(extendedAttributes.get(schema));
                for (String attr : attrsMap.keySet()) {
                    Object value = attrsMap.get(attr);
                    if (value != null) {
                        /*
                             Gets the class associated to the value of current attribute. For extended attributes, we
                             should only see coming: String, Integer, Double, boolean, and Collection.
                             Different things will be rejected
                             */
                        Class cls = value.getClass();
                        boolean isCollection = IntrospectUtil.isCollection(cls);
                        // If the attribute coming is unknown, NPE will be thrown and we are covered
                        log.debug("validateExtendedAttributes. Got value(s) for attribute '{}'", attr);
                        // Check if the multivalued custom attribute is consistent with the nature of the value itself
                        if (isCollection == extension.getFields().get(attr).isMultiValued()) {
                            if (isCollection) {
                                for (Object elem : (Collection) value) if (elem != null)
                                    validateDataTypeExtendedAttr(extension, attr, elem);
                            } else
                                validateDataTypeExtendedAttr(extension, attr, value);
                        } else
                            throw new SCIMException(ERROR_PARSING_EXTENDED);
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new SCIMException(ERROR_PARSING_EXTENDED);
            }
        } else
            throw new SCIMException(String.format(UNKNOWN_EXTENSION, schema));
    }
}
Also used : Extension(org.gluu.oxtrust.model.scim2.extensions.Extension) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) SCIMException(org.gluu.oxtrust.model.exception.SCIMException)

Example 8 with Name

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

the class UserCoreLoadingStrategy method createDummyUser.

private User createDummyUser() {
    User user = new User();
    org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
    name.setGivenName("");
    name.setMiddleName("");
    name.setFamilyName("");
    name.setHonorificPrefix("");
    name.setHonorificSuffix("");
    user.setName(name);
    user.setActive(false);
    user.setId("");
    user.setExternalId("");
    user.setUserName("");
    user.setPassword("");
    user.setDisplayName("");
    user.setNickName("");
    user.setProfileUrl("");
    user.setLocale("");
    user.setPreferredLanguage("");
    user.setTimezone("");
    user.setTitle("");
    List<GroupRef> groups = new ArrayList<GroupRef>();
    GroupRef groupRef = new GroupRef();
    groupRef.setOperation("");
    groupRef.setPrimary(false);
    groupRef.setValue("test");
    groupRef.setDisplay("");
    groupRef.setType(GroupRef.Type.DIRECT);
    groupRef.setReference("");
    groups.add(groupRef);
    user.setGroups(groups);
    List<Email> emails = new ArrayList<Email>();
    Email email = new Email();
    email.setOperation("");
    email.setPrimary(false);
    email.setValue("a@b.com");
    email.setDisplay("");
    email.setType(Email.Type.WORK);
    email.setReference("");
    emails.add(email);
    user.setEmails(emails);
    List<PhoneNumber> phoneNumbers = new ArrayList<PhoneNumber>();
    PhoneNumber phoneNumber = new PhoneNumber();
    phoneNumber.setOperation("");
    phoneNumber.setPrimary(false);
    phoneNumber.setValue("123-456-7890");
    phoneNumber.setDisplay("");
    phoneNumber.setType(PhoneNumber.Type.WORK);
    phoneNumber.setReference("");
    phoneNumbers.add(phoneNumber);
    user.setPhoneNumbers(phoneNumbers);
    List<Im> ims = new ArrayList<Im>();
    Im im = new Im();
    im.setOperation("");
    im.setPrimary(false);
    im.setValue("test");
    im.setDisplay("");
    im.setType(Im.Type.SKYPE);
    im.setReference("");
    ims.add(im);
    user.setIms(ims);
    List<Photo> photos = new ArrayList<Photo>();
    Photo photo = new Photo();
    photo.setOperation("");
    photo.setPrimary(false);
    photo.setValue("data:image/jpg;charset=utf-8;base64,dGVzdA==");
    photo.setDisplay("");
    photo.setType(Photo.Type.PHOTO);
    photo.setReference("");
    photos.add(photo);
    user.setPhotos(photos);
    List<Address> addresses = new ArrayList<Address>();
    Address address = new Address();
    address.setOperation("");
    address.setPrimary(false);
    address.setValue("test");
    address.setDisplay("");
    address.setType(Address.Type.WORK);
    address.setReference("");
    address.setStreetAddress("");
    address.setLocality("");
    address.setPostalCode("");
    address.setRegion("");
    address.setCountry("");
    address.setFormatted("");
    addresses.add(address);
    user.setAddresses(addresses);
    List<Entitlement> entitlements = new ArrayList<Entitlement>();
    Entitlement entitlement = new Entitlement();
    entitlement.setOperation("");
    entitlement.setPrimary(false);
    entitlement.setValue("test");
    entitlement.setDisplay("");
    entitlement.setType(new Entitlement.Type("test"));
    entitlement.setReference("");
    entitlements.add(entitlement);
    user.setEntitlements(entitlements);
    List<Role> roles = new ArrayList<Role>();
    Role role = new Role();
    role.setOperation("");
    role.setPrimary(false);
    role.setValue("test");
    role.setDisplay("");
    role.setType(new Role.Type("test"));
    role.setReference("");
    roles.add(role);
    user.setRoles(roles);
    List<X509Certificate> x509Certificates = new ArrayList<X509Certificate>();
    X509Certificate x509Certificate = new X509Certificate();
    x509Certificate.setOperation("");
    x509Certificate.setPrimary(false);
    x509Certificate.setValue("test");
    x509Certificate.setDisplay("");
    x509Certificate.setType(new X509Certificate.Type("test"));
    x509Certificate.setReference("");
    x509Certificates.add(x509Certificate);
    user.setX509Certificates(x509Certificates);
    return user;
}
Also used : User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Im(org.gluu.oxtrust.model.scim2.Im) Address(org.gluu.oxtrust.model.scim2.Address) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.Photo) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Role(org.gluu.oxtrust.model.scim2.Role) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement)

Example 9 with Name

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

the class UserExtensionsTest method testCreatePersonFromJsonString.

@Test
@Parameters({ "test.scim2.userext.create_json" })
public void testCreatePersonFromJsonString(final String createJson) throws Exception {
    System.out.println(" testCreatePersonFromJsonString() ");
    // Create custom attributes
    // String, not
    GluuAttribute scimCustomFirst = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomFirst") == null) {
        scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
    }
    // Date, multi-valued
    GluuAttribute scimCustomSecond = null;
    if (attributeService.getAttributeByName("scimCustomSecond") == null) {
        scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
    }
    // Numeric, not
    GluuAttribute scimCustomThird = null;
    // multi-valued
    if (attributeService.getAttributeByName("scimCustomThird") == null) {
        scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
    }
    // String CREATEJSON =
    // "{\"schemas\":[\"urn:ietf:params:scim:schemas:core:2.0:User\",\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\"],\"urn:ietf:params:scim:schemas:extension:gluu:2.0:User\":
    // {\"scimCustomFirst\":\"[1000,2000]\",\"scimCustomSecond\":[\"2016-02-23T15:35:22Z\"],\"scimCustomThird\":3000},\"externalId\":\"scimclient\",\"userName\":\"userjson.add.username\",\"name\":{\"givenName\":\"json\",\"familyName\":\"json\",\"middleName\":\"N/A\",\"honorificPrefix\":\"N/A\",\"honorificSuffix\":\"N/A\"},\"displayName\":\"json
    // json\",\"nickName\":\"json\",\"profileUrl\":\"http://www.gluu.org/\",\"emails\":[{\"value\":\"json@gluu.org\",\"type\":\"work\",\"primary\":\"true\"},{\"value\":\"json2@gluu.org\",\"type\":\"home\",\"primary\":\"false\"}],\"addresses\":[{\"type\":\"work\",\"streetAddress\":\"621
    // East 6th Street Suite
    // 200\",\"locality\":\"Austin\",\"region\":\"TX\",\"postalCode\":\"78701\",\"country\":\"US\",\"formatted\":\"621
    // East 6th Street Suite 200 Austin , TX 78701
    // US\",\"primary\":\"true\"}],\"phoneNumbers\":[{\"value\":\"646-345-2346\",\"type\":\"work\"}],\"ims\":[{\"value\":\"nynytest_user\",\"type\":\"Skype\"}],\"userType\":\"CEO\",\"title\":\"CEO\",\"preferredLanguage\":\"en-us\",\"locale\":\"en_US\",\"active\":\"true\",\"password\":\"secret\",\"roles\":[{\"value\":\"Owner\"}],\"entitlements\":[{\"value\":\"full
    // access\"}],\"x509Certificates\":[{\"value\":\"MIIDQzCCAqygAwIBAgICEAAwDQYJKoZIhvcNAQEFBQAwTjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFDASBgNVBAoMC2V4YW1wbGUuY29tMRQwEgYDVQQDDAtleGFtcGxlLmNvbTAeFw0xMTEwMjIwNjI0MzFaFw0xMjEwMDQwNjI0MzFa
    // MH8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRQwEgYDVQQKDAtleGFtcGxlLmNvbTEhMB8GA1UEAwwYTXMuIEJhcmJhcmEgSiBKZW5zZW4gSUlJMSIwIAYJKoZIhvcNAQkBFhNiamVuc2VuQGV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7Kr+Dcds/JQ5GwejJFcBIP682X3xpjis56AK02bc1FLgzdLI8auoR+cC9/Vrh5t66HkQIOdA4unHh0AaZ4xL5PhVbXIPMB5vAPKpzz5iPSi8xO8SL7I7SDhcBVJhqVqr3HgllEG6UClDdHO7nkLuwXq8HcISKkbT5WFTVfFZzidPl8HZ7DhXkZIRtJwBweq4bvm3hM1Os7UQH05ZS6cVDgweKNwdLLrT51ikSQG3DYrl+ft781UQRIqxgwqCfXEuDiinPh0kkvIi5jivVu1Z9QiwlYEdRbLJ4zJQBmDrSGTMYn4lRc2HgHO4DqB/bnMVorHB0CC6AV1QoFK4GPe1LwIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU8pD0U0vsZIsaA16lL8En8bx0F/gwHwYDVR0jBBgwFoAUdGeKitcaF7gnzsNwDx708kqaVt0wDQYJKoZIhvcNAQEFBQADgYEAA81SsFnOdYJtNg5Tcq+/ByEDrBgnusx0jloUhByPMEVkoMZ3J7j1ZgI8rAbOkNngX8+pKfTiDz1RC4+dx8oU6Za+4NJXUjlL5CvV6BEYb1+QAEJwitTVvxB/A67g42/vzgAtoRUeDov1+GFiBZ+GNF/cAYKcMtGcrs2i97ZkJMo=\"}],\"meta\":{\"created\":\"2010-01-23T04:56:22Z\",\"lastModified\":\"2011-05-13T04:42:34Z\",\"version\":\"aversion\",\"location\":\"http://localhost:8080/identity/seam/resource/restv1/Users/8c4b6c26-efaf-4840-bddf-c0146a8eb2a9\"}}";
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
    SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, ""));
    simpleModule.addDeserializer(User.class, new UserDeserializer());
    mapper.registerModule(simpleModule);
    User user = mapper.readValue(createJson, User.class);
    String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
    user.setUserName(testUserName);
    Extension extension = user.getExtension(Constants.USER_EXT_SCHEMA_ID);
    assertNotNull(extension, "(Deserialization) Custom extension not deserialized.");
    Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
    assertNotNull(customFirstField, "(Deserialization) \"scimCustomFirst\" field not deserialized.");
    assertEquals(customFirstField.getValue(), "[1000,2000]");
    System.out.println("##### (Deserialization) customFirstField.getValue() = " + customFirstField.getValue());
    Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
    assertNotNull(customSecondField, "(Deserialization) \"scimCustomSecond\" field not deserialized.");
    List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
    assertEquals(dateList.size(), 1);
    System.out.println("##### (Deserialization) dateList.get(0) = " + dateList.get(0));
    Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
    assertNotNull(customThirdField, "(Deserialization) \"scimCustomThird\" field not deserialized.");
    assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
    System.out.println("##### (Deserialization) customThirdField.getValue() = " + customThirdField.getValue());
    // Create Person
    GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
    assertNotNull(gluuPerson, "gluuPerson is null!");
    System.out.println(">>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
    String inum = personService.generateInumForNewPerson();
    String dn = personService.getDnForPerson(inum);
    String iname = personService.generateInameForNewPerson(user.getUserName());
    gluuPerson.setDn(dn);
    gluuPerson.setInum(inum);
    gluuPerson.setIname(iname);
    gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
    personService.addPerson(gluuPerson);
    // Retrieve Person
    GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
    assertNotNull(retrievedPerson, "Failed to find person.");
    User newPerson = copyUtils2.copy(retrievedPerson, null);
    extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
    assertNotNull(extension, "(Persistence) Custom extension not persisted.");
    customFirstField = extension.getFields().get("scimCustomFirst");
    assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
    assertEquals(customFirstField.getValue(), "[1000,2000]");
    System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
    customSecondField = extension.getFields().get("scimCustomSecond");
    assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
    dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
    assertEquals(dateList.size(), 1);
    System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
    customThirdField = extension.getFields().get("scimCustomThird");
    assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
    assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
    System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
    // Remove Person
    memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
Also used : UserDeserializer(org.gluu.oxtrust.service.scim2.jackson.custom.UserDeserializer) User(org.gluu.oxtrust.model.scim2.User) Date(java.util.Date) BigDecimal(java.math.BigDecimal) GluuAttribute(org.xdi.model.GluuAttribute) Extension(org.gluu.oxtrust.model.scim2.Extension) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.gluu.oxtrust.action.test.BaseTest)

Example 10 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;
    if (filterString == null || (filterString != null && filterString.isEmpty())) {
        if (entryClass.getName().equals(GluuCustomFidoDevice.class.getName())) {
            filter = Filter.create("oxId=*");
        } else {
            filter = Filter.create("inum=*");
        }
    } else {
        Class clazz = null;
        if (entryClass.getName().equals(GluuCustomPerson.class.getName())) {
            clazz = User.class;
        } else if (entryClass.getName().equals(GluuGroup.class.getName())) {
            clazz = Group.class;
        } else if (entryClass.getName().equals(GluuCustomFidoDevice.class.getName())) {
            clazz = FidoDevice.class;
        }
        filter = scimFilterParserService.createFilter(filterString, clazz);
    }
    startIndex = (startIndex < 1) ? 1 : startIndex;
    count = (count < 1) ? DEFAULT_COUNT : count;
    count = (count > getMaxCount()) ? getMaxCount() : count;
    if (entryClass.getName().equals(GluuCustomFidoDevice.class.getName())) {
        sortBy = (sortBy != null && !sortBy.isEmpty()) ? sortBy : "id";
        sortBy = getFidoDeviceLdapAttributeName(sortBy);
    } else {
        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;
    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.stripScim2Schema(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");
                        attributesSet.add("name.formatted");
                    }
                } 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");
        }
        if (entryClass.getName().equals(GluuCustomFidoDevice.class.getName())) {
            // For meta.created
            attributesSet.add("creationDate");
            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());
                } else if (entryClass.getName().equals(GluuCustomFidoDevice.class.getName())) {
                    attributes[i] = getFidoDeviceLdapAttributeName(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) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) ArrayList(java.util.ArrayList) SortOrder(org.xdi.ldap.model.SortOrder) GluuGroup(org.gluu.oxtrust.model.GluuGroup) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) GluuCustomFidoDevice(org.gluu.oxtrust.model.fido.GluuCustomFidoDevice) DEFAULT_COUNT(org.gluu.oxtrust.model.scim2.Constants.DEFAULT_COUNT) Filter(com.unboundid.ldap.sdk.Filter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

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