use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class PortletAdministrationHelper method addSubscribePermissionsToForm.
/*
* Add to the form SUBSCRIBE and BROWSE activity permissions, along with their principals,
* assigned to the portlet.
*/
private void addSubscribePermissionsToForm(IPortletDefinition def, PortletDefinitionForm form) {
final String portletTargetId = PermissionHelper.permissionTargetIdForPortletDefinition(def);
/* We are concerned with PORTAL_SUBSCRIBE system */
final IPermissionManager pm = authorizationService.newPermissionManager(IPermission.PORTAL_SUBSCRIBE);
for (String activity : PORTLET_SUBSCRIBE_ACTIVITIES) {
/* Obtain the principals that have permission for the activity on this portlet */
final IAuthorizationPrincipal[] principals = pm.getAuthorizedPrincipals(activity, portletTargetId);
for (IAuthorizationPrincipal principal : principals) {
JsonEntityBean principalBean;
// first assume this is a group
IEntityGroup group = GroupService.findGroup(principal.getKey());
if (group != null) {
// principal is a group
principalBean = new JsonEntityBean(group, EntityEnum.GROUP);
} else {
// not a group, so it must be a person
IGroupMember member = authorizationService.getGroupMember(principal);
principalBean = new JsonEntityBean(member, EntityEnum.PERSON);
// set the name
String name = groupListHelper.lookupEntityName(principalBean);
principalBean.setName(name);
}
/* Make sure we capture the principal just once*/
if (!form.getPrincipals().contains(principalBean)) {
form.addPrincipal(principalBean);
}
form.addPermission(principalBean.getTypeAndIdHash() + "_" + activity);
}
}
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class PortletPermissionsCachePrimer method primeCache.
public void primeCache() {
if (executor.getActiveCount() != 0) {
log.warn("Skipping this run becasue there are active threads in the executor, signifying the previous run is not complete");
return;
}
log.info("STARTING PortletPermissionsCachePrimer.primeCache()...");
final long timestamp = System.currentTimeMillis();
/*
* This task is pretty effort-intensive and may take in excess of a
* minute to run in a single thread. Going to use a divide-and-conquer
* approach.
*/
final Map<NodeWalker, Future<NodeWalkerReport>> futures = new HashMap<>();
final IEntityGroup rootGroup = GroupService.getRootGroup(IPerson.class);
for (Map.Entry<String, Set<String>> y : permissionsMap.entrySet()) {
final IPermissionOwner owner = permissionOwnerDao.getPermissionOwner(y.getKey());
for (String s : y.getValue()) {
final IPermissionActivity activity = permissionOwnerDao.getPermissionActivity(y.getKey(), s);
final IPermissionTargetProvider targetProvider = targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey());
final NodeWalker walker = new NodeWalker(rootGroup, owner, activity, targetProvider);
final Future<NodeWalkerReport> future = this.executor.submit(walker);
futures.put(walker, future);
}
}
int totalCombinations = 0;
for (Map.Entry<NodeWalker, Future<NodeWalkerReport>> y : futures.entrySet()) {
try {
final NodeWalkerReport report = y.getValue().get();
totalCombinations += report.getCombinationCount();
log.debug("NodeWalker '{}' processed {} combinations in {}ms", y.getKey(), report.getCombinationCount(), report.getDuration());
} catch (InterruptedException | ExecutionException e) {
log.error("NodeWalker '{}' failed", y.getKey());
}
}
log.info("COMPLETED PortletPermissionsCachePrimer.primeCache(); processed {} total combinations in {}ms", totalCombinations, Long.toString(System.currentTimeMillis() - timestamp));
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class XalanGroupMembershipHelperBean method isUserDeepMemberOf.
/* (non-Javadoc)
* @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isUserDeepMemberOf(java.lang.String, java.lang.String)
*/
@Override
public boolean isUserDeepMemberOf(String userName, String groupKey) {
final IEntityGroup distinguishedGroup = GroupService.findGroup(groupKey);
if (distinguishedGroup == null) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("No group found for key '" + groupKey + "'");
}
return false;
}
final IEntity entity = GroupService.getEntity(userName, IPerson.class);
if (entity == null) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("No user found for key '" + userName + "'");
}
return false;
}
return distinguishedGroup.deepContains(entity);
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class GroupListHelperImpl method getEntity.
/*
* (non-Javadoc)
* @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getEntity(org.apereo.portal.groups.IGroupMember)
*/
@Override
public JsonEntityBean getEntity(IGroupMember member) {
// get the type of this member entity
EntityEnum entityEnum = getEntityType(member);
// construct a new entity bean for this entity
JsonEntityBean entity;
if (entityEnum.isGroup()) {
entity = new JsonEntityBean((IEntityGroup) member, entityEnum);
} else {
entity = new JsonEntityBean(member, entityEnum);
}
// if the name hasn't been set yet, look up the entity name
if (entity.getName() == null) {
entity.setName(lookupEntityName(entity));
}
if (EntityEnum.GROUP.equals(entity.getEntityType()) || EntityEnum.PERSON.equals(entity.getEntityType())) {
IAuthorizationPrincipal principal = getPrincipalForEntity(entity);
entity.setPrincipalString(principal.getPrincipalString());
}
return entity;
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class GroupListHelperImpl method getEntity.
/*
* (non-Javadoc)
* @see org.apereo.portal.layout.dlm.remoting.IGroupListHelper#getEntity(java.lang.String, java.lang.String, boolean)
*/
@Override
public JsonEntityBean getEntity(String entityType, String entityId, boolean populateChildren) {
// get the EntityEnum for the specified entity type
EntityEnum entityEnum = EntityEnum.getEntityEnum(entityType);
if (entityEnum == null) {
throw new IllegalArgumentException(String.format("Parameter entityType has an unknown value of [%s]", entityType));
}
// to locate it
if (entityEnum.isGroup()) {
// attempt to find the entity
IEntityGroup entity = GroupService.findGroup(entityId);
if (entity == null) {
return null;
} else {
JsonEntityBean jsonBean = new JsonEntityBean(entity, entityEnum);
if (populateChildren) {
Iterator<IGroupMember> members = entity.getChildren().iterator();
jsonBean = populateChildren(jsonBean, members);
}
if (jsonBean.getEntityType().isGroup() || EntityEnum.PERSON.equals(jsonBean.getEntityType())) {
IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean);
jsonBean.setPrincipalString(principal.getPrincipalString());
}
return jsonBean;
}
} else // otherwise use the getGroupMember method
{
IGroupMember entity = GroupService.getGroupMember(entityId, entityEnum.getClazz());
if (entity == null || entity instanceof IEntityGroup) {
return null;
}
JsonEntityBean jsonBean = new JsonEntityBean(entity, entityEnum);
// the group member interface doesn't include the entity name, so
// we'll need to look that up manually
jsonBean.setName(lookupEntityName(jsonBean));
if (EntityEnum.GROUP.equals(jsonBean.getEntityType()) || EntityEnum.PERSON.equals(jsonBean.getEntityType())) {
IAuthorizationPrincipal principal = getPrincipalForEntity(jsonBean);
jsonBean.setPrincipalString(principal.getPrincipalString());
}
return jsonBean;
}
}
Aggregations