Search in sources :

Example 1 with IEntityNameFinder

use of org.apereo.portal.groups.IEntityNameFinder in project uPortal by Jasig.

the class GroupListHelperImpl method lookupEntityName.

/**
     * Convenience method that looks up the name of the given group member. Used for person types.
     *
     * @param groupMember Entity to look up
     * @return groupMember's name or null if there's an error
     */
public String lookupEntityName(JsonEntityBean entity) {
    EntityEnum entityEnum = entity.getEntityType();
    IEntityNameFinder finder;
    if (entityEnum.isGroup()) {
        finder = EntityNameFinderService.instance().getNameFinder(IEntityGroup.class);
    } else {
        finder = EntityNameFinderService.instance().getNameFinder(entityEnum.getClazz());
    }
    try {
        return finder.getName(entity.getId());
    } catch (Exception e) {
        /* An exception here isn't the end of the world.  Just log it
            and return null. */
        log.warn("Couldn't find name for entity " + entity.getId(), e);
        return null;
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) EntityEnum(org.apereo.portal.portlets.groupselector.EntityEnum) IEntityNameFinder(org.apereo.portal.groups.IEntityNameFinder)

Example 2 with IEntityNameFinder

use of org.apereo.portal.groups.IEntityNameFinder in project uPortal by Jasig.

the class PortletDefinitionImporterExporter method exportPermission.

private boolean exportPermission(IPortletDefinition def, ExternalPermissionDefinition permDef, List<String> groupList, List<String> userList) {
    final AuthorizationService authService = org.apereo.portal.services.AuthorizationService.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;
}
Also used : IPermissionManager(org.apereo.portal.security.IPermissionManager) IGroupMember(org.apereo.portal.groups.IGroupMember) IEntityNameFinder(org.apereo.portal.groups.IEntityNameFinder) AuthorizationService(org.apereo.portal.services.AuthorizationService) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityNameFinderService(org.apereo.portal.services.EntityNameFinderService)

Aggregations

IEntityNameFinder (org.apereo.portal.groups.IEntityNameFinder)2 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 IGroupMember (org.apereo.portal.groups.IGroupMember)1 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)1 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)1 IPermissionManager (org.apereo.portal.security.IPermissionManager)1 AuthorizationService (org.apereo.portal.services.AuthorizationService)1 EntityNameFinderService (org.apereo.portal.services.EntityNameFinderService)1