use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class GetMemberServicePhrase method getPhrase.
// Internal search, thus case sensitive.
public static String getPhrase(String name, String memberValue) {
String rslt = null;
// We can (and must) cut & run if the element is a <literal> or a <channel>...
if (name.equals("literal") || name.equals("channel")) {
return "local";
}
try {
Class[] leafTypes = new Class[] { IPerson.class, IPortletDefinition.class };
for (int i = 0; i < leafTypes.length && rslt == null; i++) {
EntityIdentifier[] eis = GroupService.searchForGroups(memberValue, IGroupConstants.SearchMethod.DISCRETE, leafTypes[i]);
if (eis.length == 1) {
// Match!
if (eis[0].getType() == IEntityGroup.class) {
IEntityGroup g = GroupService.findGroup(eis[0].getKey());
rslt = g.getServiceName().toString();
} else {
String msg = "The specified entity is not a group: " + memberValue;
throw new RuntimeException(msg);
}
break;
} else if (eis.length > 1) {
String msg = "Ambiguous member name: " + memberValue;
throw new RuntimeException(msg);
}
}
} catch (Throwable t) {
String msg = "Error looking up the specified member: " + memberValue;
throw new RuntimeException(msg, t);
}
if (rslt == null) {
String msg = "The specified member was not found: " + memberValue;
throw new RuntimeException(msg);
}
return rslt;
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method savePortletDefinition.
/**
* Save a portlet definition.
*
* @param definition the portlet definition
* @param categories the list of categories for the portlet
* @param permissionMap a map of permission name -> list of groups who are granted that
* permission (Note: for now, only grant is supported and only for the FRAMEWORK_OWNER perm
* manager)
*/
private IPortletDefinition savePortletDefinition(IPortletDefinition definition, List<PortletCategory> categories, Map<ExternalPermissionDefinition, Set<IGroupMember>> permissionMap) {
boolean newChannel = (definition.getPortletDefinitionId() == null);
// save the channel
definition = portletDefinitionDao.savePortletDefinition(definition);
definition = portletDefinitionDao.getPortletDefinitionByFname(definition.getFName());
final String defId = definition.getPortletDefinitionId().getStringId();
final IEntity portletDefEntity = GroupService.getEntity(defId, IPortletDefinition.class);
// The groups service needs to deal with concurrent modification better.
synchronized (this.groupUpdateLock) {
// Delete existing category memberships for this channel
if (!newChannel) {
for (IEntityGroup group : portletDefEntity.getAncestorGroups()) {
group.removeChild(portletDefEntity);
group.update();
}
}
// For each category ID, add channel to category
for (PortletCategory category : categories) {
final IEntityGroup categoryGroup = GroupService.findGroup(category.getId());
categoryGroup.addChild(portletDefEntity);
categoryGroup.updateMembers();
}
// Set groups
final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
final String target = PermissionHelper.permissionTargetIdForPortletDefinition(definition);
// Loop over the affected permission managers...
Map<String, Collection<ExternalPermissionDefinition>> permissionsBySystem = getPermissionsBySystem(permissionMap.keySet());
for (String system : permissionsBySystem.keySet()) {
Collection<ExternalPermissionDefinition> systemPerms = permissionsBySystem.get(system);
// get the permission manager for this system...
final IUpdatingPermissionManager upm = authService.newUpdatingPermissionManager(system);
final List<IPermission> permissions = new ArrayList<>();
// add activity grants for each permission..
for (ExternalPermissionDefinition permissionDef : systemPerms) {
Set<IGroupMember> members = permissionMap.get(permissionDef);
for (final IGroupMember member : members) {
final IAuthorizationPrincipal authPrincipal = authService.newPrincipal(member);
final IPermission permEntity = upm.newPermission(authPrincipal);
permEntity.setType(IPermission.PERMISSION_TYPE_GRANT);
permEntity.setActivity(permissionDef.getActivity());
permEntity.setTarget(target);
permissions.add(permEntity);
}
}
// ones
if (!newChannel) {
for (ExternalPermissionDefinition permissionName : permissionMap.keySet()) {
IPermission[] oldPermissions = upm.getPermissions(permissionName.getActivity(), target);
upm.removePermissions(oldPermissions);
}
}
upm.addPermissions(permissions.toArray(new IPermission[permissions.size()]));
}
}
if (logger.isDebugEnabled()) {
logger.debug("Portlet " + defId + " has been " + (newChannel ? "published" : "modified") + ".");
}
return definition;
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class GoogleAnalyticsController method isMember.
/**
* Check if the user is a member of the specified group name
*
* <p>Internal search, thus case sensitive.
*/
private boolean isMember(IGroupMember groupMember, String groupName) {
try {
IEntityGroup group = GroupService.findGroup(groupName);
if (group != null) {
return groupMember.isDeepMemberOf(group);
}
final EntityIdentifier[] results = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, IPerson.class);
if (results == null || results.length == 0) {
this.logger.warn("No portal group found for '{}' no users will be placed in that group for analytics", groupName);
return false;
}
if (results.length > 1) {
this.logger.warn("{} groups were found for groupName '{}'. The first result will be used.", results.length, groupName);
}
group = (IEntityGroup) GroupService.getGroupMember(results[0]);
return groupMember.isDeepMemberOf(group);
} catch (Exception e) {
this.logger.warn("Failed to determine if {} is a member of {}, returning false", groupMember, groupName, e);
return false;
}
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class PopularPortletsController method buildEventCounts.
private List<PortletUsage> buildEventCounts(Integer days, IPerson user, Locale locale) {
final DateTime end = new DateTime();
final DateTime begin = end.minusDays(days);
final IEntityGroup everyone = GroupService.getRootGroup(IPerson.class);
final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping(everyone.getKey());
final List<PortletLayoutAggregation> aggregations = portletLayoutDao.getAggregationsForAllPortlets(begin, end, AGGREGATION_INTERVAL, group);
final EntityIdentifier ei = user.getEntityIdentifier();
final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
final IAuthorizationPrincipal ap = authService.newPrincipal(ei.getKey(), ei.getType());
final Map<String, PortletUsage> resultBuilder = new HashMap<String, PortletUsage>();
for (final PortletLayoutAggregation aggregation : aggregations) {
final AggregatedPortletMapping portlet = aggregation.getPortletMapping();
final String fname = portlet.getFname();
PortletUsage portletUsage = resultBuilder.get(fname);
if (portletUsage == null) {
final IPortletDefinition portletDefinition = this.portletDefinitionDao.getPortletDefinitionByFname(fname);
if (portletDefinition == null || !ap.canSubscribe(portletDefinition.getPortletDefinitionId().getStringId())) {
// Skip portlets that no longer exist or cannot be subscribed to
continue;
}
portletUsage = new PortletUsage(portletDefinition.getPortletDefinitionId().getLongId(), fname, portletDefinition.getTitle(locale.toString()), portletDefinition.getDescription(locale.toString()));
resultBuilder.put(fname, portletUsage);
}
portletUsage.incrementCount(aggregation.getAddCount());
}
final ArrayList<PortletUsage> results = new ArrayList<PortletUsage>(resultBuilder.values());
Collections.sort(results);
return results;
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class PortletAdministrationHelper method createNewPortletDefinitionForm.
/*
* Create a {@code PortletDefinitionForm} and pre-populate it with default categories and principal permissions.
*/
private PortletDefinitionForm createNewPortletDefinitionForm() {
final PortletDefinitionForm form = new PortletDefinitionForm();
// pre-populate with top-level category
final IEntityGroup portletCategoriesGroup = GroupService.getDistinguishedGroup(IPortletDefinition.DISTINGUISHED_GROUP);
form.addCategory(new JsonEntityBean(portletCategoriesGroup, groupListHelper.getEntityType(portletCategoriesGroup)));
// pre-populate with top-level group
final IEntityGroup everyoneGroup = GroupService.getDistinguishedGroup(IPerson.DISTINGUISHED_GROUP);
final JsonEntityBean everyoneBean = new JsonEntityBean(everyoneGroup, groupListHelper.getEntityType(everyoneGroup));
form.setPrincipals(Collections.singleton(everyoneBean), true);
return form;
}
Aggregations