use of org.apereo.portal.groups.GroupsException in project uPortal by Jasig.
the class GrouperEntityGroupStore method searchForEntities.
/** @see IEntitySearcher#searchForEntities(java.lang.String, int, java.lang.Class) */
@SuppressWarnings("unchecked")
public EntityIdentifier[] searchForEntities(String query, int method, Class type) throws GroupsException {
// only search for groups
if (type != IPerson.class) {
return new EntityIdentifier[] {};
}
List<EntityIdentifier> entityIdentifiers = new ArrayList<EntityIdentifier>();
try {
GcGetSubjects subjects = new GcGetSubjects();
subjects.assignIncludeSubjectDetail(true);
WsGetSubjectsResults results = subjects.assignSearchString(query).execute();
if (results != null && results.getWsSubjects() != null) {
for (WsSubject wsSubject : results.getWsSubjects()) {
entityIdentifiers.add(new EntityIdentifier(wsSubject.getName(), ICompositeGroupService.LEAF_ENTITY_TYPE));
}
}
return entityIdentifiers.toArray(new EntityIdentifier[entityIdentifiers.size()]);
} catch (Exception e) {
LOGGER.warn("Exception while attempting to retrieve " + "search results for query " + query + " and entity type " + type.getCanonicalName() + " : " + e.getMessage());
return new EntityIdentifier[] {};
}
}
use of org.apereo.portal.groups.GroupsException in project uPortal by Jasig.
the class PortletDefinitionSearcher method searchForEntities.
@Override
public EntityIdentifier[] searchForEntities(String query, int method) throws GroupsException {
boolean allowPartial = true;
switch(method) {
case IS:
allowPartial = false;
break;
case STARTS_WITH:
query = query + "%";
break;
case ENDS_WITH:
query = "%" + query;
break;
case CONTAINS:
query = "%" + query + "%";
break;
default:
throw new GroupsException("Unknown search type");
}
// get the list of matching portlet definitions
final List<IPortletDefinition> definitions = this.portletDefinitionRegistry.searchForPortlets(query, allowPartial);
if (log.isDebugEnabled()) {
log.debug("Found " + definitions.size() + " matching definitions for query " + query);
}
// initialize an appropriately-sized array of EntityIdentifiers
final EntityIdentifier[] identifiers = new EntityIdentifier[definitions.size()];
// add an identifier for each matching portlet
for (final ListIterator<IPortletDefinition> defIter = definitions.listIterator(); defIter.hasNext(); ) {
final IPortletDefinition definition = defIter.next();
identifiers[defIter.previousIndex()] = new EntityIdentifier(definition.getPortletDefinitionId().getStringId(), this.getType());
}
return identifiers;
}
use of org.apereo.portal.groups.GroupsException 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.GroupsException in project uPortal by Jasig.
the class SmartLdapGroupStore method searchForGroups.
public EntityIdentifier[] searchForGroups(String query, int method, Class leaftype) throws GroupsException {
if (isTreeRefreshRequired()) {
refreshTree();
}
log.debug("Invoking searchForGroups(): query={}, method={}, leaftype=", query, method, leaftype.getClass().getName());
// We only match the IPerson leaf type...
final IEntityGroup root = getRootGroup();
if (!leaftype.equals(root.getLeafType())) {
return new EntityIdentifier[0];
}
// We need to escape regex special characters that appear in the query string...
final String[][] specials = new String[][] { /* backslash must come first! */
new String[] { "\\", "\\\\" }, new String[] { "[", "\\[" }, /* closing ']' isn't needed b/c it's a normal character w/o a preceding '[' */
new String[] { "{", "\\{" }, /* closing '}' isn't needed b/c it's a normal character w/o a preceding '{' */
new String[] { "^", "\\^" }, new String[] { "$", "\\$" }, new String[] { ".", "\\." }, new String[] { "|", "\\|" }, new String[] { "?", "\\?" }, new String[] { "*", "\\*" }, new String[] { "+", "\\+" }, new String[] { "(", "\\(" }, new String[] { ")", "\\)" } };
for (String[] s : specials) {
query = query.replace(s[0], s[1]);
}
// Establish the regex pattern to match on...
String regex;
switch(method) {
case IGroupConstants.IS:
regex = query.toUpperCase();
break;
case IGroupConstants.STARTS_WITH:
regex = query.toUpperCase() + ".*";
break;
case IGroupConstants.ENDS_WITH:
regex = ".*" + query.toUpperCase();
break;
case IGroupConstants.CONTAINS:
regex = ".*" + query.toUpperCase() + ".*";
break;
default:
String msg = "Unsupported search method: " + method;
throw new GroupsException(msg);
}
List<EntityIdentifier> rslt = new LinkedList<>();
for (Map.Entry<String, List<String>> y : groupsTree.getKeysByUpperCaseName().entrySet()) {
if (y.getKey().matches(regex)) {
List<String> keys = y.getValue();
for (String k : keys) {
rslt.add(new EntityIdentifier(k, IEntityGroup.class));
}
}
}
return rslt.toArray(new EntityIdentifier[rslt.size()]);
}
use of org.apereo.portal.groups.GroupsException in project uPortal by Jasig.
the class GrouperEntityGroupStore method find.
/* (non-Javadoc)
* @see org.apereo.portal.groups.IEntityGroupStore#find(java.lang.String)
*/
public IEntityGroup find(String key) throws GroupsException {
try {
// key
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Searching Grouper for a direct match for key: " + key);
}
WsGroup wsGroup = findGroupFromKey(key);
if (wsGroup == null) {
return null;
}
IEntityGroup group = createUportalGroupFromGrouperGroup(wsGroup);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Retrieved group from the Grouper server matching key " + key + ": " + group.toString());
}
// return the group
return group;
} catch (Exception e) {
LOGGER.warn("Exception while attempting to retrieve " + "group with key " + key + " from Grouper web services: " + e.getMessage());
return null;
}
}
Aggregations