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);
}
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);
}
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);
}
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();
}
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";
}
Aggregations