Search in sources :

Example 31 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class EntityPersonAttributesGroupStore method contains.

@Override
public boolean contains(IEntityGroup group, IGroupMember member) {
    if (!IPERSON_CLASS.equals(member.getLeafType())) {
        // group.getLeafType() is (presumably) IPerson.class.
        return false;
    }
    if (member.isGroup()) {
        // PAGS groups may only contain other PAGS groups (and people, of course)
        final IEntityGroup ieg = (IEntityGroup) member;
        if (!PagsService.SERVICE_NAME_PAGS.equals(ieg.getServiceName().toString())) {
            return false;
        }
    }
    final MembershipCacheKey cacheKey = new MembershipCacheKey(group.getEntityIdentifier(), member.getUnderlyingEntityIdentifier());
    Element element = membershipCache.get(cacheKey);
    if (element == null) {
        logger.debug("Checking if group {} contains member {}/{}", group.getName(), member.getKey(), member.getLeafType().getSimpleName());
        // default
        boolean answer = false;
        final PagsGroup groupDef = convertEntityToGroupDef(group);
        if (member.isGroup()) {
            final String key = ((IEntityGroup) member).getLocalKey();
            answer = groupDef.hasMember(key);
        } else {
            try {
                final IPersonAttributeDao pa = PersonAttributeDaoLocator.getPersonAttributeDao();
                final IPersonAttributes personAttributes = pa.getPerson(member.getKey());
                if (personAttributes != null) {
                    final RestrictedPerson rp = PersonFactory.createRestrictedPerson();
                    rp.setAttributes(personAttributes.getAttributes());
                    answer = groupDef.contains(rp);
                }
            } catch (Exception ex) {
                logger.error("Exception acquiring attributes for member " + member + " while checking if group " + group + " contains this member.", ex);
                return false;
            }
        }
        element = new Element(cacheKey, answer);
        membershipCache.put(element);
    }
    return (Boolean) element.getObjectValue();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) PagsGroup(org.apereo.portal.groups.pags.PagsGroup) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) IPersonAttributeDao(org.jasig.services.persondir.IPersonAttributeDao) Element(net.sf.ehcache.Element) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) GroupsException(org.apereo.portal.groups.GroupsException)

Example 32 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class DirectoryPortletController method searchDirectory.

/**
     * Search the directory for people matching the search query. Search results will be scoped to
     * the permissions of the user performing the search.
     *
     * @param query
     * @param request
     * @return
     */
protected List<IPersonAttributes> searchDirectory(String query, PortletRequest request) {
    final Map<String, Object> queryAttributes = new HashMap<String, Object>();
    for (String attr : directoryQueryAttributes) {
        queryAttributes.put(attr, query);
    }
    final List<IPersonAttributes> people;
    // get an authorization principal for the current requesting user
    HttpServletRequest servletRequest = portalRequestUtils.getPortletHttpRequest(request);
    IPerson currentUser = personManager.getPerson(servletRequest);
    // get the set of people matching the search query
    people = this.lookupHelper.searchForPeople(currentUser, queryAttributes);
    return people;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) HashMap(java.util.HashMap)

Example 33 with IPersonAttributes

use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.

the class DirectoryPortletController method findPersonByUsername.

@RenderMapping(params = "action=findByUsername")
public ModelAndView findPersonByUsername(RenderRequest request, @RequestParam String username) {
    // get an authorization principal for the current requesting user
    HttpServletRequest servletRequest = portalRequestUtils.getPortletHttpRequest(request);
    IPerson currentUser = personManager.getPerson(servletRequest);
    // get the set of people matching the search query
    final IPersonAttributes person = this.lookupHelper.findPerson(currentUser, username);
    final boolean isMobile = isMobile(request);
    String viewName = isMobile ? "/jsp/Directory/mobileDirectory" : "/jsp/Directory/directory";
    final Map<String, Object> model = new HashMap<String, Object>();
    model.put("query", username);
    model.put("people", Collections.singletonList(person));
    model.put("attributeNames", this.displayAttributes);
    return new ModelAndView(viewName, model);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.portlet.ModelAndView) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Aggregations

IPersonAttributes (org.jasig.services.persondir.IPersonAttributes)33 List (java.util.List)12 IPerson (org.apereo.portal.security.IPerson)12 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)8 LinkedHashSet (java.util.LinkedHashSet)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Principal (java.security.Principal)4 Map (java.util.Map)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 PortletRequest (javax.portlet.PortletRequest)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2 PortletPreferences (javax.portlet.PortletPreferences)2 Element (net.sf.ehcache.Element)2 GroupsException (org.apereo.portal.groups.GroupsException)2 IEntityGroup (org.apereo.portal.groups.IEntityGroup)2 Attribute (org.apereo.portal.portlets.Attribute)2