Search in sources :

Example 36 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class GrouperEntityGroupStore method searchForEntities.

/**
 * @see IEntitySearcher#searchForEntities(java.lang.String,
 *     org.apereo.portal.groups.IGroupConstants.SearchMethod, java.lang.Class)
 */
@SuppressWarnings("unchecked")
public EntityIdentifier[] searchForEntities(String query, SearchMethod method, Class type) throws GroupsException {
    // only search for groups
    if (type != IPerson.class) {
        return new EntityIdentifier[] {};
    }
    List<EntityIdentifier> entityIdentifiers = new ArrayList<EntityIdentifier>();
    try {
        GcGetSubjects subjects = new GcGetSubjects();
        subjects.assignIncludeSubjectDetail(true);
        WsGetSubjectsResults results = subjects.assignSearchString(query).execute();
        if (results != null && results.getWsSubjects() != null) {
            for (WsSubject wsSubject : results.getWsSubjects()) {
                entityIdentifiers.add(new EntityIdentifier(wsSubject.getName(), ICompositeGroupService.LEAF_ENTITY_TYPE));
            }
        }
        return entityIdentifiers.toArray(new EntityIdentifier[entityIdentifiers.size()]);
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "search results for query " + query + " and entity type " + type.getCanonicalName() + " : " + e.getMessage());
        return new EntityIdentifier[] {};
    }
}
Also used : WsGetSubjectsResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetSubjectsResults) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier) WsSubject(edu.internet2.middleware.grouperClient.ws.beans.WsSubject) GcGetSubjects(edu.internet2.middleware.grouperClient.api.GcGetSubjects) GroupsException(org.apereo.portal.groups.GroupsException)

Example 37 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class GrouperEntityGroupStore method searchForGroups.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#searchForGroups(java.lang.String, int, java.lang.Class)
     */
public EntityIdentifier[] searchForGroups(final String query, final SearchMethod method, @SuppressWarnings("unchecked") final Class leaftype) {
    // only search for groups
    if (leaftype != IPerson.class) {
        return new EntityIdentifier[] {};
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Searching Grouper for groups matching query: " + query);
    }
    // result groups.
    List<EntityIdentifier> groups = new ArrayList<EntityIdentifier>();
    try {
        // TODO: searches need to be performed against the group display
        // name rather than the group key
        GcFindGroups groupSearch = new GcFindGroups();
        WsQueryFilter filter = new WsQueryFilter();
        // is this an exact search or fuzzy
        if ((method == SearchMethod.DISCRETE_CI) || (method == SearchMethod.DISCRETE)) {
            filter.setQueryFilterType("FIND_BY_GROUP_NAME_EXACT");
        } else {
            filter.setQueryFilterType("FIND_BY_GROUP_NAME_APPROXIMATE");
        }
        filter.setGroupName(query);
        groupSearch.assignQueryFilter(filter);
        WsFindGroupsResults results = groupSearch.execute();
        if (results != null && results.getGroupResults() != null) {
            for (WsGroup g : results.getGroupResults()) {
                if (validKey(g.getName())) {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("Retrieved group: " + g.getName());
                    }
                    groups.add(new EntityIdentifier(g.getName(), IEntityGroup.class));
                }
            }
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Returning " + groups.size() + " results for query " + query);
        }
        return groups.toArray(new EntityIdentifier[groups.size()]);
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "search results for query " + query + " and entity type " + leaftype.getCanonicalName() + " : " + e.getMessage());
        return new EntityIdentifier[] {};
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) WsQueryFilter(edu.internet2.middleware.grouperClient.ws.beans.WsQueryFilter) WsFindGroupsResults(edu.internet2.middleware.grouperClient.ws.beans.WsFindGroupsResults) GcFindGroups(edu.internet2.middleware.grouperClient.api.GcFindGroups) ArrayList(java.util.ArrayList) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) EntityIdentifier(org.apereo.portal.EntityIdentifier) GroupsException(org.apereo.portal.groups.GroupsException)

Example 38 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class LDAPGroupStore method searchForEntities.

public EntityIdentifier[] searchForEntities(String query, SearchMethod method, Class type) throws GroupsException {
    if (type != group && type != iperson)
        return new EntityIdentifier[0];
    // Guarantee that LDAP injection is prevented by replacing LDAP special characters
    // with escaped versions of the character
    query = LdapEncoder.filterEncode(query);
    ArrayList ids = new ArrayList();
    switch(method) {
        case STARTS_WITH:
        case STARTS_WITH_CI:
            query = query + "*";
            break;
        case ENDS_WITH:
        case ENDS_WITH_CI:
            query = "*" + query;
            break;
        case CONTAINS:
        case CONTAINS_CI:
            query = "*" + query + "*";
            break;
        case DISCRETE:
        case DISCRETE_CI:
    }
    query = namefield + "=" + query;
    DirContext context = getConnection();
    NamingEnumeration userlist = null;
    SearchControls sc = new SearchControls();
    sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
    sc.setReturningAttributes(new String[] { keyfield });
    try {
        userlist = context.search(usercontext, query, sc);
        ArrayList keys = new ArrayList();
        processLdapResults(userlist, keys);
        String[] k = (String[]) keys.toArray(new String[0]);
        for (int i = 0; i < k.length; i++) {
            ids.add(new EntityIdentifier(k[i], iperson));
        }
        return (EntityIdentifier[]) ids.toArray(new EntityIdentifier[0]);
    } catch (NamingException nex) {
        throw new GroupsException("LDAPGroupStore: Unable to perform filter " + query, nex);
    }
}
Also used : GroupsException(org.apereo.portal.groups.GroupsException) ArrayList(java.util.ArrayList) NamingEnumeration(javax.naming.NamingEnumeration) SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 39 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class PersonDirectorySearcher method searchForEntities.

@Override
public EntityIdentifier[] searchForEntities(String query, SearchMethod method) throws GroupsException {
    // Ignores CS / CI
    switch(method) {
        case DISCRETE:
        case DISCRETE_CI:
            {
                break;
            }
        case STARTS_WITH:
        case STARTS_WITH_CI:
            {
                query = query + IPersonAttributeDao.WILDCARD;
                break;
            }
        case ENDS_WITH:
        case ENDS_WITH_CI:
            {
                query = IPersonAttributeDao.WILDCARD + query;
                break;
            }
        case CONTAINS:
        case CONTAINS_CI:
            {
                query = IPersonAttributeDao.WILDCARD + query + IPersonAttributeDao.WILDCARD;
                break;
            }
        default:
            {
                throw new GroupsException("Unknown search type");
            }
    }
    log.debug("Searching for a person directory account matching query string " + query);
    final String usernameAttribute = this.usernameAttributeProvider.getUsernameAttribute();
    final Map<String, Object> queryMap = Collections.<String, Object>singletonMap(usernameAttribute, query);
    final Set<IPersonAttributes> results = this.personAttributeDao.getPeople(queryMap);
    // create an array of EntityIdentifiers from the search results
    final List<EntityIdentifier> entityIdentifiers = new ArrayList<EntityIdentifier>(results.size());
    for (final IPersonAttributes personAttributes : results) {
        entityIdentifiers.add(new EntityIdentifier(personAttributes.getName(), this.personEntityType));
    }
    return entityIdentifiers.toArray(new EntityIdentifier[entityIdentifiers.size()]);
}
Also used : IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) GroupsException(org.apereo.portal.groups.GroupsException) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 40 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class PagsService method createPagsDefinition.

/**
 * Verifies permissions and that the group doesn't already exist (case insensitive)
 */
public IPersonAttributesGroupDefinition createPagsDefinition(IPerson person, IEntityGroup parent, String groupName, String description) {
    // What's the target of the upcoming permissions check?
    String target = parent != null ? parent.getEntityIdentifier().getKey() : IPermission.ALL_GROUPS_TARGET;
    // Verify permission
    if (!hasPermission(person, IPermission.CREATE_GROUP_ACTIVITY, target)) {
        throw new RuntimeAuthorizationException(person, IPermission.CREATE_GROUP_ACTIVITY, target);
    }
    // VALIDATION STEP:  The group name & description are allowable
    if (StringUtils.isBlank(groupName)) {
        throw new IllegalArgumentException("Specified groupName is blank:  " + groupName);
    }
    if (!GROUP_NAME_VALIDATOR_PATTERN.matcher(groupName).matches()) {
        throw new IllegalArgumentException("Specified groupName is too long, too short, or contains invalid characters:  " + groupName);
    }
    if (!StringUtils.isBlank(description)) {
        // Blank description is allowable
        if (!GROUP_DESC_VALIDATOR_PATTERN.matcher(description).matches()) {
            throw new IllegalArgumentException("Specified description is too long or contains invalid characters:  " + description);
        }
    }
    // VALIDATION STEP:  We don't have a group by that name already
    EntityIdentifier[] people = GroupService.searchForGroups(groupName, IGroupConstants.SearchMethod.DISCRETE_CI, IPerson.class);
    EntityIdentifier[] portlets = GroupService.searchForGroups(groupName, IGroupConstants.SearchMethod.DISCRETE_CI, IPortletDefinition.class);
    if (people.length != 0 || portlets.length != 0) {
        throw new IllegalArgumentException("Specified groupName already in use:  " + groupName);
    }
    IPersonAttributesGroupDefinition rslt = pagsGroupDefDao.createPersonAttributesGroupDefinition(groupName, description);
    if (parent != null) {
        // Should refactor this switch to instead choose a service and invoke a method on it
        switch(parent.getServiceName().toString()) {
            case SERVICE_NAME_LOCAL:
                IEntityGroup member = GroupService.findGroup(rslt.getCompositeEntityIdentifierForGroup().getKey());
                if (member == null) {
                    String msg = "The specified group was created, but is not present in the store:  " + rslt.getName();
                    throw new RuntimeException(msg);
                }
                parent.addChild(member);
                parent.updateMembers();
                break;
            case SERVICE_NAME_PAGS:
                IPersonAttributesGroupDefinition parentDef = getPagsGroupDefByName(parent.getName());
                Set<IPersonAttributesGroupDefinition> members = new HashSet<>(parentDef.getMembers());
                members.add(rslt);
                parentDef.setMembers(members);
                pagsGroupDefDao.updatePersonAttributesGroupDefinition(parentDef);
                break;
            default:
                String msg = "The specified group service does not support adding members:  " + parent.getServiceName();
                throw new UnsupportedOperationException(msg);
        }
    }
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Aggregations

EntityIdentifier (org.apereo.portal.EntityIdentifier)93 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)31 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)24 IPerson (org.apereo.portal.security.IPerson)17 GroupsException (org.apereo.portal.groups.GroupsException)16 IEntityGroup (org.apereo.portal.groups.IEntityGroup)16 Set (java.util.Set)14 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)13 Iterator (java.util.Iterator)12 IGroupMember (org.apereo.portal.groups.IGroupMember)12 List (java.util.List)6 Element (net.sf.ehcache.Element)6 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)6 HashMap (java.util.HashMap)5 InvalidNameException (javax.naming.InvalidNameException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 GcFindGroups (edu.internet2.middleware.grouperClient.api.GcFindGroups)2