use of org.apereo.portal.groups.IEntity 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.IEntity in project uPortal by Jasig.
the class UpdatePreferencesServlet method getUserPrincipal.
private IAuthorizationPrincipal getUserPrincipal(final String userName) {
final IEntity user = GroupService.getEntity(userName, IPerson.class);
if (user == null) {
return null;
}
final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
return authService.newPrincipal(user);
}
use of org.apereo.portal.groups.IEntity 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.IEntity in project uPortal by Jasig.
the class XalanAuthorizationHelperBean method getUserPrincipal.
protected IAuthorizationPrincipal getUserPrincipal(final String userName) {
final IEntity user = GroupService.getEntity(userName, IPerson.class);
if (user == null) {
return null;
}
final AuthorizationServiceFacade authService = AuthorizationServiceFacade.instance();
return authService.newPrincipal(user);
}
use of org.apereo.portal.groups.IEntity in project uPortal by Jasig.
the class XalanGroupMembershipHelperBean method isUserDeepMemberOfGroupName.
/* (non-Javadoc)
* @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isUserDeepMemberOfGroupName(java.lang.String, java.lang.String)
*
* groupName is case sensitive.
*/
@Override
public boolean isUserDeepMemberOfGroupName(String userName, String groupName) {
final EntityIdentifier[] results = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, IPerson.class);
if (results == null || results.length == 0) {
return false;
}
if (results.length > 1) {
this.logger.warn(results.length + " groups were found for '" + groupName + "'. The first result will be used.");
}
final IGroupMember group = GroupService.getGroupMember(results[0]);
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 group.asGroup().deepContains(entity);
}
Aggregations