use of org.apereo.portal.groups.GroupsException in project uPortal by Jasig.
the class PortletDefinitionSearcher method searchForEntities.
// Internal search, so shouldn't be called as case insensitive.
@Override
public EntityIdentifier[] searchForEntities(String query, SearchMethod method) throws GroupsException {
boolean allowPartial = true;
switch(method) {
case DISCRETE:
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 SmartLdapGroupStore method searchForGroups.
// Treats case sensitive and case insensitive searching the same.
public EntityIdentifier[] searchForGroups(String query, SearchMethod method, Class leaftype) throws GroupsException {
if (isTreeRefreshRequired()) {
refreshTree();
}
log.debug("Invoking searchForGroups(): query={}, method={}, leaftype=", query, method, leaftype.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 DISCRETE:
case DISCRETE_CI:
regex = query.toUpperCase();
break;
case STARTS_WITH:
case STARTS_WITH_CI:
regex = query.toUpperCase() + ".*";
break;
case ENDS_WITH:
case ENDS_WITH_CI:
regex = ".*" + query.toUpperCase();
break;
case CONTAINS:
case CONTAINS_CI:
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 AuthorizationImpl method getInheritedPrincipals.
/**
* Hook into the Groups system, find all containing groups, and convert the them to <code>
* IAuthorizationPrincipals</code>.
*
* @param principal - org.apereo.portal.security.IAuthorizationPrincipal
* @return java.util.Iterator over Collection of IEntityGroups
*/
private Iterator getInheritedPrincipals(IAuthorizationPrincipal principal) throws AuthorizationException {
Iterator i = null;
ArrayList<IAuthorizationPrincipal> al = new ArrayList<>(5);
try {
i = getGroupsForPrincipal(principal);
} catch (GroupsException ge) {
throw new AuthorizationException("Could not retrieve Groups for " + principal, ge);
}
while (i.hasNext()) {
IEntityGroup group = (IEntityGroup) i.next();
IAuthorizationPrincipal p = getPrincipalForGroup(group);
al.add(p);
}
return al.iterator();
}
Aggregations