Search in sources :

Example 1 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class PortalPreAuthenticatedProcessingFilter method retrieveCredentialAndPrincipalTokensFromPropertiesFile.

private void retrieveCredentialAndPrincipalTokensFromPropertiesFile() {
    try {
        String key;
        // We retrieve the tokens representing the credential and principal
        // parameters from the security properties file.
        Properties props = ResourceLoader.getResourceAsProperties(getClass(), "/properties/security.properties");
        Enumeration<?> propNames = props.propertyNames();
        while (propNames.hasMoreElements()) {
            String propName = (String) propNames.nextElement();
            String propValue = props.getProperty(propName);
            if (propName.startsWith("credentialToken.")) {
                key = propName.substring(16);
                this.credentialTokens.put(key, propValue);
            }
            if (propName.startsWith("principalToken.")) {
                key = propName.substring(15);
                this.principalTokens.put(key, propValue);
            }
        }
    } catch (PortalException pe) {
        logger.error("LoginServlet::static ", pe);
    } catch (IOException ioe) {
        logger.error("LoginServlet::static ", ioe);
    }
}
Also used : PortalException(org.apereo.portal.PortalException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 2 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class UpdatePreferencesServlet method addTab.

/**
     * Add a new tab to the layout. The new tab will be appended to the end of the list and named
     * with the BLANK_TAB_NAME variable.
     *
     * @param request
     * @throws IOException
     */
@RequestMapping(method = RequestMethod.POST, params = "action=addTab")
public ModelAndView addTab(HttpServletRequest request, HttpServletResponse response, @RequestParam("widths[]") String[] widths) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IPerson per = getPerson(ui, response);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    // Verify that the user has permission to add this tab
    final IAuthorizationPrincipal authPrincipal = this.getUserPrincipal(per.getUserName());
    if (!authPrincipal.hasPermission(IPermission.PORTAL_SYSTEM, IPermission.ADD_TAB_ACTIVITY, IPermission.ALL_TARGET)) {
        logger.warn("Attempt to add a tab through the REST API by unauthorized user '" + per.getUserName() + "'");
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Add tab disabled"));
    }
    // construct a brand new tab
    String id = "tbd";
    String tabName = request.getParameter("tabName");
    if (StringUtils.isBlank(tabName))
        tabName = DEFAULT_TAB_NAME;
    IUserLayoutFolderDescription newTab = new UserLayoutFolderDescription();
    newTab.setName(tabName);
    newTab.setId(id);
    newTab.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
    newTab.setHidden(false);
    newTab.setUnremovable(false);
    newTab.setImmutable(false);
    // add the tab to the layout
    ulm.addNode(newTab, ulm.getRootFolderId(), null);
    try {
        // save the user's layout
        ulm.saveUserLayout();
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
    // get the id of the newly added tab
    String tabId = newTab.getId();
    for (String width : widths) {
        // create new column element
        IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
        newColumn.setName("Column");
        newColumn.setId("tbd");
        newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
        newColumn.setHidden(false);
        newColumn.setUnremovable(false);
        newColumn.setImmutable(false);
        // add the column to our layout
        ulm.addNode(newColumn, tabId, null);
        this.stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.STRUCTURE, newColumn.getId(), "width", width + "%");
        try {
            // This sets the column attribute in memory but doesn't persist it.  Comment says saves changes "prior to persisting"
            Element folder = ulm.getUserLayoutDOM().getElementById(newColumn.getId());
            UserPrefsHandler.setUserPreference(folder, "width", per);
        } catch (Exception e) {
            logger.error("Error saving new column widths", e);
        }
    }
    // this new tab;  use the currently active tabGroup.
    if (request.getParameter(TAB_GROUP_PARAMETER) != null) {
        String tabGroup = request.getParameter(TAB_GROUP_PARAMETER).trim();
        if (logger.isDebugEnabled()) {
            logger.debug(TAB_GROUP_PARAMETER + "=" + tabGroup);
        }
        if (!TAB_GROUP_DEFAULT.equals(tabGroup) && tabGroup.length() != 0) {
            // Persists SSUP values to the database
            this.stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.STRUCTURE, tabId, TAB_GROUP_PARAMETER, tabGroup);
        }
    }
    try {
        // save the user's layout
        ulm.saveUserLayout();
    } catch (PortalException e) {
        return handlePersistError(request, response, e);
    }
    return new ModelAndView("jsonView", Collections.singletonMap("tabId", tabId));
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) Element(org.w3c.dom.Element) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) UserLayoutFolderDescription(org.apereo.portal.layout.node.UserLayoutFolderDescription) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) XPathExpressionException(javax.xml.xpath.XPathExpressionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PortalException(org.apereo.portal.PortalException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class UpdatePreferencesServlet method updateAttributes.

/**
     * Update the attributes for the node. Unrecognized attributes will log a warning, but are
     * otherwise ignored.
     *
     * @param request
     * @param response
     * @param targetId - the id of the node whose attributes will be updated.
     * @param attributes - parse the JSON name-value pairs in the body as the attributes of the
     *     folder. e.g. : { "structureAttributes" : {"display" : "row", "other" : "another" },
     *     "attributes" : {"hidden": "true", "type" : "header-top" } }
     */
@RequestMapping(method = RequestMethod.POST, params = "action=updateAttributes")
public ModelAndView updateAttributes(HttpServletRequest request, HttpServletResponse response, @RequestParam("targetId") String targetId, @RequestBody Map<String, Map<String, String>> attributes) {
    IUserLayoutManager ulm = userInstanceManager.getUserInstance(request).getPreferencesManager().getUserLayoutManager();
    if (!ulm.getNode(targetId).isEditAllowed()) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.element.update", "Unable to update element", RequestContextUtils.getLocale(request))));
    }
    // Update the attributes based on the supplied JSON (request body name-value pairs)
    IUserLayoutNodeDescription node = ulm.getNode(targetId);
    if (node == null) {
        logger.warn("[updateAttributes()] Unable to locate node with id: " + targetId);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return new ModelAndView("jsonView", Collections.singletonMap("error", "Unable to locate node with id: " + targetId));
    } else {
        setObjectAttributes(node, request, attributes);
        final Locale locale = RequestContextUtils.getLocale(request);
        try {
            ulm.saveUserLayout();
        } catch (PortalException e) {
            return handlePersistError(request, response, e);
        }
        Map<String, String> model = Collections.singletonMap("success", getMessage("success.element.update", "Updated element attributes", locale));
        return new ModelAndView("jsonView", model);
    }
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Locale(java.util.Locale) ModelAndView(org.springframework.web.servlet.ModelAndView) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class UserLocaleHelper method updateUserLocale.

/**
     * Update the current user's locale to match the selected locale. This implementation will
     * update the session locale, and if the user is not a guest, will also update the locale in the
     * user's persisted preferences.
     *
     * @param request
     * @param localeString
     */
public void updateUserLocale(HttpServletRequest request, String localeString) {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IUserPreferencesManager upm = ui.getPreferencesManager();
    final IUserProfile userProfile = upm.getUserProfile();
    LocaleManager localeManager = userProfile.getLocaleManager();
    if (localeString != null) {
        // build a new Locale[] array from the specified locale
        Locale userLocale = parseLocale(localeString);
        Locale[] locales = new Locale[] { userLocale };
        // set this locale in the session
        localeManager.setSessionLocales(locales);
        // if the current user is logged in, also update the persisted
        // user locale
        final IPerson person = ui.getPerson();
        if (!person.isGuest()) {
            try {
                localeManager.persistUserLocales(new Locale[] { userLocale });
                localeStore.updateUserLocales(person, new Locale[] { userLocale });
                // remove person layout framgent from session since it contains some of the data in previous
                // translation and won't be cleared until next logout-login (applies when using
                // RDBMDistributedLayoutStore as user layout store).
                person.setAttribute(Constants.PLF, null);
                upm.getUserLayoutManager().loadUserLayout(true);
            } catch (Exception e) {
                throw new PortalException(e);
            }
        }
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) LocaleManager(org.apereo.portal.i18n.LocaleManager) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 5 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class UpdatePreferencesServlet method renameTab.

/**
     * Rename a specified tab.
     *
     * @param request
     * @throws IOException
     */
@RequestMapping(method = RequestMethod.POST, params = "action=renameTab")
public ModelAndView renameTab(HttpServletRequest request, HttpServletResponse response) throws IOException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    // element ID of the tab to be renamed
    String tabId = request.getParameter("tabId");
    IUserLayoutFolderDescription tab = (IUserLayoutFolderDescription) ulm.getNode(tabId);
    // desired new name
    String tabName = request.getParameter("tabName");
    if (!ulm.canUpdateNode(tab)) {
        logger.warn("Attempting to rename an immutable tab");
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return new ModelAndView("jsonView", Collections.singletonMap("error", getMessage("error.element.update", "Unable to update element", RequestContextUtils.getLocale(request))));
    }
    /*
         * Update the tab and save the layout
         */
    tab.setName(StringUtils.isBlank(tabName) ? DEFAULT_TAB_NAME : tabName);
    final boolean updated = ulm.updateNode(tab);
    if (updated) {
        try {
            // save the user's layout
            ulm.saveUserLayout();
        } catch (PortalException e) {
            return handlePersistError(request, response, e);
        }
        //TODO why do we have to do this, shouldn't modifying the layout be enough to trigger a full re-render (layout's cache key changes)
        this.stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.STRUCTURE, tabId, "name", tabName);
    }
    Map<String, String> model = Collections.singletonMap("message", "saved new tab name");
    return new ModelAndView("jsonView", model);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) ModelAndView(org.springframework.web.servlet.ModelAndView) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PortalException (org.apereo.portal.PortalException)47 Element (org.w3c.dom.Element)19 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)16 IUserInstance (org.apereo.portal.user.IUserInstance)14 Document (org.w3c.dom.Document)14 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)13 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 IPerson (org.apereo.portal.security.IPerson)9 Node (org.w3c.dom.Node)9 Locale (java.util.Locale)7 IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 HashMap (java.util.HashMap)6 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)6 UserLayoutFolderDescription (org.apereo.portal.layout.node.UserLayoutFolderDescription)6 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4