use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class FileSystemGroupStore method find.
/**
* Returns an instance of the <code>IEntityGroup</code> from the data store.
*
* @return org.apereo.portal.groups.IEntityGroup
* @param key java.lang.String
*/
public IEntityGroup find(String key) throws GroupsException {
if (log.isDebugEnabled()) {
log.debug(DEBUG_CLASS_NAME + ".find(): group key: " + key);
}
String path = getFilePathFromKey(key);
File f = new File(path);
GroupHolder groupHolder = cacheGet(key);
if (groupHolder == null || (groupHolder.getLastModified() != f.lastModified())) {
if (log.isDebugEnabled()) {
log.debug(DEBUG_CLASS_NAME + ".find(): retrieving group from file system for " + path);
}
if (!f.exists()) {
if (log.isDebugEnabled()) {
log.debug(DEBUG_CLASS_NAME + ".find(): file does not exist: " + path);
}
return null;
}
IEntityGroup group = newInstance(f);
groupHolder = new GroupHolder(group, f.lastModified());
cachePut(key, groupHolder);
}
return groupHolder.getGroup();
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class GrouperEntityGroupStore method createUportalGroupFromGrouperGroup.
/**
* Construct an IEntityGroup from a Grouper WsGroup.
*
* @param wsGroup
* @return the group
*/
protected IEntityGroup createUportalGroupFromGrouperGroup(WsGroup wsGroup) {
IEntityGroup iEntityGroup = new EntityGroupImpl(wsGroup.getName(), IPerson.class);
// need to set the group name and description to the actual
// display name and description
iEntityGroup.setName(wsGroup.getDisplayName());
iEntityGroup.setDescription(wsGroup.getDescription());
return iEntityGroup;
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class GrouperEntityGroupStore method findParentGroups.
/* (non-Javadoc)
* @see org.apereo.portal.groups.IEntityGroupStore#findParentGroups(org.apereo.portal.groups.IGroupMember)
*/
@SuppressWarnings("unchecked")
public Iterator findParentGroups(IGroupMember gm) throws GroupsException {
final List<IEntityGroup> parents = new LinkedList<IEntityGroup>();
GcGetGroups getGroups = new GcGetGroups();
String uportalStem = getStemPrefix();
// if only searching in a specific stem
if (!StringUtils.isBlank(uportalStem)) {
getGroups.assignStemScope(StemScope.ALL_IN_SUBTREE);
getGroups.assignWsStemLookup(new WsStemLookup(uportalStem, null));
}
String key = null;
String subjectSourceId = null;
if (gm.isGroup()) {
key = ((IEntityGroup) gm).getLocalKey();
if (!validKey(key)) {
return parents.iterator();
}
subjectSourceId = "g:gsa";
} else {
// Determine the key to use for this entity. If the entity is a
// group, we should use the group's local key (excluding the
// "grouper." portion of the full key. If the entity is not a
// group type, just use the key.
key = gm.getKey();
}
getGroups.addSubjectLookup(new WsSubjectLookup(null, subjectSourceId, key));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Searching Grouper for parent groups of the entity with key: " + key);
}
try {
WsGetGroupsResults results = getGroups.execute();
if (results == null || results.getResults() == null || results.getResults().length != 1) {
LOGGER.debug("Grouper service returned no matches for key " + key);
return parents.iterator();
}
WsGetGroupsResult wsg = results.getResults()[0];
if (wsg.getWsGroups() != null) {
for (WsGroup g : wsg.getWsGroups()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.trace("Retrieved group: " + g.getName());
}
IEntityGroup parent = createUportalGroupFromGrouperGroup(g);
parents.add(parent);
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Retrieved " + parents.size() + " parent groups of entity with key " + key);
}
} catch (Exception e) {
LOGGER.warn("Exception while attempting to retrieve " + "parents for entity with key " + key + " from Grouper web services: " + e.getMessage());
return Collections.<IEntityGroup>emptyList().iterator();
}
return parents.iterator();
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class EntityPersonAttributesGroupStore method searchForGroups.
@Override
public EntityIdentifier[] searchForGroups(String query, int method, Class leaftype) throws GroupsException {
if (leaftype != IPERSON_CLASS) {
return EMPTY_SEARCH_RESULTS;
}
Set<IPersonAttributesGroupDefinition> pagsGroups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitions();
List<EntityIdentifier> results = new ArrayList<EntityIdentifier>();
switch(method) {
case IS:
for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
if (g.getName().equalsIgnoreCase(query)) {
results.add(g.getEntityIdentifier());
}
}
break;
case STARTS_WITH:
for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
if (g.getName().toUpperCase().startsWith(query.toUpperCase())) {
results.add(g.getEntityIdentifier());
}
}
break;
case ENDS_WITH:
for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
if (g.getName().toUpperCase().endsWith(query.toUpperCase())) {
results.add(g.getEntityIdentifier());
}
}
break;
case CONTAINS:
for (IPersonAttributesGroupDefinition pagsGroup : pagsGroups) {
IEntityGroup g = convertPagsGroupToEntity(pagsGroup);
if (g.getName().toUpperCase().indexOf(query.toUpperCase()) != -1) {
results.add(g.getEntityIdentifier());
}
}
break;
}
return results.toArray(new EntityIdentifier[] {});
}
use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.
the class PagsService method createPagsDefinition.
/** Verifies permissions and that the group doesn't already exist */
public IPersonAttributesGroupDefinition createPagsDefinition(IPerson person, IEntityGroup parent, String groupName, String description) {
// What's the target of the upcoming permissions check?
String target = parent != null ? parent.getEntityIdentifier().getKey() : IPermission.ALL_GROUPS_TARGET;
// Verify permission
if (!hasPermission(person, IPermission.CREATE_GROUP_ACTIVITY, target)) {
throw new RuntimeAuthorizationException(person, IPermission.CREATE_GROUP_ACTIVITY, target);
}
// VALIDATION STEP: The group name & description are allowable
if (StringUtils.isBlank(groupName)) {
throw new IllegalArgumentException("Specified groupName is blank: " + groupName);
}
if (!GROUP_NAME_VALIDATOR_PATTERN.matcher(groupName).matches()) {
throw new IllegalArgumentException("Specified groupName is too long, too short, or contains invalid characters: " + groupName);
}
if (!StringUtils.isBlank(description)) {
// Blank description is allowable
if (!GROUP_DESC_VALIDATOR_PATTERN.matcher(description).matches()) {
throw new IllegalArgumentException("Specified description is too long or contains invalid characters: " + description);
}
}
// VALIDATION STEP: We don't have a group by that name already
EntityIdentifier[] people = GroupService.searchForGroups(groupName, IGroupConstants.IS, IPerson.class);
EntityIdentifier[] portlets = GroupService.searchForGroups(groupName, IGroupConstants.IS, IPortletDefinition.class);
if (people.length != 0 || portlets.length != 0) {
throw new IllegalArgumentException("Specified groupName already in use: " + groupName);
}
IPersonAttributesGroupDefinition rslt = pagsGroupDefDao.createPersonAttributesGroupDefinition(groupName, description);
if (parent != null) {
// Should refactor this switch to instead choose a service and invoke a method on it
switch(parent.getServiceName().toString()) {
case SERVICE_NAME_LOCAL:
IEntityGroup member = GroupService.findGroup(rslt.getCompositeEntityIdentifierForGroup().getKey());
if (member == null) {
String msg = "The specified group was created, but is not present in the store: " + rslt.getName();
throw new RuntimeException(msg);
}
parent.addChild(member);
parent.updateMembers();
break;
case SERVICE_NAME_PAGS:
IPersonAttributesGroupDefinition parentDef = getPagsGroupDefByName(parent.getName());
Set<IPersonAttributesGroupDefinition> members = new HashSet<>(parentDef.getMembers());
members.add(rslt);
parentDef.setMembers(members);
pagsGroupDefDao.updatePersonAttributesGroupDefinition(parentDef);
break;
default:
String msg = "The specified group service does not support adding members: " + parent.getServiceName();
throw new UnsupportedOperationException(msg);
}
}
return rslt;
}
Aggregations