Search in sources :

Example 41 with IPortletDefinition

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

the class PortletEntityRegistryImpl method parseConsistentPortletEntityId.

protected IPortletEntityId parseConsistentPortletEntityId(HttpServletRequest request, String consistentEntityIdString) {
    Validate.notNull(consistentEntityIdString, "consistentEntityIdString can not be null");
    // Check in the cache first
    final Element element = this.entityIdParseCache.get(consistentEntityIdString);
    if (element != null) {
        final Object value = element.getObjectValue();
        if (value != null) {
            return (IPortletEntityId) value;
        }
    }
    if (!PortletEntityIdStringUtils.hasCorrectNumberOfParts(consistentEntityIdString)) {
        throw new IllegalArgumentException("consistentEntityIdString does not have 3 parts and is invalid: " + consistentEntityIdString);
    }
    // Verify the portlet definition id
    final String portletDefinitionIdString = PortletEntityIdStringUtils.parsePortletDefinitionId(consistentEntityIdString);
    final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionIdString);
    if (portletDefinition == null) {
        throw new IllegalArgumentException("No parent IPortletDefinition found for " + portletDefinitionIdString + " from entity id string: " + consistentEntityIdString);
    }
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    // Verify non-delegate layout node id exists and is for a portlet
    final String layoutNodeId = PortletEntityIdStringUtils.parseLayoutNodeId(consistentEntityIdString);
    if (!PortletEntityIdStringUtils.isDelegateLayoutNode(layoutNodeId)) {
        final IUserLayoutNodeDescription node = userLayoutManager.getNode(layoutNodeId);
        if (node == null || node.getType() != LayoutNodeType.PORTLET) {
            throw new IllegalArgumentException("No portlet layout node found for " + layoutNodeId + " from entity id string: " + consistentEntityIdString);
        }
        // TODO is this doable for delegation?
        // Verify the portlet definition matches
        final IUserLayoutChannelDescription portletNode = (IUserLayoutChannelDescription) node;
        final String channelPublishId = portletNode.getChannelPublishId();
        if (!portletDefinitionId.getStringId().equals(channelPublishId)) {
            throw new IllegalArgumentException("The portlet layout node found for " + layoutNodeId + " does not match the IPortletDefinitionId " + portletDefinitionId + " specified in entity id string: " + consistentEntityIdString);
        }
    }
    // TODO when there is a JPA backed user dao actually verify this mapping
    // User just conver to an int
    final int userId;
    final String userIdAsString = PortletEntityIdStringUtils.parseUserIdAsString(consistentEntityIdString);
    try {
        userId = Integer.parseInt(userIdAsString);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The user id " + userIdAsString + " is not a valid integer from entity id string: " + consistentEntityIdString, e);
    }
    final IPortletEntityId portletEntityId = createConsistentPortletEntityId(portletDefinitionId, layoutNodeId, userId);
    // Cache the resolution
    this.entityIdParseCache.put(new Element(consistentEntityIdString, portletEntityId));
    return portletEntityId;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(net.sf.ehcache.Element) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IUserInstance(org.apereo.portal.user.IUserInstance) 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)

Example 42 with IPortletDefinition

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

the class PortletEntityRegistryImpl method getOrCreatePortletEntity.

@Override
public IPortletEntity getOrCreatePortletEntity(HttpServletRequest request, IUserInstance userInstance, String layoutNodeId) {
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    // Find the channel and portlet definitions
    final IUserLayoutChannelDescription channelNode = (IUserLayoutChannelDescription) userLayoutManager.getNode(layoutNodeId);
    if (channelNode == null) {
        this.logger.warn("No layout node exists for id " + layoutNodeId + ", no portlet entity will be returned.");
        return null;
    }
    final String channelPublishId = channelNode.getChannelPublishId();
    final IPortletDefinition portletDefinition = this.getPortletDefinition(request, userInstance, channelPublishId);
    if (portletDefinition != null) {
        final IPerson person = userInstance.getPerson();
        return this.getOrCreatePortletEntity(request, portletDefinition.getPortletDefinitionId(), layoutNodeId, person.getID());
    }
    // No permission to see the portlet
    return null;
}
Also used : IPerson(org.apereo.portal.security.IPerson) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 43 with IPortletDefinition

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

the class PortletWindowRegistryImpl method getOrCreateStatelessPortletWindow.

@Override
public IPortletWindow getOrCreateStatelessPortletWindow(HttpServletRequest request, IPortletWindowId basePortletWindowId) {
    // extract the entity ID
    if (!(basePortletWindowId instanceof PortletWindowIdImpl)) {
        final String basePortletWindowIdStr = basePortletWindowId.getStringId();
        basePortletWindowId = this.getPortletWindowId(request, basePortletWindowIdStr);
    }
    // Get the entity ID for the portlet window
    final IPortletEntityId portletEntityId = ((PortletWindowIdImpl) basePortletWindowId).getPortletEntityId();
    // Create the stateless ID
    final PortletWindowIdImpl statelessPortletWindowId = this.createPortletWindowId(STATELESS_PORTLET_WINDOW_ID, portletEntityId);
    // See if there is already a request cached stateless window
    IPortletWindow statelessPortletWindow = this.getPortletWindow(request, statelessPortletWindowId);
    if (statelessPortletWindow != null) {
        return statelessPortletWindow;
    }
    // Lookup the base portlet window to clone the stateless from
    final IPortletWindow basePortletWindow = this.getPortletWindow(request, basePortletWindowId);
    final PortletWindowCache<PortletWindowData> statelessPortletWindowDataMap = this.getStatelessPortletWindowDataMap(request, true);
    // If no base to clone from lookup the entity and pluto definition data
    if (basePortletWindow == null) {
        final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
        if (portletEntity == null) {
            throw new IllegalArgumentException("No IPortletEntity could be found for " + portletEntity + " while creating stateless portlet window for " + basePortletWindowId);
        }
        final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
        final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
        final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
        final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
        statelessPortletWindowDataMap.storeWindow(portletWindowData);
        statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    } else // Clone the existing base window
    {
        final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
        portletWindowData.setExpirationCache(basePortletWindow.getExpirationCache());
        portletWindowData.setPortletMode(basePortletWindow.getPortletMode());
        portletWindowData.setWindowState(basePortletWindow.getWindowState());
        portletWindowData.setPublicRenderParameters(basePortletWindow.getPublicRenderParameters());
        portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters());
        statelessPortletWindowDataMap.storeWindow(portletWindowData);
        final IPortletEntity portletEntity = basePortletWindow.getPortletEntity();
        final PortletDefinition portletDescriptor = basePortletWindow.getPlutoPortletWindow().getPortletDefinition();
        statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    }
    // Cache the stateless window in the request
    final PortletWindowCache<IPortletWindow> portletWindowMap = this.getPortletWindowMap(request);
    portletWindowMap.storeWindow(statelessPortletWindow);
    return statelessPortletWindow;
}
Also used : IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 44 with IPortletDefinition

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

the class AuthorizationImpl method canPrincipalConfigure.

@Override
@RequestCache
public boolean canPrincipalConfigure(IAuthorizationPrincipal principal, String portletDefinitionId) throws AuthorizationException {
    String owner = IPermission.PORTAL_PUBLISH;
    String target = IPermission.PORTLET_PREFIX + portletDefinitionId;
    // retrieve the indicated channel from the channel registry store and
    // determine its current lifecycle state
    IPortletDefinition portlet = this.portletDefinitionRegistry.getPortletDefinition(portletDefinitionId);
    if (portlet == null) {
        throw new AuthorizationException("Unable to locate portlet " + portletDefinitionId);
    }
    final String activity = IPermission.PORTLET_MODE_CONFIG;
    boolean isAllowed = doesPrincipalHavePermission(principal, owner, activity, target);
    logger.trace("In canPrincipalConfigure() - principal.key=[{}], is allowed?=[{}]", principal.getKey(), isAllowed);
    return isAllowed;
}
Also used : AuthorizationException(org.apereo.portal.AuthorizationException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestCache(org.apereo.portal.concurrency.caching.RequestCache)

Example 45 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) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) HashSet(java.util.HashSet) Async(org.springframework.scheduling.annotation.Async)

Aggregations

IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)109 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)24 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)22 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)17 ArrayList (java.util.ArrayList)16 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)11 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)9 HashMap (java.util.HashMap)8 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)7 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)7 IUserInstance (org.apereo.portal.user.IUserInstance)7 Locale (java.util.Locale)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)6