Search in sources :

Example 46 with PortalException

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

the class UserInstanceManagerImpl method getUserInstance.

/**
     * Returns the UserInstance object that is associated with the given request.
     *
     * @param request Incoming HttpServletRequest
     * @return UserInstance object associated with the given request
     */
@Override
public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
    try {
        request = this.portalRequestUtils.getOriginalPortalRequest(request);
    } catch (IllegalArgumentException iae) {
    //ignore, just means that this isn't a wrapped request
    }
    // Use request attributes first for the fastest possible retrieval
    IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
    if (userInstance != null) {
        return userInstance;
    }
    final IPerson person;
    try {
        // Retrieve the person object that is associated with the request
        person = this.personManager.getPerson(request);
    } catch (Exception e) {
        logger.error("Exception while retrieving IPerson!", e);
        throw new PortalSecurityException("Could not retrieve IPerson", e);
    }
    if (person == null) {
        throw new PortalSecurityException("PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
    }
    final HttpSession session = request.getSession();
    if (session == null) {
        throw new IllegalStateException("HttpServletRequest.getSession() returned a null session for request: " + request);
    }
    // Return the UserInstance object if it's in the session
    UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
    if (userInstanceHolder != null) {
        userInstance = userInstanceHolder.getUserInstance();
        if (userInstance != null) {
            return userInstance;
        }
    }
    // Create either a UserInstance or a GuestUserInstance
    final LocaleManager localeManager = this.getLocaleManager(request, person);
    final String userAgent = this.getUserAgent(request);
    final IUserProfile userProfile = this.getUserProfile(request, person, localeManager, userAgent);
    //Create the user layout manager and user instance object
    IUserLayoutManager userLayoutManager = userLayoutManagerFactory.getUserLayoutManager(person, userProfile);
    final UserPreferencesManager userPreferencesManager = new UserPreferencesManager(person, userProfile, userLayoutManager);
    userInstance = new UserInstance(person, userPreferencesManager, localeManager);
    //Ensure the newly created UserInstance is cached in the session
    if (userInstanceHolder == null) {
        userInstanceHolder = new UserInstanceHolder();
    }
    userInstanceHolder.setUserInstance(userInstance);
    session.setAttribute(KEY, userInstanceHolder);
    request.setAttribute(KEY, userInstance);
    // Return the new UserInstance
    return userInstance;
}
Also used : HttpSession(javax.servlet.http.HttpSession) PortalSecurityException(org.apereo.portal.security.PortalSecurityException) PortalException(org.apereo.portal.PortalException) PortalSecurityException(org.apereo.portal.security.PortalSecurityException) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) LocaleManager(org.apereo.portal.i18n.LocaleManager) UserInstance(org.apereo.portal.UserInstance) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 47 with PortalException

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

the class LogoutController method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    final Map<String, String> rdHash = new HashMap<String, String>(1);
    try {
        // We retrieve the redirect strings for each context
        // from the security properties file.
        String key;
        final Properties props = ResourceLoader.getResourceAsProperties(LogoutController.class, "/properties/security.properties");
        final Enumeration propNames = props.propertyNames();
        while (propNames.hasMoreElements()) {
            final String propName = (String) propNames.nextElement();
            final String propValue = props.getProperty(propName);
            if (propName.startsWith("logoutRedirect.")) {
                key = propName.substring(15);
                key = key.startsWith("root.") ? key.substring(5) : key;
                if (log.isDebugEnabled()) {
                    log.debug("Redirect key=" + key + ", value=" + propValue);
                }
                rdHash.put(key, propValue);
            }
        }
    } catch (final PortalException pe) {
        log.error("Failed to load logout redirect URLs", pe);
    } catch (final IOException ioe) {
        log.error("Failed to load logout redirect URLs", ioe);
    }
    this.redirectMap = rdHash;
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) PortalException(org.apereo.portal.PortalException) IOException(java.io.IOException) Properties(java.util.Properties)

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