Search in sources :

Example 46 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class LoginPortletHelper method getSelectedProfile.

/**
 * Get the profile that should be pre-selected in the local login form.
 *
 * @param request
 * @return
 */
public String getSelectedProfile(PortletRequest request) {
    // if a profile selection exists in the session, use it
    final PortletSession session = request.getPortletSession();
    String profileName = (String) session.getAttribute(SessionAttributeProfileMapperImpl.DEFAULT_SESSION_ATTRIBUTE_NAME, PortletSession.APPLICATION_SCOPE);
    // the user
    if (profileName == null) {
        // get the profile for the current request
        final HttpServletRequest httpServletRequest = portalRequestUtils.getPortletHttpRequest(request);
        final IUserInstance ui = userInstanceManager.getUserInstance(httpServletRequest);
        final IUserProfile profile = ui.getPreferencesManager().getUserProfile();
        // the profile key map used by the session attribute profile mapper
        for (Map.Entry<String, String> entry : mappings.entrySet()) {
            if (entry.getValue().equals(profile.getProfileFname())) {
                profileName = entry.getKey();
                break;
            }
        }
    }
    return profileName;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) PortletSession(javax.portlet.PortletSession) IUserProfile(org.apereo.portal.IUserProfile) Map(java.util.Map)

Example 47 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class UpdatePreferencesServlet method updatePermissions.

@RequestMapping(method = RequestMethod.POST, params = "action=updatePermissions")
public ModelAndView updatePermissions(HttpServletRequest request, HttpServletResponse response) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    String elementId = request.getParameter("elementID");
    IUserLayoutNodeDescription node = ulm.getNode(elementId);
    if (node == null) {
        logger.warn("Failed to locate node for permissions update");
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Invalid node id " + elementId));
    }
    String deletable = request.getParameter("deletable");
    if (!StringUtils.isBlank(deletable)) {
        node.setDeleteAllowed(Boolean.valueOf(deletable));
    }
    String movable = request.getParameter("movable");
    if (!StringUtils.isBlank(movable)) {
        node.setMoveAllowed(Boolean.valueOf(movable));
    }
    String editable = request.getParameter("editable");
    if (!StringUtils.isBlank(editable)) {
        node.setEditAllowed(Boolean.valueOf(editable));
    }
    String canAddChildren = request.getParameter("addChildAllowed");
    if (!StringUtils.isBlank(canAddChildren)) {
        node.setAddChildAllowed(Boolean.valueOf(canAddChildren));
    }
    ulm.updateNode(node);
    try {
        // save the user's layout
        ulm.saveUserLayout();
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
    return new ModelAndView("jsonView", Collections.emptyMap());
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) ModelAndView(org.springframework.web.servlet.ModelAndView) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 48 with IUserInstance

use of org.apereo.portal.user.IUserInstance 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 49 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class UpdatePreferencesServlet method moveTab.

/**
 * Move a tab left or right.
 *
 * @param sourceId node ID of tab to move
 * @param method insertBefore or appendAfter. If appendAfter, tab is added as last tab (parent
 *     of destinationId).
 * @param destinationId insertBefore: node ID of tab to move sourceId before. insertAfter: node
 *     ID of another tab
 * @param request
 * @param response
 * @throws PortalException
 * @throws IOException
 */
@RequestMapping(method = RequestMethod.POST, params = "action=moveTab")
public ModelAndView moveTab(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "sourceID") String sourceId, @RequestParam String method, @RequestParam(value = "elementID") String destinationId) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    final Locale locale = RequestContextUtils.getLocale(request);
    // If we're moving this element before another one, we need
    // to know what the target is. If there's no target, just
    // assume we're moving it to the very end of the list.
    String siblingId = null;
    if ("insertBefore".equals(method))
        siblingId = destinationId;
    try {
        // move the node as requested and save the layout
        if (!ulm.moveNode(sourceId, ulm.getParentId(destinationId), siblingId)) {
            logger.warn("Failed to move tab in user layout. moveNode returned false");
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("error.move.tab", "There was an issue moving the tab, please refresh the page and try again.", locale)));
        }
        ulm.saveUserLayout();
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
    return new ModelAndView("jsonView", Collections.singletonMap("response", getMessage("success.move.tab", "Tab moved successfully", locale)));
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) ModelAndView(org.springframework.web.servlet.ModelAndView) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 50 with IUserInstance

use of org.apereo.portal.user.IUserInstance in project uPortal by Jasig.

the class UpdatePreferencesServlet method addPortlet.

/**
 * Add a new channel.
 *
 * @param request
 * @param response
 * @throws IOException
 * @throws PortalException
 */
@RequestMapping(method = RequestMethod.POST, params = "action=addPortlet")
public ModelAndView addPortlet(HttpServletRequest request, HttpServletResponse response) throws IOException, PortalException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    final Locale locale = RequestContextUtils.getLocale(request);
    // gather the parameters we need to move a channel
    String destinationId = request.getParameter("elementID");
    String sourceId = request.getParameter("channelID");
    String method = request.getParameter("position");
    String fname = request.getParameter("fname");
    if (destinationId == null) {
        String tabName = request.getParameter("tabName");
        if (tabName != null) {
            destinationId = getTabIdFromName(ulm.getUserLayout(), tabName);
        }
    }
    IPortletDefinition definition;
    if (sourceId != null)
        definition = portletDefinitionRegistry.getPortletDefinition(sourceId);
    else if (fname != null)
        definition = portletDefinitionRegistry.getPortletDefinitionByFname(fname);
    else {
        logger.error("SourceId or fname invalid when adding a portlet");
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "SourceId or fname invalid"));
    }
    IUserLayoutChannelDescription channel = new UserLayoutChannelDescription(definition);
    IUserLayoutNodeDescription node;
    if (isTab(ulm, destinationId)) {
        node = addNodeToTab(ulm, channel, destinationId);
    } else {
        boolean isInsert = method != null && method.equals("insertBefore");
        // If neither an insert or type folder - Can't "insert into" non-folder
        if (!(isInsert || isFolder(ulm, destinationId))) {
            logger.error("Cannot insert into portlet element");
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return new ModelAndView("jsonView", Collections.singletonMap("error", "Cannot insert into portlet element"));
        }
        String siblingId = isInsert ? destinationId : null;
        String target = isInsert ? ulm.getParentId(destinationId) : destinationId;
        // move the channel into the column
        node = ulm.addNode(channel, target, siblingId);
    }
    if (node == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.add.element", "Unable to add element", locale)));
    }
    String nodeId = node.getId();
    try {
        // save the user's layout
        ulm.saveUserLayout();
        if (addedWindowState != null) {
            IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, channel.getFunctionalName());
            portletWindow.setWindowState(addedWindowState);
            this.portletWindowRegistry.storePortletWindow(request, portletWindow);
        }
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
    Map<String, String> model = new HashMap<>();
    model.put("response", getMessage("success.add.portlet", "Added a new channel", locale));
    model.put("newNodeId", nodeId);
    return new ModelAndView("jsonView", model);
}
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) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IUserInstance(org.apereo.portal.user.IUserInstance) 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)

Aggregations

IUserInstance (org.apereo.portal.user.IUserInstance)65 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)28 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)28 IPerson (org.apereo.portal.security.IPerson)25 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)15 PortalException (org.apereo.portal.PortalException)14 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)12 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 IUserProfile (org.apereo.portal.IUserProfile)10 Locale (java.util.Locale)9 IUserLayout (org.apereo.portal.layout.IUserLayout)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 HashMap (java.util.HashMap)6 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)6 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)6 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)5