Search in sources :

Example 76 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 */
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.IS, 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 77 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 AuthorizationService authService = AuthorizationService.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) AuthorizationService(org.apereo.portal.services.AuthorizationService) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 78 with EntityIdentifier

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

the class XalanGroupMembershipHelperBean method isUserDeepMemberOfGroupName.

/* (non-Javadoc)
     * @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isUserDeepMemberOfGroupName(java.lang.String, java.lang.String)
     */
@Override
public boolean isUserDeepMemberOfGroupName(String userName, String groupName) {
    final EntityIdentifier[] results = GroupService.searchForGroups(groupName, GroupService.IS, IPerson.class);
    if (results == null || results.length == 0) {
        return false;
    }
    if (results.length > 1) {
        this.logger.warn(results.length + " groups were found for '" + groupName + "'. The first result will be used.");
    }
    final IGroupMember group = GroupService.getGroupMember(results[0]);
    final IEntity entity = GroupService.getEntity(userName, IPerson.class);
    if (entity == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No user found for key '" + userName + "'");
        }
        return false;
    }
    return group.asGroup().deepContains(entity);
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) IEntity(org.apereo.portal.groups.IEntity) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 79 with EntityIdentifier

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

the class PortletEventCoordinatationService method resolvePortletEvents.

@Override
public void resolvePortletEvents(HttpServletRequest request, PortletEventQueue portletEventQueue) {
    final Queue<QueuedEvent> events = portletEventQueue.getUnresolvedEvents();
    //Skip all processing if there are no new events.
    if (events.isEmpty()) {
        return;
    }
    //Get all the portlets the user is subscribed to
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    //Make a local copy so we can remove data from it
    final Set<String> allLayoutNodeIds = new LinkedHashSet<String>(userLayoutManager.getAllSubscribedChannels());
    final Map<String, IPortletEntity> portletEntityCache = new LinkedHashMap<String, IPortletEntity>();
    while (!events.isEmpty()) {
        final QueuedEvent queuedEvent = events.poll();
        if (queuedEvent == null) {
            //no more queued events, done resolving
            return;
        }
        final IPortletWindowId sourceWindowId = queuedEvent.getPortletWindowId();
        final Event event = queuedEvent.getEvent();
        final boolean globalEvent = isGlobalEvent(request, sourceWindowId, event);
        final Set<IPortletDefinition> portletDefinitions = new LinkedHashSet<IPortletDefinition>();
        if (globalEvent) {
            portletDefinitions.addAll(this.portletDefinitionRegistry.getAllPortletDefinitions());
        }
        //Check each subscription to see what events it is registered to see
        for (final Iterator<String> layoutNodeIdItr = allLayoutNodeIds.iterator(); layoutNodeIdItr.hasNext(); ) {
            final String layoutNodeId = layoutNodeIdItr.next();
            IPortletEntity portletEntity = portletEntityCache.get(layoutNodeId);
            if (portletEntity == null) {
                portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, layoutNodeId);
                // if portlet entity registry returned null, then portlet has been deleted - remove it (see UP-3378)
                if (portletEntity == null) {
                    layoutNodeIdItr.remove();
                    continue;
                }
                final IPortletDefinitionId portletDefinitionId = portletEntity.getPortletDefinitionId();
                final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
                if (portletDescriptor == null) {
                    //Missconfigured portlet, remove it from the list so we don't check again and ignore it
                    layoutNodeIdItr.remove();
                    continue;
                }
                final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor.getSupportedProcessingEvents();
                //Skip portlets that don't handle any events and remove them from the set so they are not checked again
                if (supportedProcessingEvents == null || supportedProcessingEvents.size() == 0) {
                    layoutNodeIdItr.remove();
                    continue;
                }
                portletEntityCache.put(layoutNodeId, portletEntity);
            }
            final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
            final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
            if (this.supportsEvent(event, portletDefinitionId)) {
                this.logger.debug("{} supports event {}", portletDefinition, event);
                //If this is the default portlet entity remove the definition from the all defs set to avoid duplicate processing
                final IPortletEntity defaultPortletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
                if (defaultPortletEntity.equals(portletEntity)) {
                    portletDefinitions.remove(portletDefinition);
                }
                // Is this portlet permitted to receive events?  (Or is it disablePortletEvents=true?)
                IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
                if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
                    logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
                    continue;
                }
                final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
                final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
                for (final IPortletWindow portletWindow : portletWindows) {
                    this.logger.debug("{} resolved target {}", event, portletWindow);
                    final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                    final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
                    portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
                }
            } else {
                portletDefinitions.remove(portletDefinition);
            }
        }
        if (!portletDefinitions.isEmpty()) {
            final IPerson user = userInstance.getPerson();
            final EntityIdentifier ei = user.getEntityIdentifier();
            final IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
            //If the event is global there might still be portlet definitions that need targeting
            for (final IPortletDefinition portletDefinition : portletDefinitions) {
                // Is this portlet permitted to receive events?  (Or is it disablePortletEvents=true?)
                IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(PortletExecutionManager.DISABLE_PORTLET_EVENTS_PARAMETER);
                if (disablePortletEvents != null && Boolean.parseBoolean(disablePortletEvents.getValue())) {
                    logger.info("Ignoring portlet events for portlet '{}' because they have been disabled.", portletDefinition.getFName());
                    continue;
                }
                final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
                //Check if the user can render the portlet definition before doing event tests
                if (ap.canRender(portletDefinitionId.getStringId())) {
                    if (this.supportsEvent(event, portletDefinitionId)) {
                        this.logger.debug("{} supports event {}", portletDefinition, event);
                        final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreateDefaultPortletEntity(request, portletDefinitionId);
                        final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
                        final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllPortletWindowsForEntity(request, portletEntityId);
                        for (final IPortletWindow portletWindow : portletWindows) {
                            this.logger.debug("{} resolved target {}", event, portletWindow);
                            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
                            final Event unmarshalledEvent = this.unmarshall(portletWindow, event);
                            portletEventQueue.offerEvent(portletWindowId, new QueuedEvent(sourceWindowId, unmarshalledEvent));
                        }
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EntityIdentifier(org.apereo.portal.EntityIdentifier) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) LinkedHashMap(java.util.LinkedHashMap) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) Event(javax.portlet.Event) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Aggregations

EntityIdentifier (org.apereo.portal.EntityIdentifier)79 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)31 HashSet (java.util.HashSet)20 IPerson (org.apereo.portal.security.IPerson)17 ArrayList (java.util.ArrayList)15 IEntityGroup (org.apereo.portal.groups.IEntityGroup)13 IGroupMember (org.apereo.portal.groups.IGroupMember)12 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)12 Set (java.util.Set)9 GroupsException (org.apereo.portal.groups.GroupsException)9 Iterator (java.util.Iterator)7 Element (net.sf.ehcache.Element)6 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)6 HashMap (java.util.HashMap)4 List (java.util.List)4 LinkedHashSet (java.util.LinkedHashSet)3 LinkedList (java.util.LinkedList)2 Locale (java.util.Locale)2 Map (java.util.Map)2 SortedSet (java.util.SortedSet)2