Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Fixes a number of bugs in the initial effort. Things appear to work e…
Browse files Browse the repository at this point in the history
…xcellent with initial testing now
  • Loading branch information
GraylinKim committed Dec 17, 2010
1 parent dcacdd6 commit 59d7230
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 69 deletions.
Expand Up @@ -72,7 +72,7 @@ private boolean isApproved(String permissions) {
TreeSet<String> user_credentials = user.getCredentials();

//Break the permissions up and check for matches
for(String temp : permissions.split(" "))
for(String temp : SerialUtils.loadStringSet(permissions))
if(user_credentials.contains(temp) == true)
return true;

Expand Down
Expand Up @@ -39,14 +39,14 @@ public SecureQueryParser(String qstr, SolrParams localParams, SolrParams params,

public static String secureQuery(String query,String credential) {
String newQuery = "";
TreeSet<String> basics = new TreeSet<String>(Arrays.asList("uid","otype"));
TreeSet<String> basics = new TreeSet<String>(Arrays.asList("uid","otype","firstName","lastName","fullName"));
Pattern p = Pattern.compile("(.*?)(\\w+):((?:\\(.+?\\))|(?:\\[.+?\\])|\\w+|(?:\"[\\w ]+\"))([\\) ]*)?");
Matcher m = p.matcher(query);
while(m.find()) {
if(basics.contains(m.group(2)))
newQuery += m.group(1)+m.group(2)+":"+m.group(3);
else
newQuery += m.group(1)+"("+m.group(2)+":"+m.group(3)+" AND "+m.group(2)+"_access:"+credential+")"+m.group(4);
newQuery += m.group(1)+"("+m.group(2)+":"+m.group(3)+" AND "+m.group(2)+"_access:("+credential+") )"+m.group(4);
}
System.out.println("Transformed Query: "+newQuery);
return newQuery;
Expand Down
Expand Up @@ -74,6 +74,6 @@ public void writeSecureField(SolrInputDocument doc, String name, String value, H

//Add a permissions field for it with no impact on search ranking
//(I'm not actually sure that's what boost does, we should look it up.
doc.addField(name+"_access", SerialUtils.writeStringSet(field_permissions)+" admin", 0f);
doc.addField(name+"_access", SerialUtils.writeStringSet(field_permissions), 0f);
}
}
Expand Up @@ -61,7 +61,7 @@ public Person loadPersonByUid(String uid) {
public ArrayList<Person> loadPeopleByQuery(String query) {

String creds = SerialUtils.writeStringSet(user.getCredentials());
query = "{!secure credential:"+creds+"}"+query;
query = "{!secure credential=\""+creds+"\"}"+query;

System.out.println("\nLoading People By Query: "+query);
System.out.println("===============================================");
Expand Down
67 changes: 3 additions & 64 deletions src/main/java/gov/nysenate/opendirectory/utils/SerialUtils.java
Expand Up @@ -4,58 +4,23 @@
import gov.nysenate.opendirectory.solr.SolrSession;

import java.util.Arrays;
import java.util.HashMap;
import java.util.TreeSet;

public class SerialUtils {

public static void main(String[] args) {

String sethash = "uid:public:phone:public senate:permissions:admin:phone2:senate";
String stringset = "javascript python soccer";
String stringhash = "bush2:Annabel Bush:williams:Jared Williams:hoppin:Andrew Hoppin";

//Test the set hash loader
HashMap<String, TreeSet<String>> perms = loadSetHash(sethash);
for(String key : perms.keySet()) {
System.out.println(key+": "+perms.get(key).toString());
}
String stringset = "javascript, python, soccer";

//Test the string set loader
System.out.println(loadStringSet(stringset).toString());

//test the string hash loader
HashMap<String, String> bookmarks = loadStringHash(stringhash);
for(String key : bookmarks.keySet()) {
System.out.println(key+": "+bookmarks.get(key));
}
}

public static HashMap<String,String> loadStringHash(String str) {
HashMap<String,String> map = new HashMap<String,String>();
if(str!=null && !str.isEmpty()) {
String[] parts = str.split(":");
for(int i=0; i<parts.length-1; i+=2) {
map.put(parts[i],parts[i+1]);
}
}
return map;
}

public static HashMap<String,TreeSet<String>> loadSetHash(String str) {
HashMap<String,TreeSet<String>> map = new HashMap<String,TreeSet<String>>();
if(str!=null && !str.isEmpty()) {
String[] parts = str.split(":");
for(int i=0; i<parts.length-1; i+=2)
map.put(parts[i], loadStringSet(parts[i+1]));
}
return map;
}

public static TreeSet<String> loadStringSet(String str) {
if(str==null || str.isEmpty())
return new TreeSet<String>();
return new TreeSet<String>(Arrays.asList(str.split(" ")));
return new TreeSet<String>(Arrays.asList(str.split(", ")));
}

public static TreeSet<Person> loadBookmarks(String str,Person person, SolrSession session) {
Expand All @@ -76,40 +41,14 @@ public static TreeSet<Person> loadBookmarks(String str,Person person, SolrSessio

return new TreeSet<Person>(session.loadPeopleByQuery(query));
}

public static String writeStringHash(HashMap<String, String> map) {
if(map==null)
return "";

String str = "";
for(String key : map.keySet()) {
if(!str.isEmpty())
str+=":";
str+=key+":"+map.get(key);
}
return str;
}

public static String writeSetHash(HashMap<String, TreeSet<String>> map) {
if(map==null)
return "";

String str = "";
for(String key : map.keySet()) {
if(!str.isEmpty())
str+=":";
str+=key+":"+writeStringSet(map.get(key));
}
return str;
}

public static String writeStringSet(TreeSet<String> set) {
if(set == null)
return "";

String str = "";
for(String s : set)
str += s+" ";
str += s+", ";

return str;
}
Expand Down

0 comments on commit 59d7230

Please sign in to comment.