Search in sources :

Example 31 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.
 *
 * <p>Role is case sensitive.
 *
 * @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.SearchMethod.DISCRETE, 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);
    final boolean rslt = personGroupMember.isDeepMemberOf(groupForRole);
    logger.trace("Answering {} for isUserInRole where user='{}', role='{}', and groupForRole='{}'", rslt, person.getUserName(), role, groupForRole.getName());
    return rslt;
}
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 32 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 List<Locale> locales = localeManager.getLocales();
    return Collections.enumeration(locales);
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) LocaleManager(org.apereo.portal.i18n.LocaleManager)

Example 33 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 34 with IUserInstance

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

the class UrlNodeSyntaxHelperRegistryImpl method getCurrentUrlNodeSyntaxHelper.

@Override
public IUrlNodeSyntaxHelper getCurrentUrlNodeSyntaxHelper(HttpServletRequest request) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserProfile userProfile = preferencesManager.getUserProfile();
    final int themeStylesheetId = userProfile.getThemeStylesheetId();
    final IUrlNodeSyntaxHelper themeUrlSyntaxHelper = getUrlNodeSyntaxHelperForStylesheet(themeStylesheetId);
    if (themeUrlSyntaxHelper != null) {
        return themeUrlSyntaxHelper;
    }
    final int structureStylesheetId = userProfile.getStructureStylesheetId();
    final IUrlNodeSyntaxHelper structureUrlSyntaxHelper = getUrlNodeSyntaxHelperForStylesheet(structureStylesheetId);
    if (structureUrlSyntaxHelper != null) {
        return structureUrlSyntaxHelper;
    }
    throw new IllegalStateException("No IUrlNodeSyntaxHelper could be found for the current request. Review the IStylesheetDescriptor configuration.");
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Example 35 with IUserInstance

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

the class PortalHttpServletRequestWrapper method getUserPrincipal.

@Override
public Principal getUserPrincipal() {
    if (super.getSession(false) == null) {
        return super.getUserPrincipal();
    }
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(this.getWrappedRequest());
    final IPerson person = userInstance.getPerson();
    if (person == null || person.isGuest()) {
        return null;
    }
    return person;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson)

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