Search in sources :

Example 26 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class XalanAuthorizationHelperBean method canRender.

/* (non-Javadoc)
     * @see org.apereo.portal.security.xslt.IAuthorizationHelper#canRender(java.lang.String, java.lang.String)
     */
@Override
public boolean canRender(final String userName, final String fname) {
    if (userName == null || fname == null) {
        return false;
    }
    final IAuthorizationPrincipal userPrincipal = this.getUserPrincipal(userName);
    if (userPrincipal == null) {
        return false;
    }
    final String portletId;
    try {
        final IPortletDefinition portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fname);
        if (portletDefinition == null) {
            if (this.logger.isInfoEnabled()) {
                this.logger.info("No PortletDefinition for fname='" + fname + "', returning false.");
            }
            return false;
        }
        portletId = portletDefinition.getPortletDefinitionId().getStringId();
    } catch (Exception e) {
        this.logger.warn("Could not find PortletDefinition for fname='" + fname + "' while checking if user '" + userName + "' can render it. Returning FALSE.", e);
        return false;
    }
    return userPrincipal.canRender(portletId);
}
Also used : IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 27 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class XalanGroupMembershipHelperBean method isChannelDeepMemberOf.

/* (non-Javadoc)
     * @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isChannelDeepMemberOf(java.lang.String, java.lang.String)
     */
@Override
public boolean isChannelDeepMemberOf(String fname, String groupKey) {
    final IEntityGroup distinguishedGroup = GroupService.findGroup(groupKey);
    if (distinguishedGroup == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No group found for key '" + groupKey + "'");
        }
        return false;
    }
    final IPortletDefinition portletDefinition;
    try {
        portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fname);
    } catch (Exception e) {
        this.logger.warn("Caught exception while retrieving portlet definition for fname '" + fname + "'", e);
        return false;
    }
    if (portletDefinition == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No portlet found for key '" + fname + "'");
        }
        return false;
    }
    final String portletId = portletDefinition.getPortletDefinitionId().getStringId();
    final IEntity entity = GroupService.getEntity(portletId, IPortletDefinition.class);
    if (entity == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No portlet found for id '" + portletId + "'");
        }
        return false;
    }
    return distinguishedGroup.deepContains(entity);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IEntity(org.apereo.portal.groups.IEntity) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 28 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletExecutionManager method getPortletEventTimeout.

protected long getPortletEventTimeout(IPortletWindowId portletWindowId, HttpServletRequest request) {
    if (this.ignoreTimeouts) {
        return DEBUG_TIMEOUT;
    }
    final IPortletDefinition portletDefinition = getPortletDefinition(portletWindowId, request);
    final Integer eventTimeout = portletDefinition.getEventTimeout();
    if (eventTimeout != null) {
        return getModifiedTimeout(portletDefinition, request, eventTimeout);
    }
    return getModifiedTimeout(portletDefinition, request, portletDefinition.getTimeout());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 29 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class PortletExecutionManager method doPortletAction.

/* (non-Javadoc)
     * @see org.apereo.portal.portlet.rendering.IPortletExecutionManager#doPortletAction(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public void doPortletAction(IPortletWindowId portletWindowId, HttpServletRequest request, HttpServletResponse response) {
    final long timeout = getPortletActionTimeout(portletWindowId, request);
    final IPortletExecutionWorker<Long> portletActionExecutionWorker = this.portletWorkerFactory.createActionWorker(request, response, portletWindowId);
    portletActionExecutionWorker.submit();
    try {
        portletActionExecutionWorker.get(timeout);
    } catch (Exception e) {
        // put the exception into the error map for the session
        final Map<IPortletWindowId, Exception> portletFailureMap = getPortletErrorMap(request);
        portletFailureMap.put(portletWindowId, e);
    }
    //If the worker is still running add it to the hung-workers queue
    if (!portletActionExecutionWorker.isComplete()) {
        cancelWorker(request, portletActionExecutionWorker);
    }
    // Is this portlet permitted to emit events?  (Or is it disablePortletEvents=true?)
    final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(request, portletWindowId);
    IPortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition();
    IPortletDefinitionParameter disablePortletEvents = portletDefinition.getParameter(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());
    } else {
        // Proceed with events...
        final PortletEventQueue portletEventQueue = this.eventCoordinationService.getPortletEventQueue(request);
        this.doPortletEvents(portletEventQueue, request, response);
    }
}
Also used : IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) IOException(java.io.IOException) MaintenanceModeException(org.apereo.portal.portlets.error.MaintenanceModeException) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 30 with IPortletDefinition

use of org.apereo.portal.portlet.om.IPortletDefinition in project uPortal by Jasig.

the class MarketplaceService method loadMarketplaceEntriesFor.

/**
     * Load the list of marketplace entries for a user. Will load entries async. This method is
     * primarily intended for seeding data. Most impls should call browseableMarketplaceEntriesFor()
     * instead.
     *
     * <p>Note: Set is immutable since it is potentially shared between threads. If the set needs
     * mutability, be sure to consider the thread safety implications. No protections have been
     * provided against modifying the MarketplaceEntry itself, so be careful when modifying the
     * entities contained in the list.
     *
     * @param user The non-null user
     * @param categories Restricts the output to entries within the specified categories if
     *     non-empty
     * @return a Future that will resolve to a set of MarketplaceEntry objects the requested user
     *     has browse access to.
     * @throws java.lang.IllegalArgumentException if user is null
     * @since 4.2
     */
@Async
public Future<ImmutableSet<MarketplaceEntry>> loadMarketplaceEntriesFor(final IPerson user, final Set<PortletCategory> categories) {
    final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
    List<IPortletDefinition> allDisplayablePortletDefinitions = this.portletDefinitionRegistry.getAllPortletDefinitions();
    if (!categories.isEmpty()) {
        // Indicates we plan to restrict portlets displayed in the Portlet
        // Marketplace to those that belong to one or more specified groups.
        Element portletDefinitionsElement = marketplaceCategoryCache.get(categories);
        if (portletDefinitionsElement == null) {
            /*
                 * Collection not in cache -- need to recreate it
                 */
            // Gather the complete collection of allowable categories (specified categories & their descendants)
            final Set<PortletCategory> allSpecifiedAndDecendantCategories = new HashSet<>();
            for (PortletCategory pc : categories) {
                collectSpecifiedAndDescendantCategories(pc, allSpecifiedAndDecendantCategories);
            }
            // Filter portlets that match the criteria
            Set<IPortletDefinition> filteredPortletDefinitions = new HashSet<>();
            for (final IPortletDefinition portletDefinition : allDisplayablePortletDefinitions) {
                final Set<PortletCategory> parents = portletCategoryRegistry.getParentCategories(portletDefinition);
                for (final PortletCategory parent : parents) {
                    if (allSpecifiedAndDecendantCategories.contains(parent)) {
                        filteredPortletDefinitions.add(portletDefinition);
                        break;
                    }
                }
            }
            portletDefinitionsElement = new Element(categories, new ArrayList<>(filteredPortletDefinitions));
            marketplaceCategoryCache.put(portletDefinitionsElement);
        }
        allDisplayablePortletDefinitions = (List<IPortletDefinition>) portletDefinitionsElement.getObjectValue();
    }
    final Set<MarketplaceEntry> visiblePortletDefinitions = new HashSet<>();
    for (final IPortletDefinition portletDefinition : allDisplayablePortletDefinitions) {
        if (mayBrowsePortlet(principal, portletDefinition)) {
            final MarketplacePortletDefinition marketplacePortletDefinition = getOrCreateMarketplacePortletDefinition(portletDefinition);
            final MarketplaceEntry entry = new MarketplaceEntry(marketplacePortletDefinition, user);
            // flag whether this use can add the portlet...
            boolean canAdd = mayAddPortlet(user, portletDefinition);
            entry.setCanAdd(canAdd);
            visiblePortletDefinitions.add(entry);
        }
    }
    logger.trace("These portlet definitions {} are browseable by {}.", visiblePortletDefinitions, user);
    Future<ImmutableSet<MarketplaceEntry>> result = new AsyncResult<>(ImmutableSet.copyOf(visiblePortletDefinitions));
    Element cacheElement = new Element(user.getUserName(), result);
    marketplaceUserPortletDefinitionCache.put(cacheElement);
    return result;
}
Also used : Element(net.sf.ehcache.Element) ArrayList(java.util.ArrayList) MarketplaceEntry(org.apereo.portal.rest.layout.MarketplaceEntry) ImmutableSet(com.google.common.collect.ImmutableSet) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) Async(org.springframework.scheduling.annotation.Async)

Aggregations

IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)103 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)24 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)23 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)17 ArrayList (java.util.ArrayList)14 IPortletDefinitionId (org.apereo.portal.portlet.om.IPortletDefinitionId)14 HashSet (java.util.HashSet)13 IPerson (org.apereo.portal.security.IPerson)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)10 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)9 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)9 HashMap (java.util.HashMap)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 IUserInstance (org.apereo.portal.user.IUserInstance)7 Locale (java.util.Locale)6 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)6 PortalException (org.apereo.portal.PortalException)6 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)6