/** * Apply the 'search by role' filter to the lucene query string. * * @param parametersMap * @param filters */ protected void buildSearchByRoleQuery(Map<String, String> parametersMap, List<String> filters) { SearchableRole role = SearchableRole.valueOf(getSearchParam(parametersMap, REQUEST_PARAMETERS.role.toString())); String userid = getSearchParam(parametersMap, REQUEST_PARAMETERS.userid.toString()); AuthorizableManager authorizableManager = null; Session adminSession = null; try { adminSession = repository.loginAdministrative(); authorizableManager = adminSession.getAuthorizableManager(); Authorizable au = authorizableManager.findAuthorizable(userid); List<Authorizable> groups = AuthorizableUtil.getUserFacingGroups(au, authorizableManager); groups.add(au); List<String> groupStrs = new ArrayList<String>(groups.size()); for (Authorizable memberAuthz : groups) { groupStrs.add(ClientUtils.escapeQueryChars(memberAuthz.getId())); } filters.add(String.format(ROLE_TEMPLATE, role.toString(), JOINER_OR.join(groupStrs))); adminSession.logout(); } catch (ClientPoolException e) { throw new RuntimeException(e); } catch (StorageClientException e) { throw new RuntimeException(e); } catch (AccessDeniedException e) { throw new RuntimeException(e); } finally { SparseUtils.logoutQuietly(adminSession); } }
@Override public Query getQuery(Map<String, String> config) { // verify that we can determine a userid // 1) start with the remote user String userid = config.get("_userId"); // 2) revert to userid param if (config.containsKey("userid")) { userid = config.get("userid"); } // 3) finally, use Anonymous if no userid is present if (userid == null) { userid = User.ANON_USER; } // verify there is a valid role specified String roleStr = config.get(REQUEST_PARAMETERS.role.toString()); if (roleStr != null) { try { SearchableRole.valueOf(roleStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Provided role parameter is not a valid role: " + roleStr, e); } } else { throw new MissingParameterException("Required parameter 'role' was not found."); } // need to ensure non-escaped parameters get set for userid config.put(REQUEST_PARAMETERS.userid.toString(), userid); return super.getQuery(config); }
/** * @deprecated {@inheritDoc} * @see * org.sakaiproject.nakamura.api.search.solr.SolrSearchPropertyProvider#loadUserProperties(org.apache.sling.api.SlingHttpServletRequest, * java.util.Map) */ @Override public void loadUserProperties( SlingHttpServletRequest request, Map<String, String> propertiesMap) { // verify that we can determine a userid String userid = SearchRequestUtils.getUser(request); if (userid == null) { userid = User.ANON_USER; } // verify there is a valid role specified String roleStr = propertiesMap.get(REQUEST_PARAMETERS.role.toString()); if (roleStr != null) { try { SearchableRole.valueOf(roleStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Provided role parameter is not a valid role: " + roleStr, e); } } else { throw new MissingParameterException("Required parameter 'role' was not found."); } // need to ensure non-escaped parameters get set for userid propertiesMap.put(REQUEST_PARAMETERS.userid.toString(), userid); propertiesMap.put(TEMPLATE_PROPS._q.toString(), configureQString(propertiesMap)); }