use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.
the class GrouperEntityGroupStore method findEntitiesForGroup.
/* (non-Javadoc)
* @see org.apereo.portal.groups.IEntityGroupStore#findEntitiesForGroup(org.apereo.portal.groups.IEntityGroup)
*/
@SuppressWarnings("unchecked")
public Iterator findEntitiesForGroup(IEntityGroup group) throws GroupsException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Searching Grouper for members of the group with key: " + group.getKey());
}
try {
// execute a search for members of the specified group
GcGetMembers getGroupsMembers = new GcGetMembers();
getGroupsMembers.addGroupName(group.getLocalKey());
getGroupsMembers.assignIncludeSubjectDetail(true);
WsGetMembersResults results = getGroupsMembers.execute();
if (results == null || results.getResults() == null || results.getResults().length == 0 || results.getResults()[0].getWsSubjects() == null) {
LOGGER.debug("No members found for Grouper group with key " + group.getLocalKey());
return Collections.<IGroupMember>emptyList().iterator();
}
WsSubject[] gInfos = results.getResults()[0].getWsSubjects();
final List<IGroupMember> members = new ArrayList<IGroupMember>(gInfos.length);
// add each result to the member list
for (WsSubject gInfo : gInfos) {
// if the member is not a group (aka person)
if (!StringUtils.equals(gInfo.getSourceId(), "g:gsa")) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("creating leaf member:" + gInfo.getId() + " and name: " + gInfo.getName() + " from group: " + group.getLocalKey());
}
// use the name instead of id as it shows better in the display
IGroupMember member = new EntityImpl(gInfo.getName(), IPerson.class);
members.add(member);
}
}
// return an iterator for the assembled group
return members.iterator();
} catch (Exception e) {
LOGGER.warn("Exception while attempting to retrieve " + "member entities of group with key " + group.getKey() + " from Grouper web services: " + e.getMessage());
return Collections.<IGroupMember>emptyList().iterator();
}
}
use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.
the class AdHocGroupTester method test.
/*
* At some point, a person is being tested for group membership. During that test, the thread hits an ad hoc group
* tester. When that tester calls isDeepMemberOf, a test for group membership is triggered. During this call stack,
* the second call to the ad hoc group tester returns false. Assuming the group hierarchy is not itself recursive
* for the group containing the ad hoc group test, the test returns a usable value.
*
* If there is no caching and the second person object only exists for the recursive call, then the implementation
* works.
*
* Also, if the person object is cached and used twice, then the group key with the ad hoc tester is not added to
* the containing group keys during the recursion but is added (or not) after the test call returns positive.
*/
@Override
public boolean test(IPerson person) {
String personHash = person.getEntityIdentifier().getKey() + groupHash + Thread.currentThread().getId();
logger.debug("Entering test() for {}", personHash);
IEntityGroup entityGroup = findGroupByName(groupName);
if (entityGroup == null) {
logger.error("Group named '{}' in ad hoc group tester definition not found!!", groupName);
return false;
}
IGroupMember gmPerson = findPersonAsGroupMember(person);
if (currentTests.getQuiet(personHash) != null) {
logger.debug("Returning from test() for {} due to recursion for person = {}", personHash, person.toString());
// stop recursing
return false;
}
Element cacheEl = new Element(personHash, personHash);
currentTests.put(cacheEl);
// method that potentially recurs
boolean isPersonGroupMember = gmPerson.isDeepMemberOf(entityGroup);
currentTests.remove(personHash);
final boolean rslt = isPersonGroupMember ^ isNotTest;
logger.debug("Returning '{}' from test() for '{}' {} a (deep) member of '{}'", rslt, person.getUserName(), isNotTest ? "is not" : "is", entityGroup.getName());
return rslt;
}
use of org.apereo.portal.groups.IGroupMember in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method exportPermission.
private boolean exportPermission(IPortletDefinition def, ExternalPermissionDefinition permDef, List<String> groupList, List<String> userList) {
final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
final IPermissionManager pm = authService.newPermissionManager(permDef.getSystem());
final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);
final IAuthorizationPrincipal[] principals = pm.getAuthorizedPrincipals(permDef.getActivity(), portletTargetId);
boolean permAdded = false;
for (IAuthorizationPrincipal principal : principals) {
IGroupMember member = authService.getGroupMember(principal);
if (member.isGroup()) {
final EntityNameFinderService entityNameFinderService = EntityNameFinderService.instance();
final IEntityNameFinder nameFinder = entityNameFinderService.getNameFinder(member.getType());
try {
groupList.add(nameFinder.getName(member.getKey()));
permAdded = true;
} catch (Exception e) {
throw new RuntimeException("Could not find group name for entity: " + member.getKey(), e);
}
} else {
if (userList != null) {
userList.add(member.getKey());
permAdded = true;
}
}
}
Collections.sort(groupList);
if (userList != null) {
Collections.sort(userList);
}
return permAdded;
}
use of org.apereo.portal.groups.IGroupMember 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.IGroupMember in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method importData.
@Transactional
@Override
public void importData(ExternalPortletDefinition portletRep) {
final IPortletDefinition def = portletDefinitionUnmarshaller.unmarshall(portletRep);
final List<PortletCategory> categories = new ArrayList<>();
for (String categoryName : portletRep.getCategories()) {
// Import/Export function, thus the group search is case sensitive.
EntityIdentifier[] cats = GroupService.searchForGroups(categoryName, IGroupConstants.SearchMethod.DISCRETE, IPortletDefinition.class);
PortletCategory category;
if (cats != null && cats.length > 0) {
category = portletCategoryRegistry.getPortletCategory(cats[0].getKey());
} else {
category = portletCategoryRegistry.getPortletCategory(categoryName);
}
if (category == null) {
throw new IllegalArgumentException("No category '" + categoryName + "' found when importing portlet: " + portletRep.getFname());
}
categories.add(category);
}
final String fname = portletRep.getFname();
final Map<ExternalPermissionDefinition, Set<IGroupMember>> permissions = new HashMap<>();
final Set<IGroupMember> subscribeMembers = toGroupMembers(portletRep.getGroups(), fname);
permissions.put(ExternalPermissionDefinition.SUBSCRIBE, subscribeMembers);
if (portletRep.getPermissions() != null && portletRep.getPermissions().getPermissions() != null) {
for (ExternalPermissionMemberList perm : portletRep.getPermissions().getPermissions()) {
Set<IGroupMember> members = toGroupMembers(perm.getGroups(), fname);
ExternalPermissionDefinition permDef = toExternalPermissionDefinition(perm.getSystem(), perm.getActivity());
if (permissions.containsKey(permDef)) {
permissions.get(permDef).addAll(members);
} else {
permissions.put(permDef, members);
}
}
}
savePortletDefinition(def, categories, permissions);
}
Aggregations