Search in sources :

Example 16 with IUserInstance

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

the class PortalHttpServletRequestWrapper method isUserInRole.

/**
     * Determines whether or not the user is in the given role. The wrapped request is consulted
     * first then the {@link GroupService} is used to determine if a group exists for the specified
     * role and if the user is a member of it.
     *
     * @see
     *     org.apereo.portal.utils.web.AbstractHttpServletRequestWrapper#isUserInRole(java.lang.String)
     */
@Override
public boolean isUserInRole(String role) {
    if (super.getSession(false) == null) {
        return super.isUserInRole(role);
    }
    //Check the wrapped request first
    final boolean isUserInRole = super.isUserInRole(role);
    if (isUserInRole) {
        return true;
    }
    //Find the group for the role, if not found return false
    IEntityGroup groupForRole = GroupService.findGroup(role);
    if (groupForRole == null) {
        final EntityIdentifier[] results = GroupService.searchForGroups(role, GroupService.IS, IPerson.class);
        if (results == null || results.length == 0) {
            return false;
        }
        if (results.length > 1) {
            this.logger.warn(results.length + " groups were found for role '" + role + "'. The first result will be used.");
        }
        IGroupMember member = GroupService.getGroupMember(results[0]);
        if (member == null || !member.isGroup()) {
            return false;
        }
        groupForRole = member.asGroup();
    }
    //Load the group information about the current user
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(this.getWrappedRequest());
    final IPerson person = userInstance.getPerson();
    final EntityIdentifier personEntityId = person.getEntityIdentifier();
    final IGroupMember personGroupMember = GroupService.getGroupMember(personEntityId);
    return personGroupMember.isDeepMemberOf(groupForRole);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IUserInstance(org.apereo.portal.user.IUserInstance) IGroupMember(org.apereo.portal.groups.IGroupMember) IPerson(org.apereo.portal.security.IPerson) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 17 with IUserInstance

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

the class PortalHttpServletRequestWrapper method getLocales.

/* (non-Javadoc)
     * @see org.apereo.portal.url.AbstractHttpServletRequestWrapper#getLocales()
     */
@Override
public Enumeration<Locale> getLocales() {
    if (super.getSession(false) == null) {
        return super.getLocales();
    }
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(this.getWrappedRequest());
    final LocaleManager localeManager = userInstance.getLocaleManager();
    final Locale[] locales = localeManager.getLocales();
    return new ArrayEnumerator<Locale>(locales);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) ArrayEnumerator(org.apereo.portal.utils.ArrayEnumerator) LocaleManager(org.apereo.portal.i18n.LocaleManager)

Example 18 with IUserInstance

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

the class PortletEntityRegistryImpl method getOrCreateDelegatePortletEntity.

@Override
public IPortletEntity getOrCreateDelegatePortletEntity(HttpServletRequest request, IPortletWindowId parentPortletWindowId, IPortletDefinitionId delegatePortletDefinitionId) {
    //Create a special synthetic layout node ID for the delegate entity
    final String layoutNodeId = PortletWindowIdStringUtils.convertToDelegateLayoutNodeId(parentPortletWindowId.toString());
    //Grab the current user
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    final int userId = person.getID();
    //Use the general API, the only thing special is the layout node id
    return getOrCreatePortletEntity(request, delegatePortletDefinitionId, layoutNodeId, userId);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson)

Example 19 with IUserInstance

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

the class PortalUrlProviderImpl method verifyPortletWindowId.

/**
     * Verify the requested portlet window corresponds to a node in the user's layout and return the
     * corresponding layout node id
     */
protected String verifyPortletWindowId(HttpServletRequest request, IPortletWindowId portletWindowId) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
    final IPortletWindowId delegationParentWindowId = portletWindow.getDelegationParentId();
    if (delegationParentWindowId != null) {
        return verifyPortletWindowId(request, delegationParentWindowId);
    }
    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final String channelSubscribeId = portletEntity.getLayoutNodeId();
    final IUserLayoutNodeDescription node = userLayoutManager.getNode(channelSubscribeId);
    if (node == null) {
        throw new IllegalArgumentException("No layout node exists for id " + channelSubscribeId + " of window " + portletWindowId);
    }
    return node.getId();
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 20 with IUserInstance

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

the class PortletMarketplaceController method getLayoutInfo.

@ResourceMapping("layoutInfo")
public String getLayoutInfo(ResourceRequest request, @RequestParam String portletFName, Model model) throws TransformerException {
    Validate.notNull(portletFName, "Please supply a portlet fname");
    final HttpServletRequest servletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    IUserInstance ui = userInstanceManager.getUserInstance(servletRequest);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    IPerson person = ui.getPerson();
    DistributedUserLayout userLayout = userLayoutStore.getUserLayout(person, upm.getUserProfile());
    List<PortletTab> tabs = getPortletTabInfo(userLayout, portletFName);
    boolean isFavorite = isPortletFavorited(ulm.getUserLayout(), portletFName);
    model.addAttribute("favorite", isFavorite);
    model.addAttribute("tabs", tabs);
    return "json";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) DistributedUserLayout(org.apereo.portal.layout.dlm.DistributedUserLayout) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping)

Aggregations

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