ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject [5/9] git commit: ARGUS-64
Date Fri, 19 Sep 2014 21:32:56 GMT
ARGUS-64

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

Branch: refs/heads/master
Commit: a6f5be8a7b7d7a4daa3358d386d2a5467bb6bebf
Parents: 5c29ec2
Author: rmani <rmani@hortonworks.com>
Authored: Tue Sep 16 18:21:13 2014 -0700
Committer: rmani <rmani@hortonworks.com>
Committed: Tue Sep 16 18:21:13 2014 -0700

----------------------------------------------------------------------
 .../com/xasecure/pdp/config/ConfigWatcher.java  | 12 +++-
 .../xasecure/pdp/config/PolicyRefresher.java    | 68 +++++++++++++-------
 2 files changed, 54 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/a6f5be8a/agents-impl/src/main/java/com/xasecure/pdp/config/ConfigWatcher.java
----------------------------------------------------------------------
diff --git a/agents-impl/src/main/java/com/xasecure/pdp/config/ConfigWatcher.java b/agents-impl/src/main/java/com/xasecure/pdp/config/ConfigWatcher.java
index e286cfb..f510328 100644
--- a/agents-impl/src/main/java/com/xasecure/pdp/config/ConfigWatcher.java
+++ b/agents-impl/src/main/java/com/xasecure/pdp/config/ConfigWatcher.java
@@ -92,6 +92,7 @@ public abstract class ConfigWatcher extends Thread {
 
 	private static XaSecureCredentialProvider xasecurecp = null;
 	
+	
 	public abstract void doOnChange();
 	
 	private String keyStoreFile =  null ;
@@ -110,7 +111,9 @@ public abstract class ConfigWatcher extends Thread {
 	
 	private String sslConfigFileName = null ;
 	
-	boolean policyCacheLoadedOnce = false;
+	public boolean policyCacheLoadedOnce = false;
+	
+	public boolean cacheModfied = false;
 
 	public ConfigWatcher(String url, long aIntervalInMilliSeconds,String sslConfigFileName,String
lastStoredFileName) {
 		super("XaSecureConfigURLWatcher");
@@ -227,11 +230,15 @@ public abstract class ConfigWatcher extends Thread {
 			LOG.debug("No Change found in the policy from " + url);
 		}
 	}
+	
+	public boolean iscacheModfied() {
+		   return cacheModfied;
+	}
 
 	private boolean isFileChanged() {
 		boolean isChanged = false;
 		
-		
+		cacheModfied = false;
 		try {	
 			
 			Client client = null;
@@ -278,6 +285,7 @@ public abstract class ConfigWatcher extends Thread {
 									lastModifiedTime = policyContainer.getLastUpdatedTimeInEpoc();
 									isChanged = true;
 									policyCacheLoadedOnce = false;
+									cacheModfied = true;
 									if (LOG.isDebugEnabled()) {
 										LOG.debug("Got response: 200 with {change in lastupdatedTime}\n" + gson.toJson(newPolicyContainer));
 									}

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/a6f5be8a/agents-impl/src/main/java/com/xasecure/pdp/config/PolicyRefresher.java
----------------------------------------------------------------------
diff --git a/agents-impl/src/main/java/com/xasecure/pdp/config/PolicyRefresher.java b/agents-impl/src/main/java/com/xasecure/pdp/config/PolicyRefresher.java
index 0b1f38e..c1db8ac 100644
--- a/agents-impl/src/main/java/com/xasecure/pdp/config/PolicyRefresher.java
+++ b/agents-impl/src/main/java/com/xasecure/pdp/config/PolicyRefresher.java
@@ -76,6 +76,7 @@ public class PolicyRefresher  {
 		this.policyChangeListener = policyChangeListener;
 		if (this.policyContainer != null) {
 			savePolicyToFile() ;
+			savePolicyToCacheFile();
 			notifyPolicyChange() ;
 		}
 	}
@@ -124,6 +125,7 @@ public class PolicyRefresher  {
 						PolicyContainer newPolicyContainer = getPolicyContainer() ;
 						setPolicyContainer(newPolicyContainer) ;
 						savePolicyToFile() ;
+						savePolicyToCacheFile();
 						notifyPolicyChange(); 
 					};
 				};
@@ -153,7 +155,10 @@ public class PolicyRefresher  {
 	
 	
 	private void savePolicyToFile() {
-		
+		if (!watcherDaemon.iscacheModfied()) {
+			// Do not Save the file if the policy is not modified.
+			return;
+		}
 		LOG.debug("savePolicyToFile() is called with [" + saveAsFileName + "] - START") ;
 		String fileName = null;
 		if (saveAsFileName != null) {
@@ -175,31 +180,46 @@ public class PolicyRefresher  {
 					writer.close();
 				}
 			}
-			
-			if (lastStoredFileName != null) {
-				File lastSaveFileName = new File(lastStoredFileName);
-								
-				try {
-					writer = new PrintWriter(new FileWriter(lastSaveFileName));
-					writer.println(policyAsJson);
-					
-				}
-				catch(IOException ioe){
-					LOG.error("Unable to save the policy into Last Stored Policy File [" + lastSaveFileName.getAbsolutePath()
+ "]", ioe );
-				}
-			    finally {
-			    	 //make the policy file cache to be 600 permission when it gets created and updated
-			    	 lastSaveFileName.setReadable(false,false);
-					 lastSaveFileName.setReadable(true,true);
-			    	 if (writer != null) {
-					 writer.close();
-			    	}
-			    }
-			
-		     }
+			LOG.debug("savePolicyToFile() is called with [" + fileName + "] - END") ;
 		}
+	}	
+	
+	 private void savePolicyToCacheFile() {
+		 
+		 if (!watcherDaemon.iscacheModfied()) {
+			    // Don't Save the file if the policy is not modified.
+				return;
+		  }
+		 
+		 LOG.debug("savePolicyToCacheFile() is called with [" + lastStoredFileName + "] - START")
;
 		
-		LOG.debug("savePolicyToFile() is called with [" + fileName + "] - END") ;
+   		 if (lastStoredFileName != null) {
+   		
+			File lastSaveFile = new File(lastStoredFileName) ;
+			Gson gson = new GsonBuilder().setPrettyPrinting().setExclusionStrategies(policyExclusionStrategy).create()
;
+			String policyAsJson = gson.toJson(policyContainer) ;
+			PrintWriter writer = null ;
+										
+			try {
+				writer = new PrintWriter(new FileWriter(lastSaveFile));
+				writer.println(policyAsJson);
+				
+			}
+			catch(IOException ioe){
+				LOG.error("Unable to save the policy into Last Stored Policy File [" + lastSaveFile.getAbsolutePath()
+ "]", ioe );
+			}
+		    finally {
+		    	 //make the policy file cache to be 600 permission when it gets created and updated
+		    	 lastSaveFile.setReadable(false,false);
+		    	 lastSaveFile.setReadable(true,true);
+		    	 if (writer != null) {
+				 writer.close();
+		    	}
+		    }
+			
+		  }
+
+		LOG.debug("savePolicyToCacheFile() is called with [" + lastStoredFileName + "] - END")
;
 
 	}	
 


Mime
View raw message