Search in sources :

Example 46 with IEntityGroup

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);
        }
    }
}
Also used : IPermissionManager(org.apereo.portal.security.IPermissionManager) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Example 47 with IEntityGroup

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));
}
Also used : IPermissionActivity(org.apereo.portal.permission.IPermissionActivity) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) IEntityGroup(org.apereo.portal.groups.IEntityGroup) IPermissionTargetProvider(org.apereo.portal.permission.target.IPermissionTargetProvider) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) IPermissionOwner(org.apereo.portal.permission.IPermissionOwner)

Example 48 with IEntityGroup

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);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IEntity(org.apereo.portal.groups.IEntity)

Example 49 with IEntityGroup

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;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Example 50 with IEntityGroup

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;
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Aggregations

IEntityGroup (org.apereo.portal.groups.IEntityGroup)77 IGroupMember (org.apereo.portal.groups.IGroupMember)29 ArrayList (java.util.ArrayList)21 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)16 EntityIdentifier (org.apereo.portal.EntityIdentifier)14 HashSet (java.util.HashSet)11 HashMap (java.util.HashMap)10 LinkedList (java.util.LinkedList)9 GroupsException (org.apereo.portal.groups.GroupsException)9 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)9 IPermission (org.apereo.portal.security.IPermission)9 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)8 List (java.util.List)7 CompositeName (javax.naming.CompositeName)7 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 IPerson (org.apereo.portal.security.IPerson)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 DateTime (org.joda.time.DateTime)7