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;
}
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());
}
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)));
}
}
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)));
}
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);
}
Aggregations