use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class UserGroupSkinMappingTransformerConfigurationSource method getSkinName.
protected String getSkinName(HttpServletRequest request) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IPerson person = userInstance.getPerson();
final EntityIdentifier personIdentifier = person.getEntityIdentifier();
final IGroupMember groupMember = GroupService.getGroupMember(personIdentifier);
final Map<IGroupMember, String> groupMemberToSkinMapping = groupMemberToSkinMappingCreator.get();
for (final Entry<IGroupMember, String> groupToSkinEntry : groupMemberToSkinMapping.entrySet()) {
final IGroupMember group = groupToSkinEntry.getKey();
if (group.isGroup() && groupMember.isDeepMemberOf(group.asGroup())) {
final String skin = groupToSkinEntry.getValue();
getLogger().debug("Setting skin override {} for {} because they are a member of {}", new Object[] { skin, person.getUserName(), group });
//Cache the resolution
return skin;
}
}
getLogger().debug("No user {} is not a member of any configured groups, no skin override will be done", person.getUserName());
return null;
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class MapBackedEntityCache method add.
/* (non-Javadoc)
* @see org.apereo.portal.concurrency.IEntityCache#add(org.apereo.portal.IBasicEntity)
*/
public void add(IBasicEntity entity) throws CachingException {
final EntityIdentifier entityIdentifier = entity.getEntityIdentifier();
final Class<? extends IBasicEntity> addType = entityIdentifier.getType();
if (!this.entityType.isAssignableFrom(addType)) {
throw new CachingException("Problem adding " + entity + ": entity type '" + addType + "' is incompatible with cache type '" + this.entityType + "'.");
}
this.cache.put(entityIdentifier.getKey(), entity);
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class GroupsTester method testUpdateMembersVisibility.
public void testUpdateMembersVisibility() throws Exception {
print(CR + "***** ENTERING GroupsTester.testUpdateMembersVisibility() *****" + CR);
String msg = null;
Class type = TEST_ENTITY_CLASS;
int totNumGroups = 3;
int totNumEntities = 5;
IEntityGroup[] groups = new IEntityGroup[totNumGroups];
IEntity[] entities = new IEntity[totNumEntities];
IGroupMember[] groupMembers = null;
Iterator itr = null;
ArrayList list = null;
int idx = 0;
boolean testValue = false;
msg = "Creating " + totNumGroups + " new groups.";
print(msg);
for (idx = 0; idx < totNumGroups; idx++) {
groups[idx] = getNewGroup();
// cache members from now on.
groups[idx].getChildren();
assertNotNull(msg, groups[idx]);
}
IEntityGroup rootGroup = groups[0];
IEntityGroup childGroup = groups[1];
msg = "Adding " + (totNumGroups - 1) + " to root group.";
print(msg);
for (idx = 1; idx < totNumGroups; idx++) {
rootGroup.addChild(groups[idx]);
}
msg = "Retrieving members from root group.";
print(msg);
list = new ArrayList(rootGroup.getChildren());
assertEquals(msg, (totNumGroups - 1), list.size());
msg = "Adding " + (totNumEntities - 2) + " to root group.";
print(msg);
for (idx = 0; idx < (totNumEntities - 2); idx++) {
rootGroup.addChild(testEntities[idx]);
}
msg = "Retrieving members from root group.";
print(msg);
list = new ArrayList(rootGroup.getChildren());
assertEquals(msg, (totNumGroups - 1 + totNumEntities - 2), list.size());
msg = "Adding 2 entities to child group.";
print(msg);
childGroup.addChild(testEntities[totNumEntities - 1]);
childGroup.addChild(testEntities[totNumEntities]);
msg = "Retrieving ALL members from root group.";
print(msg);
list = new ArrayList(rootGroup.getDescendants());
assertEquals(msg, (totNumGroups - 1 + totNumEntities), list.size());
// At this point, the child group members should not yet be aware of their parents.
msg = "Checking child groups for parents (should be none).";
print(msg);
list = new ArrayList();
for (idx = 1; idx < totNumGroups; idx++) {
list.addAll(groups[idx].getParentGroups());
assertEquals(msg, 0, list.size());
}
testValue = testEntities[0].isMemberOf(rootGroup);
assertEquals(msg, false, testValue);
// Update the parent group. Its children should now be aware of it.
msg = "Updating parent group.";
print(msg);
rootGroup.update();
msg = "Checking child entity for membership in parent.";
print(msg);
testValue = testEntities[0].isMemberOf(rootGroup);
assertEquals(msg, true, testValue);
// Child group not yet updated. Its child should still be unaware of it.
msg = "Checking child entity for membership in child group.";
print(msg);
testValue = testEntities[totNumEntities].isMemberOf(childGroup);
assertEquals(msg, false, testValue);
// Update the child group. Its children should now be aware of it.
msg = "Updating child group.";
print(msg);
childGroup.update();
msg = "Checking child entity for membership in child group.";
print(msg);
testValue = testEntities[totNumEntities].isMemberOf(childGroup);
assertEquals(msg, true, testValue);
msg = "Getting child entity thru the service (should be cached copy).";
print(msg);
EntityIdentifier entID = testEntities[totNumEntities].getUnderlyingEntityIdentifier();
IGroupMember ent = GroupService.getGroupMember(entID);
msg = "Checking child entity for membership in child group.";
print(msg);
testValue = ent.isMemberOf(childGroup);
assertEquals(msg, true, testValue);
// Child entity should now be aware of both of its parents.
msg = "Checking child entity for ALL containing groups.";
print(msg);
list = new ArrayList(ent.getAncestorGroups());
assertEquals(msg, 2, list.size());
print(CR + "***** LEAVING GroupsTester.testUpdateMembersVisibility() *****" + CR);
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class ImportExportPortletController method getAllowedTypes.
/**
* Return a list of all permitted import/export types for the given permission and the current
* user.
*
* @param request
* @param activityName
* @return
*/
protected List<IPortalDataType> getAllowedTypes(PortletRequest request, String activityName, Iterable<IPortalDataType> dataTypes) {
// get the authorization principal representing the current user
final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
final IPerson person = personManager.getPerson(httpServletRequest);
final EntityIdentifier ei = person.getEntityIdentifier();
final IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
// filter the list of configured import/export types by user permission
final List<IPortalDataType> results = new ArrayList<IPortalDataType>();
for (IPortalDataType type : dataTypes) {
final String typeId = type.getTypeId();
if (ap.hasPermission(IPermission.PORTAL_SYSTEM, activityName, typeId)) {
results.add(type);
}
}
return results;
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class PortalHttpServletRequestWrapper method isUserInRole.
/**
* Determines whether or not the user is in the given role. The wrapped request is consulted
* first then the {@link GroupService} is used to determine if a group exists for the specified
* role and if the user is a member of it.
*
* @see
* org.apereo.portal.utils.web.AbstractHttpServletRequestWrapper#isUserInRole(java.lang.String)
*/
@Override
public boolean isUserInRole(String role) {
if (super.getSession(false) == null) {
return super.isUserInRole(role);
}
//Check the wrapped request first
final boolean isUserInRole = super.isUserInRole(role);
if (isUserInRole) {
return true;
}
//Find the group for the role, if not found return false
IEntityGroup groupForRole = GroupService.findGroup(role);
if (groupForRole == null) {
final EntityIdentifier[] results = GroupService.searchForGroups(role, GroupService.IS, IPerson.class);
if (results == null || results.length == 0) {
return false;
}
if (results.length > 1) {
this.logger.warn(results.length + " groups were found for role '" + role + "'. The first result will be used.");
}
IGroupMember member = GroupService.getGroupMember(results[0]);
if (member == null || !member.isGroup()) {
return false;
}
groupForRole = member.asGroup();
}
//Load the group information about the current user
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(this.getWrappedRequest());
final IPerson person = userInstance.getPerson();
final EntityIdentifier personEntityId = person.getEntityIdentifier();
final IGroupMember personGroupMember = GroupService.getGroupMember(personEntityId);
return personGroupMember.isDeepMemberOf(groupForRole);
}
Aggregations