Search in sources :

Example 6 with PortletCategory

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

the class MarketplaceEntry method getPortletCategories.

private Set<String> getPortletCategories(MarketplacePortletDefinition pdef) {
    Set<PortletCategory> categories = pdef.getCategories();
    Set<String> rslt = new HashSet<String>();
    for (PortletCategory category : categories) {
        String lowerCase = category.getName().toLowerCase();
        if (!"all categories".equals(lowerCase)) {
            rslt.add(StringUtils.capitalize(category.getName().toLowerCase()));
        }
    }
    return rslt;
}
Also used : PortletCategory(org.apereo.portal.portlet.om.PortletCategory) HashSet(java.util.HashSet)

Example 7 with PortletCategory

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

the class AuthorizationImpl method canPrincipalManage.

/**
     * This checks if the framework has granted principal a right to publish. DO WE WANT SOMETHING
     * THIS COARSE (de)?
     *
     * @param principal IAuthorizationPrincipal
     * @return boolean
     */
@RequestCache
public boolean canPrincipalManage(IAuthorizationPrincipal principal, PortletLifecycleState state, String categoryId) throws AuthorizationException {
    //    return doesPrincipalHavePermission
    //      (principal, IPermission.PORTAL_FRAMEWORK, IPermission.CHANNEL_PUBLISHER_ACTIVITY, null);
    String owner = IPermission.PORTAL_PUBLISH;
    // retrieve the indicated channel from the channel registry store and
    // determine its current lifecycle state
    PortletCategory category = PortletCategoryRegistryLocator.getPortletCategoryRegistry().getPortletCategory(categoryId);
    if (category == null) {
        //				IPermission.CHANNEL_MANAGER_APPROVED_ACTIVITY, target);
        throw new AuthorizationException("Unable to locate category " + categoryId);
    }
    int order = state.getOrder();
    String activity = IPermission.PORTLET_MANAGER_MAINTENANCE_ACTIVITY;
    if (order <= PortletLifecycleState.MAINTENANCE.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_EXPIRED_ACTIVITY;
    if (order <= PortletLifecycleState.EXPIRED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_ACTIVITY;
    if (order <= PortletLifecycleState.PUBLISHED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_APPROVED_ACTIVITY;
    if (order <= PortletLifecycleState.APPROVED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_CREATED_ACTIVITY;
    if (order <= PortletLifecycleState.CREATED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, categoryId)) {
        return true;
    }
    return false;
}
Also used : AuthorizationException(org.apereo.portal.AuthorizationException) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) RequestCache(org.apereo.portal.concurrency.caching.RequestCache)

Example 8 with PortletCategory

use of org.apereo.portal.portlet.om.PortletCategory 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)

Example 9 with PortletCategory

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

the class MarketplaceService method onApplicationEvent.

/**
     * Handle the portal LoginEvent. If marketplace caching is enabled, will preload marketplace
     * entries for the currently logged in user.
     *
     * @param loginEvent the login event.
     */
@Override
public void onApplicationEvent(LoginEvent loginEvent) {
    if (enableMarketplacePreloading) {
        final IPerson person = loginEvent.getPerson();
        /*
             * Passing an empty collection pre-loads an unfiltered collection;
             * instances of PortletMarketplace that specify filtering will
             * trigger a new collection to be loaded.
             */
        final Set<PortletCategory> empty = Collections.emptySet();
        loadMarketplaceEntriesFor(person, empty);
    }
}
Also used : IPerson(org.apereo.portal.security.IPerson) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Example 10 with PortletCategory

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

the class ChannelListController method getRegistryOriginal.

/*
     * Private methods that support the original (pre-4.3) version of the API
     */
/**
     * Gathers and organizes the response based on the specified rootCategory and the permissions of
     * the specified user.
     */
private Map<String, SortedSet<?>> getRegistryOriginal(WebRequest request, IPerson user) {
    /*
         * This collection of all the portlets in the portal is for the sake of
         * tracking which ones are uncategorized.
         */
    Set<IPortletDefinition> portletsNotYetCategorized = new HashSet<IPortletDefinition>(portletDefinitionRegistry.getAllPortletDefinitions());
    // construct a new channel registry
    Map<String, SortedSet<?>> rslt = new TreeMap<String, SortedSet<?>>();
    SortedSet<ChannelCategoryBean> categories = new TreeSet<ChannelCategoryBean>();
    // add the root category and all its children to the registry
    final PortletCategory rootCategory = portletCategoryRegistry.getTopLevelPortletCategory();
    final Locale locale = getUserLocale(user);
    categories.add(prepareCategoryBean(request, rootCategory, portletsNotYetCategorized, user, locale));
    /*
         * uPortal historically has provided for a convention that portlets not in any category
         * may potentially be viewed by users but may not be subscribed to.
         *
         * As of uPortal 4.2, the logic below now takes any portlets the user has BROWSE access to
         * that have not already been identified as belonging to a category and adds them to a category
         * called Uncategorized.
         */
    EntityIdentifier ei = user.getEntityIdentifier();
    IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
    // construct a new channel category bean for this category
    String uncategorizedString = messageSource.getMessage(UNCATEGORIZED, new Object[] {}, locale);
    ChannelCategoryBean uncategorizedPortletsBean = new ChannelCategoryBean(new PortletCategory(uncategorizedString));
    uncategorizedPortletsBean.setName(UNCATEGORIZED);
    uncategorizedPortletsBean.setDescription(messageSource.getMessage(UNCATEGORIZED_DESC, new Object[] {}, locale));
    for (IPortletDefinition portlet : portletsNotYetCategorized) {
        if (authorizationService.canPrincipalBrowse(ap, portlet)) {
            // construct a new channel bean from this channel
            ChannelBean channel = getChannel(portlet, request, locale);
            uncategorizedPortletsBean.addChannel(channel);
        }
    }
    // Add even if no portlets in category
    categories.add(uncategorizedPortletsBean);
    rslt.put("categories", categories);
    return rslt;
}
Also used : Locale(java.util.Locale) EntityIdentifier(org.apereo.portal.EntityIdentifier) ChannelBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelBean) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) ChannelCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.ChannelCategoryBean) TreeSet(java.util.TreeSet) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) HashSet(java.util.HashSet) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Aggregations

PortletCategory (org.apereo.portal.portlet.om.PortletCategory)29 HashSet (java.util.HashSet)19 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)12 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)7 EntityIdentifier (org.apereo.portal.EntityIdentifier)6 IGroupMember (org.apereo.portal.groups.IGroupMember)6 ArrayList (java.util.ArrayList)5 MarketplaceEntry (org.apereo.portal.rest.layout.MarketplaceEntry)5 IPerson (org.apereo.portal.security.IPerson)5 IEntityGroup (org.apereo.portal.groups.IEntityGroup)4 Locale (java.util.Locale)3 SortedSet (java.util.SortedSet)3 TreeSet (java.util.TreeSet)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 PortletPreferences (javax.portlet.PortletPreferences)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 IEntity (org.apereo.portal.groups.IEntity)2 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)2