incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject git commit: Added in the ability to specify global user if using security in Blur
Date Sat, 07 Jun 2014 12:24:30 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 5fa8c6480 -> 4a4338af2


Added in the ability to specify global user if using security in Blur


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/4a4338af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/4a4338af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/4a4338af

Branch: refs/heads/apache-blur-0.2
Commit: 4a4338af2408f7ae5fffc903c381ff999d8edae4
Parents: 5fa8c64
Author: Chris Rohr <rohr.chris@gmail.com>
Authored: Sat Jun 7 08:24:25 2014 -0400
Committer: Chris Rohr <rohr.chris@gmail.com>
Committed: Sat Jun 7 08:24:25 2014 -0400

----------------------------------------------------------------------
 .../blur/console/servlets/SearchServlet.java    |  7 +--
 .../org/apache/blur/console/util/Config.java    | 53 ++++++++++++--------
 .../apache/blur/console/util/SearchUtil.java    | 51 +++++++------------
 3 files changed, 55 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4a4338af/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
index 1697d59..c7abcef 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
@@ -38,17 +38,18 @@ public class SearchServlet extends BaseConsoleServlet {
 	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
 		String path = request.getPathInfo();
 		if (path == null) {
-			sendSearch(response, request.getParameterMap());
+			String remoteHost = request.getRemoteHost();
+			sendSearch(response, request.getParameterMap(), remoteHost);
 		} else {
 			response.setStatus(404);
 			IOUtils.write("Route [" + path + "] doesn't exist", response.getOutputStream());
 		}
 	}
 	
-	private void sendSearch(HttpServletResponse response, Map<String, String[]> params)
throws IOException {
+	private void sendSearch(HttpServletResponse response, Map<String, String[]> params,
String remoteHost) throws IOException {
 		Map<String, Object> results = new HashMap<String, Object>();
 		try {
-			results = SearchUtil.search(params);
+			results = SearchUtil.search(params, remoteHost);
 		} catch (IOException e) {
 			throw new IOException(e);
 		} catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4a4338af/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
index cd9ca18..3b98267 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.blur.BlurConfiguration;
 import org.apache.blur.manager.clusterstatus.ZookeeperClusterStatus;
@@ -29,16 +30,22 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
 
 public class Config {
 	private static final File TMPDIR = new File(System.getProperty("blur.tmp.dir", "./target/mini-cluster"));
 	private static final Log log = LogFactory.getLog(Config.class);
 	
-	private static int port = 8080;
+	private static int port;
 	private static BlurConfiguration blurConfig;
 	private static ZookeeperClusterStatus zk;
 	private static String blurConnection;
 	private static Object cluster;
+	private static Map<String, String> globalUserProperties;
 
 	public static int getConsolePort() {
 		return port;
@@ -46,6 +53,9 @@ public class Config {
 	public static BlurConfiguration getBlurConfig() {
 		return blurConfig;
 	}
+	public static Map<String, String> getUserProperties() {
+		return globalUserProperties;
+	}
 	
 	public static void setupConfig() throws IOException {
 		if (cluster == null) {
@@ -65,6 +75,27 @@ public class Config {
 		}
 		zk = new ZookeeperClusterStatus(blurConfig.get("blur.zookeeper.connection"), blurConfig);
 		blurConnection = buildConnectionString();
+		port = blurConfig.getInt("blur.console.port", 8080);
+		parseSecurity();
+	}
+	
+	private static void parseSecurity() {
+		String securityFile = blurConfig.get("blur.console.security.file");
+		
+		if (securityFile != null) {
+			JsonFactory factory = new JsonFactory(); 
+		    ObjectMapper mapper = new ObjectMapper(factory); 
+		    File from = new File(securityFile); 
+		    TypeReference<Map<String,String>> typeRef 
+		            = new TypeReference<Map<String,String>>() {};
+
+		    try {
+				globalUserProperties = mapper.readValue(from, typeRef);
+			} catch (Exception e) {
+				log.error("Unable to parse security file.  Search may not work right.", e);
+				globalUserProperties = null;
+			} 
+		}
 	}
 	
 	public static String getConnectionString() throws IOException {
@@ -89,7 +120,6 @@ public class Config {
 			} catch (Exception e) {
 				log.fatal("Unable to stop mini cluster through reflection.", e);
 			}
-//			cluster.shutdownBlurCluster();
 			File file = new File(TMPDIR, "blur-cluster-test");
 			if (file.exists()) {
 				FileUtils.deleteDirectory(file);
@@ -98,25 +128,11 @@ public class Config {
 	}
 	
 	
-	@SuppressWarnings("unchecked")
+	@SuppressWarnings({ "unchecked", "rawtypes" })
 	public static void setupMiniCluster() throws IOException {
-//		GCWatcher.init(0.60);
-//	    LocalFileSystem localFS = FileSystem.getLocal(new Configuration());
 	    File testDirectory = new File(TMPDIR, "blur-cluster-test").getAbsoluteFile();
 	    testDirectory.mkdirs();
 
-//	    Path directory = new Path(testDirectory.getPath());
-//	    FsPermission dirPermissions = localFS.getFileStatus(directory).getPermission();
-//	    FsAction userAction = dirPermissions.getUserAction();
-//	    FsAction groupAction = dirPermissions.getGroupAction();
-//	    FsAction otherAction = dirPermissions.getOtherAction();
-//
-//	    StringBuilder builder = new StringBuilder();
-//	    builder.append(userAction.ordinal());
-//	    builder.append(groupAction.ordinal());
-//	    builder.append(otherAction.ordinal());
-//	    String dirPermissionNum = builder.toString();
-//	    System.setProperty("dfs.datanode.data.dir.perm", dirPermissionNum);
 	    testDirectory.delete();
 	    try {
 	    	Class clusterClass = Class.forName("org.apache.blur.MiniCluster", false, Config.class.getClassLoader());
@@ -130,8 +146,5 @@ public class Config {
 	    	log.fatal("Unable to start in dev mode because MiniCluster isn't in classpath", e);
 	    	cluster = null;
 	    }
-//	    cluster = ConstructorUtils.in
-//	    cluster = new MiniCluster();
-//	    cluster.startBlurCluster(new File(testDirectory, "cluster").getAbsolutePath(), 2,
3, true);
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4a4338af/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
b/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
index d19ead7..ccf66d2 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
@@ -26,6 +26,7 @@ import org.apache.blur.thrift.generated.Record;
 import org.apache.blur.thrift.generated.Row;
 import org.apache.blur.thrift.generated.ScoreType;
 import org.apache.blur.thrift.generated.Selector;
+import org.apache.blur.thrift.generated.User;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 
@@ -54,33 +55,7 @@ public class SearchUtil {
 	private static final String ROW_ROW_OPTION = "rowrow";
 	private static final String RECORD_RECORD_OPTION = "recordrecord";
 	
-	/**
-	 * Record only results:
-	 * 
-	 * {
-	 * 	famName: [
-	 * 		{
-	 * 			colName: value
-	 * 		}
-	 * 	]
-	 * }
-	 * 
-	 * Row results:
-	 * {
-	 * 	famName: [ 
-	 * 		{
-	 * 			rowid: rowid,
-	 * 			records: [
-	 * 				{
-	 * 					colName: value
-	 * 				}
-	 * 			]
-	 * 		}
-	 * 	]
-	 * }
-	 */
-	
-	public static Map<String, Object> search(Map<String, String[]> params) throws
IOException, BlurException, TException {
+	public static Map<String, Object> search(Map<String, String[]> params, String
remoteHost) throws IOException, BlurException, TException {
 		String table = params.get("table")[0];
 		String query = params.get("query")[0];
 		String rowQuery = params.get("rowRecordOption")[0];
@@ -89,23 +64,24 @@ public class SearchUtil {
 		String[] families = params.get("families[]");
 		
 		if (families == null || families.length == 0) {
-			return fullTextSearch(table, query);
+			return fullTextSearch(table, query, remoteHost);
 		}
 		
 		if (ArrayUtils.contains(families, "rowid")) {
-			return fetchRow(table, query, families);
+			return fetchRow(table, query, families, remoteHost);
 		}
 		
 		if (ArrayUtils.contains(families, "recordid")) {
 			return fetchRecord(table, query, families);
 		}
 		
-		return searchAndFetch(table, query, rowQuery, start, fetch, families);
+		return searchAndFetch(table, query, rowQuery, start, fetch, families, remoteHost);
 	}
 	
 	@SuppressWarnings({ "unchecked", "rawtypes" })
-	private static Map<String, Object> searchAndFetch(String table, String query, String
rowQuery, String start, String fetch, String[] families) throws IOException, BlurException,
TException {
+	private static Map<String, Object> searchAndFetch(String table, String query, String
rowQuery, String start, String fetch, String[] families, String remoteHost) throws IOException,
BlurException, TException {
 		Iface client = BlurClient.getClient(Config.getConnectionString());
+		setUser(client, remoteHost);
 		
 		boolean recordsOnly = RECORD_RECORD_OPTION.equalsIgnoreCase(rowQuery);
 		
@@ -166,8 +142,9 @@ public class SearchUtil {
 		return results;
 	}
 	
-	private static Map<String, Object> fullTextSearch(String table, String query) throws
IOException, BlurException, TException {
+	private static Map<String, Object> fullTextSearch(String table, String query, String
remoteHost) throws IOException, BlurException, TException {
 		Iface client = BlurClient.getClient(Config.getConnectionString());
+		setUser(client, remoteHost);
 		
 		BlurQuery blurQuery = new BlurQuery();
 		
@@ -181,8 +158,10 @@ public class SearchUtil {
 	}
 	
 	@SuppressWarnings({ "unchecked", "rawtypes" })
-	private static Map<String, Object> fetchRow(String table, String query, String[] families)
throws IOException, BlurException, TException {
+	private static Map<String, Object> fetchRow(String table, String query, String[] families,
String remoteHost) throws IOException, BlurException, TException {
 		Iface client = BlurClient.getClient(Config.getConnectionString());
+		setUser(client, remoteHost);
+		
 		Selector selector = new Selector();
 		String rowid = StringUtils.remove(query, "rowid:");
 		selector.setRowId(rowid);
@@ -258,4 +237,10 @@ public class SearchUtil {
 		
 		return row;
 	}
+	
+	private static void setUser(Iface client, String username) throws TException {
+		if (Config.getUserProperties() != null) {
+			client.setUser(new User(username, Config.getUserProperties()));
+		}
+	}
 }


Mime
View raw message