Search in sources :

Example 66 with IAuthorizationPrincipal

use of org.apereo.portal.security.IAuthorizationPrincipal in project uPortal by Jasig.

the class EntityServiceTest method testGetPrincipalForEntity.

@Test
public void testGetPrincipalForEntity() {
    IAuthorizationPrincipal returnString = entityService.getPrincipalForEntity(null);
    Assert.assertNull(returnString);
}
Also used : IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) Test(org.junit.Test)

Example 67 with IAuthorizationPrincipal

use of org.apereo.portal.security.IAuthorizationPrincipal in project uPortal by Jasig.

the class ChannelListController method preparePortletCategoryBean.

private PortletCategoryBean preparePortletCategoryBean(WebRequest req, PortletCategory category, Set<IPortletDefinition> portletsNotYetCategorized, IPerson user, Locale locale) {
    /* Prepare child categories. */
    Set<PortletCategoryBean> subcategories = new HashSet<>();
    for (PortletCategory childCategory : this.portletCategoryRegistry.getChildCategories(category)) {
        PortletCategoryBean childBean = preparePortletCategoryBean(req, childCategory, portletsNotYetCategorized, user, locale);
        subcategories.add(childBean);
    }
    // add the direct child channels for this category
    Set<IPortletDefinition> portlets = portletCategoryRegistry.getChildPortlets(category);
    EntityIdentifier ei = user.getEntityIdentifier();
    IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    Set<PortletDefinitionBean> marketplacePortlets = new HashSet<>();
    for (IPortletDefinition portlet : portlets) {
        if (authorizationService.canPrincipalBrowse(ap, portlet)) {
            PortletDefinitionBean pdb = preparePortletDefinitionBean(req, portlet, locale);
            marketplacePortlets.add(pdb);
        }
        /*
             * Remove the portlet from the uncategorized collection;
             * note -- this approach will not prevent portlets from
             * appearing in multiple categories (as appropriate).
             */
        portletsNotYetCategorized.remove(portlet);
    }
    // construct a new portlet category bean for this category
    PortletCategoryBean categoryBean = PortletCategoryBean.fromPortletCategory(category, subcategories, marketplacePortlets);
    categoryBean.setName(messageSource.getMessage(category.getName(), new Object[] {}, locale));
    return categoryBean;
}
Also used : PortletCategoryBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier) PortletDefinitionBean(org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean) HashSet(java.util.HashSet) PortletCategory(org.apereo.portal.portlet.om.PortletCategory) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 68 with IAuthorizationPrincipal

use of org.apereo.portal.security.IAuthorizationPrincipal in project uPortal by Jasig.

the class UpdatePreferencesServlet method addFavorite.

@RequestMapping(method = RequestMethod.POST, params = "action=addFavorite")
public ModelAndView addFavorite(@RequestParam String channelId, HttpServletRequest request, HttpServletResponse response) throws IOException {
    final IUserInstance ui = userInstanceManager.getUserInstance(request);
    final IPerson person = getPerson(ui, response);
    final IPortletDefinition pdef = portletDefinitionRegistry.getPortletDefinition(channelId);
    final Locale locale = RequestContextUtils.getLocale(request);
    final IAuthorizationPrincipal authPrincipal = this.getUserPrincipal(person.getUserName());
    final String targetString = PermissionHelper.permissionTargetIdForPortletDefinition(pdef);
    if (!authPrincipal.hasPermission(IPermission.PORTAL_SYSTEM, IPermission.PORTLET_FAVORITE_ACTIVITY, targetString)) {
        logger.warn("Unauthorized attempt to favorite portlet '{}' through the REST API by user '{}'", pdef.getFName(), person.getUserName());
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.favorite.not.permitted", "Favorite not permitted", locale)));
    }
    final UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    final IUserLayoutManager ulm = upm.getUserLayoutManager();
    final IUserLayoutChannelDescription channel = new UserLayoutChannelDescription(pdef);
    // get favorite tab
    final String favoriteTabNodeId = FavoritesUtils.getFavoriteTabNodeId(ulm.getUserLayout());
    if (favoriteTabNodeId != null) {
        // add portlet to favorite tab
        final IUserLayoutNodeDescription node = addNodeToTab(ulm, channel, favoriteTabNodeId);
        if (node == null) {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.add.portlet.in.tab", "Can''t add a new favorite", locale)));
        }
        try {
            // save the user's layout
            ulm.saveUserLayout();
        } catch (PortalException e) {
            return handlePersistError(request, response, e);
        }
        // document success for notifications
        final Map<String, String> model = new HashMap<>();
        final String channelTitle = channel.getTitle();
        model.put("response", getMessage("favorites.added.favorite", channelTitle, "Added " + channelTitle + " as a favorite.", locale));
        model.put("newNodeId", node.getId());
        return new ModelAndView("jsonView", model);
    } else {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.finding.favorite.tab", "Can''t find favorite tab", locale)));
    }
}
Also used : Locale(java.util.Locale) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortalException(org.apereo.portal.PortalException) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) UserLayoutChannelDescription(org.apereo.portal.layout.node.UserLayoutChannelDescription) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with IAuthorizationPrincipal

use of org.apereo.portal.security.IAuthorizationPrincipal in project uPortal by Jasig.

the class PermissionAdministrationHelper method canEditOwner.

public boolean canEditOwner(IPerson currentUser, String owner) {
    EntityIdentifier ei = currentUser.getEntityIdentifier();
    IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    return (ap.hasPermission(IPermission.PORTAL_PERMISSIONS, IPermission.EDIT_PERMISSIONS_ACTIVITY, IPermission.ALL_TARGET));
}
Also used : IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 70 with IAuthorizationPrincipal

use of org.apereo.portal.security.IAuthorizationPrincipal in project uPortal by Jasig.

the class ImportExportController method importEntity.

@RequestMapping(value = "/import", method = RequestMethod.POST)
public void importEntity(@RequestParam("file") MultipartFile entityFile, HttpServletRequest request, HttpServletResponse response) throws IOException, XMLStreamException {
    // Get a StAX reader for the source to determine info about the data to import
    final BufferedXMLEventReader bufferedXmlEventReader = createSourceXmlEventReader(entityFile);
    final PortalDataKey portalDataKey = getPortalDataKey(bufferedXmlEventReader);
    final IPerson person = personManager.getPerson(request);
    final EntityIdentifier ei = person.getEntityIdentifier();
    final IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    if (!ap.hasPermission("UP_SYSTEM", "IMPORT_ENTITY", portalDataKey.getName().getLocalPart())) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    portalDataHandlerService.importData(new StAXSource(bufferedXmlEventReader));
    response.setStatus(HttpServletResponse.SC_OK);
}
Also used : BufferedXMLEventReader(org.apereo.portal.xml.stream.BufferedXMLEventReader) IPerson(org.apereo.portal.security.IPerson) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortalDataKey(org.apereo.portal.io.xml.PortalDataKey) EntityIdentifier(org.apereo.portal.EntityIdentifier) StAXSource(javax.xml.transform.stax.StAXSource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)87 EntityIdentifier (org.apereo.portal.EntityIdentifier)31 IPerson (org.apereo.portal.security.IPerson)21 ArrayList (java.util.ArrayList)19 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)17 IEntityGroup (org.apereo.portal.groups.IEntityGroup)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 IGroupMember (org.apereo.portal.groups.IGroupMember)14 IPermission (org.apereo.portal.security.IPermission)14 HashSet (java.util.HashSet)12 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 ModelAndView (org.springframework.web.servlet.ModelAndView)9 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)8 AuthorizationServiceFacade (org.apereo.portal.services.AuthorizationServiceFacade)8 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)7 HashMap (java.util.HashMap)6 IUserInstance (org.apereo.portal.user.IUserInstance)5 Locale (java.util.Locale)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)4