Search in sources :

Example 66 with EntityIdentifier

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

the class ApiGroupsService method getGroupsForMember.

// Internal search, thus case sensitive.
@Override
public Set<Entity> getGroupsForMember(String memberName) {
    Set<Entity> groups = new HashSet<Entity>();
    if (StringUtils.isNotEmpty(memberName)) {
        EntityIdentifier[] identifiers = GroupService.searchForEntities(memberName, GroupService.SearchMethod.DISCRETE, EntityEnum.PERSON.getClazz());
        for (EntityIdentifier entityIdentifier : identifiers) {
            if (entityIdentifier.getType().equals(EntityEnum.PERSON.getClazz())) {
                IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
                if (memberName.equalsIgnoreCase(groupMember.getKey())) {
                    Iterator it = GroupService.findParentGroups(groupMember);
                    while (it.hasNext()) {
                        IEntityGroup g = (IEntityGroup) it.next();
                        Entity e = EntityFactory.createEntity(g, EntityEnum.getEntityEnum(g.getLeafType(), true));
                        groups.add(e);
                    }
                    return groups;
                }
            }
        }
    }
    return groups;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) Iterator(java.util.Iterator) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 67 with EntityIdentifier

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

the class ApiGroupsService method getMembersForGroup.

@Override
public Set<Entity> getMembersForGroup(String groupName) {
    Set<Entity> members = new HashSet<Entity>();
    if (StringUtils.isNotEmpty(groupName)) {
        EntityIdentifier[] identifiers = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, EntityEnum.GROUP.getClazz());
        for (EntityIdentifier entityIdentifier : identifiers) {
            if (entityIdentifier.getType().equals(IEntityGroup.class)) {
                IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
                if (groupMember.getLeafType().equals(IPerson.class)) {
                    String groupMemberName = EntityService.instance().lookupEntityName(EntityEnum.GROUP, groupMember.getKey());
                    if (groupName.equalsIgnoreCase(groupMemberName)) {
                        for (IGroupMember gm : groupMember.asGroup().getDescendants()) {
                            if (!gm.isGroup()) {
                                EntityIdentifier ident = gm.getUnderlyingEntityIdentifier();
                                Entity member = findMember(ident.getKey(), true);
                                members.add(member);
                            }
                        }
                        return members;
                    }
                }
            }
        }
    }
    return members;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 68 with EntityIdentifier

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

the class EntityService method search.

// External search, thus case insensitive.
public Set<Entity> search(String entityType, String searchTerm) {
    if (StringUtils.isBlank(entityType) && StringUtils.isBlank(searchTerm)) {
        return null;
    }
    Set<Entity> results = new HashSet<Entity>();
    EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
    EntityIdentifier[] identifiers;
    Class<?> identifierType;
    // to locate it
    if (entityEnum.isGroup()) {
        identifiers = GroupService.searchForGroups(searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz());
        identifierType = IEntityGroup.class;
    } else // otherwise use the getGroupMember method
    {
        identifiers = GroupService.searchForEntities(searchTerm, GroupService.SearchMethod.CONTAINS_CI, entityEnum.getClazz());
        identifierType = entityEnum.getClazz();
    }
    for (EntityIdentifier entityIdentifier : identifiers) {
        if (entityIdentifier.getType().equals(identifierType)) {
            IGroupMember groupMember = GroupService.getGroupMember(entityIdentifier);
            Entity entity = getEntity(groupMember);
            results.add(entity);
        }
    }
    return results;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 69 with EntityIdentifier

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

the class ChannelListController method preparePortletCategoryBean.

private PortletCategoryBean preparePortletCategoryBean(WebRequest req, PortletCategory category, Set<IPortletDefinition> portletsNotYetCategorized, IPerson user, Locale locale) {
    /* Prepare child categories. */
    Set<PortletCategoryBean> subcategories = new HashSet<>();
    for (PortletCategory childCategory : this.portletCategoryRegistry.getChildCategories(category)) {
        PortletCategoryBean childBean = preparePortletCategoryBean(req, childCategory, portletsNotYetCategorized, user, locale);
        subcategories.add(childBean);
    }
    // add the direct child channels for this category
    Set<IPortletDefinition> portlets = portletCategoryRegistry.getChildPortlets(category);
    EntityIdentifier ei = user.getEntityIdentifier();
    IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    Set<PortletDefinitionBean> marketplacePortlets = new HashSet<>();
    for (IPortletDefinition portlet : portlets) {
        if (authorizationService.canPrincipalBrowse(ap, portlet)) {
            PortletDefinitionBean pdb = preparePortletDefinitionBean(req, portlet, locale);
            marketplacePortlets.add(pdb);
        }
        /*
             * Remove the portlet from the uncategorized collection;
             * note -- this approach will not prevent portlets from
             * appearing in multiple categories (as appropriate).
             */
        portletsNotYetCategorized.remove(portlet);
    }
    // construct a new portlet category bean for this category
    PortletCategoryBean categoryBean = PortletCategoryBean.fromPortletCategory(category, subcategories, marketplacePortlets);
    categoryBean.setName(messageSource.getMessage(category.getName(), new Object[] {}, locale));
    return categoryBean;
}
Also used : PortletCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 70 with EntityIdentifier

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

the class PermissionAdministrationHelper method canEditOwner.

public boolean canEditOwner(IPerson currentUser, String owner) {
    EntityIdentifier ei = currentUser.getEntityIdentifier();
    IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    return (ap.hasPermission(IPermission.PORTAL_PERMISSIONS, IPermission.EDIT_PERMISSIONS_ACTIVITY, IPermission.ALL_TARGET));
}
Also used : IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier)

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