Search in sources :

Example 21 with IUserInstance

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

the class PortletEntityRegistryImpl method getOrCreateDefaultPortletEntity.

@Override
public IPortletEntity getOrCreateDefaultPortletEntity(HttpServletRequest request, IPortletDefinitionId portletDefinitionId) {
    Validate.notNull(request, "HttpServletRequest cannot be null");
    Validate.notNull(portletDefinitionId, "portletDefinitionId cannot be null");
    final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionId);
    if (portletDefinition == null) {
        throw new IllegalArgumentException("No portlet definition found for id '" + portletDefinitionId + "'.");
    }
    // Determine the appropriate portlet window ID for the definition
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    // Determine the subscribe ID
    final String portletFName = portletDefinition.getFName();
    final String layoutNodeId = userLayoutManager.getSubscribeId(portletFName);
    if (layoutNodeId == null) {
        throw new IllegalArgumentException("No layout node ID found for fname '" + portletFName + "'.");
    }
    this.logger.trace("Found layout node {} for portlet definition {}", layoutNodeId, portletFName);
    final IPerson person = userInstance.getPerson();
    final int personId = person.getID();
    return this.getOrCreatePortletEntity(request, portletDefinitionId, layoutNodeId, personId);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 22 with IUserInstance

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

the class PortletEntityRegistryImpl method parseConsistentPortletEntityId.

protected IPortletEntityId parseConsistentPortletEntityId(HttpServletRequest request, String consistentEntityIdString) {
    Validate.notNull(consistentEntityIdString, "consistentEntityIdString can not be null");
    // Check in the cache first
    final Element element = this.entityIdParseCache.get(consistentEntityIdString);
    if (element != null) {
        final Object value = element.getObjectValue();
        if (value != null) {
            return (IPortletEntityId) value;
        }
    }
    if (!PortletEntityIdStringUtils.hasCorrectNumberOfParts(consistentEntityIdString)) {
        throw new IllegalArgumentException("consistentEntityIdString does not have 3 parts and is invalid: " + consistentEntityIdString);
    }
    // Verify the portlet definition id
    final String portletDefinitionIdString = PortletEntityIdStringUtils.parsePortletDefinitionId(consistentEntityIdString);
    final IPortletDefinition portletDefinition = this.getPortletDefinition(request, portletDefinitionIdString);
    if (portletDefinition == null) {
        throw new IllegalArgumentException("No parent IPortletDefinition found for " + portletDefinitionIdString + " from entity id string: " + consistentEntityIdString);
    }
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    // Verify non-delegate layout node id exists and is for a portlet
    final String layoutNodeId = PortletEntityIdStringUtils.parseLayoutNodeId(consistentEntityIdString);
    if (!PortletEntityIdStringUtils.isDelegateLayoutNode(layoutNodeId)) {
        final IUserLayoutNodeDescription node = userLayoutManager.getNode(layoutNodeId);
        if (node == null || node.getType() != LayoutNodeType.PORTLET) {
            throw new IllegalArgumentException("No portlet layout node found for " + layoutNodeId + " from entity id string: " + consistentEntityIdString);
        }
        // TODO is this doable for delegation?
        // Verify the portlet definition matches
        final IUserLayoutChannelDescription portletNode = (IUserLayoutChannelDescription) node;
        final String channelPublishId = portletNode.getChannelPublishId();
        if (!portletDefinitionId.getStringId().equals(channelPublishId)) {
            throw new IllegalArgumentException("The portlet layout node found for " + layoutNodeId + " does not match the IPortletDefinitionId " + portletDefinitionId + " specified in entity id string: " + consistentEntityIdString);
        }
    }
    // TODO when there is a JPA backed user dao actually verify this mapping
    // User just conver to an int
    final int userId;
    final String userIdAsString = PortletEntityIdStringUtils.parseUserIdAsString(consistentEntityIdString);
    try {
        userId = Integer.parseInt(userIdAsString);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The user id " + userIdAsString + " is not a valid integer from entity id string: " + consistentEntityIdString, e);
    }
    final IPortletEntityId portletEntityId = createConsistentPortletEntityId(portletDefinitionId, layoutNodeId, userId);
    // Cache the resolution
    this.entityIdParseCache.put(new Element(consistentEntityIdString, portletEntityId));
    return portletEntityId;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(net.sf.ehcache.Element) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 23 with IUserInstance

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

the class PortletWindowRegistryImpl method storePortletWindow.

@Override
public void storePortletWindow(HttpServletRequest request, IPortletWindow portletWindow) {
    if (isDisablePersistentWindowStates(request)) {
        return;
    }
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    if (person.isGuest()) {
        // Never persist things for the guest user, just rely on in-memory storage
        return;
    }
    final IStylesheetDescriptor themeStylesheetDescriptor = this.getThemeStylesheetDescriptor(request);
    final WindowState windowState = portletWindow.getWindowState();
    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final WindowState entityWindowState = portletEntity.getWindowState(themeStylesheetDescriptor);
    // If the window and entity states are different
    if (windowState != entityWindowState && !windowState.equals(entityWindowState)) {
        final WindowState defaultWindowState = this.getDefaultWindowState(themeStylesheetDescriptor);
        // If a window state is set and is one of the persistent states set it on the entity
        if (!defaultWindowState.equals(windowState) && persistentWindowStates.contains(windowState)) {
            portletEntity.setWindowState(themeStylesheetDescriptor, windowState);
        } else // If not remove the state from the entity
        if (entityWindowState != null) {
            portletEntity.setWindowState(themeStylesheetDescriptor, null);
        }
        // Persist the modified entity
        this.portletEntityRegistry.storePortletEntity(request, portletEntity);
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) WindowState(javax.portlet.WindowState) IPerson(org.apereo.portal.security.IPerson) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IStylesheetDescriptor(org.apereo.portal.layout.om.IStylesheetDescriptor)

Example 24 with IUserInstance

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

the class UserLayoutStoreComponent method getUserLayoutManager.

/**
 * Get the {@link IUserLayoutManager} for the user making the request
 */
protected IUserLayoutManager getUserLayoutManager(HttpServletRequest request) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    return preferencesManager.getUserLayoutManager();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Example 25 with IUserInstance

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

the class ProfileFNamePredicate method test.

@Override
public boolean test(final HttpServletRequest request) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final String profileFName = userInstance.getPreferencesManager().getUserProfile().getProfileFname();
    // used for logging
    final String username = userInstance.getPerson().getUserName();
    if (profileFNameToMatch.equals(profileFName)) {
        logger.debug("User {} does have profile with matching fname {}.", username, profileFName);
        return true;
    }
    logger.debug("Request for user {} presents profile fname {} which does not match configured profile fname {}.", username, profileFName, profileFNameToMatch);
    return false;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance)

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