You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2012/03/29 17:27:51 UTC
svn commit: r1306913 -
/incubator/wookie/trunk/src/org/apache/wookie/server/security/ApiKeys.java
Author: scottbw
Date: Thu Mar 29 15:27:50 2012
New Revision: 1306913
URL: http://svn.apache.org/viewvc?rev=1306913&view=rev
Log:
Made a number of improvements to the ApiKeys class to ensure file consistency, including adding read locks as well as write locks, and turning off AutoSave explicitly.
Modified:
incubator/wookie/trunk/src/org/apache/wookie/server/security/ApiKeys.java
Modified: incubator/wookie/trunk/src/org/apache/wookie/server/security/ApiKeys.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/server/security/ApiKeys.java?rev=1306913&r1=1306912&r2=1306913&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/server/security/ApiKeys.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/server/security/ApiKeys.java Thu Mar 29 15:27:50 2012
@@ -57,6 +57,7 @@ public class ApiKeys {
keys = new HashMap<String, ApiKey>();
properties = new PropertiesConfiguration("keys");
properties.setReloadingStrategy(reloader);
+ properties.setAutoSave(false);
load();
} catch (ConfigurationException e) {
logger.error("Problem initializing the API Keys from configuration", e);
@@ -77,10 +78,15 @@ public class ApiKeys {
* if the file needs to be reloaded
*/
private void refresh(){
- if (reloader.reloadingRequired()){
- keys.clear();
- load();
- reloader.reloadingPerformed();
+ lock.lock();
+ try{
+ if (reloader.reloadingRequired()){
+ keys.clear();
+ load();
+ reloader.reloadingPerformed();
+ }
+ } finally {
+ lock.unlock();
}
}
@@ -93,13 +99,14 @@ public class ApiKeys {
try {
properties.clear();
properties.load();
-
+ keys.clear();
@SuppressWarnings("rawtypes")
Iterator keys = properties.getKeys();
while(keys.hasNext()){
String key = (String)keys.next();
String email = properties.getString(key);
- addKeyToCollection(key,email);
+ ApiKey apiKey = new ApiKey(key, email);
+ this.keys.put(apiKey.getValue(), apiKey);
}
} catch (ConfigurationException e) {
logger.error("Error loading API Keys from the keys file", e);
@@ -162,7 +169,9 @@ public class ApiKeys {
if (addKeyToCollection(key, email)){
lock.lock();
try {
+ properties.clearProperty(key);
properties.addProperty(key, email);
+ properties.save();
} finally {
lock.unlock();
}
@@ -182,6 +191,15 @@ public class ApiKeys {
public void removeKey(String key) throws ResourceNotFoundException{
if (keys.containsKey(key)){
keys.remove(key);
+ lock.lock();
+ try{
+ properties.clearProperty(key);
+ properties.save();
+ } catch (ConfigurationException e) {
+ logger.error("Problem with keys properties configuration", e);
+ } finally {
+ lock.unlock();
+ }
} else {
throw new ResourceNotFoundException();
}