Search in sources :

Example 1 with SortOrder

use of org.xdi.ldap.model.SortOrder 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 2 with SortOrder

use of org.xdi.ldap.model.SortOrder 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

Filter (com.unboundid.ldap.sdk.Filter)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2 GluuGroup (org.gluu.oxtrust.model.GluuGroup)2 DEFAULT_COUNT (org.gluu.oxtrust.model.scim2.Constants.DEFAULT_COUNT)2 SortOrder (org.xdi.ldap.model.SortOrder)2 GluuCustomFidoDevice (org.gluu.oxtrust.model.fido.GluuCustomFidoDevice)1 ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)1 Group (org.gluu.oxtrust.model.scim2.Group)1