Search in sources :

Example 86 with EntityIdentifier

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

the class GetMemberServicePhrase method getPhrase.

// Internal search, thus case sensitive.
public static String getPhrase(String name, String memberValue) {
    String rslt = null;
    // We can (and must) cut & run if the element is a <literal> or a <channel>...
    if (name.equals("literal") || name.equals("channel")) {
        return "local";
    }
    try {
        Class[] leafTypes = new Class[] { IPerson.class, IPortletDefinition.class };
        for (int i = 0; i < leafTypes.length && rslt == null; i++) {
            EntityIdentifier[] eis = GroupService.searchForGroups(memberValue, IGroupConstants.SearchMethod.DISCRETE, leafTypes[i]);
            if (eis.length == 1) {
                // Match!
                if (eis[0].getType() == IEntityGroup.class) {
                    IEntityGroup g = GroupService.findGroup(eis[0].getKey());
                    rslt = g.getServiceName().toString();
                } else {
                    String msg = "The specified entity is not a group:  " + memberValue;
                    throw new RuntimeException(msg);
                }
                break;
            } else if (eis.length > 1) {
                String msg = "Ambiguous member name:  " + memberValue;
                throw new RuntimeException(msg);
            }
        }
    } catch (Throwable t) {
        String msg = "Error looking up the specified member:  " + memberValue;
        throw new RuntimeException(msg, t);
    }
    if (rslt == null) {
        String msg = "The specified member was not found:  " + memberValue;
        throw new RuntimeException(msg);
    }
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IPerson(org.apereo.portal.security.IPerson) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 87 with EntityIdentifier

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

the class GroupKeyOrLiteralPhrase method evaluate.

// Internal search, thus case sensitive.
@Override
public Object evaluate(TaskRequest req, TaskResponse res) {
    String rslt = null;
    Element e = (Element) element.evaluate(req, res);
    if (e.getName().equals("group")) {
        // This is a group name, we need to look up the key...
        try {
            Class[] types = new Class[] { IPerson.class, IPortletDefinition.class };
            for (Class c : types) {
                EntityIdentifier[] eis = GroupService.searchForGroups(e.getText(), IGroupConstants.SearchMethod.DISCRETE, c);
                switch(eis.length) {
                    case 1:
                        // This is good -- what we hope for...
                        rslt = GroupService.findGroup(eis[0].getKey()).getKey();
                        break;
                    case 0:
                        // This is ok -- try the next type...
                        continue;
                    default:
                        String msg2 = "Ambiguous group name:  " + e.getText();
                        throw new RuntimeException(msg2);
                }
            }
            // We better have a match by now...
            if (rslt == null) {
                String msg = "No group with the specified name was found:  " + e.getText();
                throw new RuntimeException(msg);
            }
        } catch (Throwable t) {
            String msg = "Error looking up the specified group:  " + e.getText();
            throw new RuntimeException(msg, t);
        }
    } else if (e.getName().equals("literal")) {
        rslt = e.getText();
    } else {
        String msg = "Unsupported element type:  " + e.getName();
        throw new RuntimeException(msg);
    }
    return rslt;
}
Also used : IPerson(org.apereo.portal.security.IPerson) Element(org.dom4j.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 88 with EntityIdentifier

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

the class PortletDefinitionImporterExporter method importData.

@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
    final IPortletDefinition def = portletDefinitionUnmarshaller.unmarshall(portletRep);
    final List<PortletCategory> categories = new ArrayList<>();
    for (String categoryName : portletRep.getCategories()) {
        // Import/Export function, thus the group search is case sensitive.
        EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.SearchMethod.DISCRETE, IPortletDefinition.class);
        PortletCategory category;
        if (cats != null && cats.length > 0) {
            category = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
        } else {
            category = portletCategoryRegistry.getPortletCategory(categoryName);
        }
        if (category == null) {
            throw new IllegalArgumentException("No category '" + categoryName + "' found when importing portlet: " + portletRep.getFname());
        }
        categories.add(category);
    }
    final String fname = portletRep.getFname();
    final Map<ExternalPermissionDefinition, Set<IGroupMember>> permissions = new HashMap<>();
    final Set<IGroupMember> subscribeMembers = toGroupMembers(portletRep.getGroups(), fname);
    permissions.put(ExternalPermissionDefinition.SUBSCRIBE, subscribeMembers);
    if (portletRep.getPermissions() != null && portletRep.getPermissions().getPermissions() != null) {
        for (ExternalPermissionMemberList perm : portletRep.getPermissions().getPermissions()) {
            Set<IGroupMember> members = toGroupMembers(perm.getGroups(), fname);
            ExternalPermissionDefinition permDef = toExternalPermissionDefinition(perm.getSystem(), perm.getActivity());
            if (permissions.containsKey(permDef)) {
                permissions.get(permDef).addAll(members);
            } else {
                permissions.put(permDef, members);
            }
        }
    }
    savePortletDefinition(def, categories, permissions);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier) IGroupMember(org.apereo.portal.groups.IGroupMember) ExternalPermissionDefinition(org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) Transactional(org.springframework.transaction.annotation.Transactional)

Example 89 with EntityIdentifier

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

the class GoogleAnalyticsController method isMember.

/**
 * Check if the user is a member of the specified group name
 *
 * <p>Internal search, thus case sensitive.
 */
private boolean isMember(IGroupMember groupMember, String groupName) {
    try {
        IEntityGroup group = GroupService.findGroup(groupName);
        if (group != null) {
            return groupMember.isDeepMemberOf(group);
        }
        final EntityIdentifier[] results = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, IPerson.class);
        if (results == null || results.length == 0) {
            this.logger.warn("No portal group found for '{}' no users will be placed in that group for analytics", groupName);
            return false;
        }
        if (results.length > 1) {
            this.logger.warn("{} groups were found for groupName '{}'. The first result will be used.", results.length, groupName);
        }
        group = (IEntityGroup) GroupService.getGroupMember(results[0]);
        return groupMember.isDeepMemberOf(group);
    } catch (Exception e) {
        this.logger.warn("Failed to determine if {} is a member of {}, returning false", groupMember, groupName, e);
        return false;
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) EntityIdentifier(org.apereo.portal.EntityIdentifier) IOException(java.io.IOException)

Example 90 with EntityIdentifier

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

the class PopularPortletsController method buildEventCounts.

private List<PortletUsage> buildEventCounts(Integer days, IPerson user, Locale locale) {
    final DateTime end = new DateTime();
    final DateTime begin = end.minusDays(days);
    final IEntityGroup everyone = GroupService.getRootGroup(IPerson.class);
    final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping(everyone.getKey());
    final List<PortletLayoutAggregation> aggregations = portletLayoutDao.getAggregationsForAllPortlets(begin, end, AGGREGATION_INTERVAL, group);
    final EntityIdentifier ei = user.getEntityIdentifier();
    final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
    final IAuthorizationPrincipal ap = authService.newPrincipal(ei.getKey(), ei.getType());
    final Map<String, PortletUsage> resultBuilder = new HashMap<String, PortletUsage>();
    for (final PortletLayoutAggregation aggregation : aggregations) {
        final AggregatedPortletMapping portlet = aggregation.getPortletMapping();
        final String fname = portlet.getFname();
        PortletUsage portletUsage = resultBuilder.get(fname);
        if (portletUsage == null) {
            final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinitionByFname(fname);
            if (portletDefinition == null || !ap.canSubscribe(portletDefinition.getPortletDefinitionId().getStringId())) {
                // Skip portlets that no longer exist or cannot be subscribed to
                continue;
            }
            portletUsage = new PortletUsage(portletDefinition.getPortletDefinitionId().getLongId(), fname, portletDefinition.getTitle(locale.toString()), portletDefinition.getDescription(locale.toString()));
            resultBuilder.put(fname, portletUsage);
        }
        portletUsage.incrementCount(aggregation.getAddCount());
    }
    final ArrayList<PortletUsage> results = new ArrayList<PortletUsage>(resultBuilder.values());
    Collections.sort(results);
    return results;
}
Also used : HashMap(java.util.HashMap) PortletLayoutAggregation(org.apereo.portal.events.aggr.portletlayout.PortletLayoutAggregation) AggregatedPortletMapping(org.apereo.portal.events.aggr.portlets.AggregatedPortletMapping) ArrayList(java.util.ArrayList) EntityIdentifier(org.apereo.portal.EntityIdentifier) DateTime(org.joda.time.DateTime) IEntityGroup(org.apereo.portal.groups.IEntityGroup) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) AuthorizationServiceFacade(org.apereo.portal.services.AuthorizationServiceFacade) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

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