You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by rm...@apache.org on 2011/01/28 14:58:41 UTC

svn commit: r1064676 - /incubator/isis/trunk/alternatives/security/file/src/main/java/org/apache/isis/alternatives/security/file/authorization/FileAuthorizor.java

Author: rmatthews
Date: Fri Jan 28 13:58:41 2011
New Revision: 1064676

URL: http://svn.apache.org/viewvc?rev=1064676&view=rev
Log:
Fixed natural naming of classes 

Modified:
    incubator/isis/trunk/alternatives/security/file/src/main/java/org/apache/isis/alternatives/security/file/authorization/FileAuthorizor.java

Modified: incubator/isis/trunk/alternatives/security/file/src/main/java/org/apache/isis/alternatives/security/file/authorization/FileAuthorizor.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/alternatives/security/file/src/main/java/org/apache/isis/alternatives/security/file/authorization/FileAuthorizor.java?rev=1064676&r1=1064675&r2=1064676&view=diff
==============================================================================
--- incubator/isis/trunk/alternatives/security/file/src/main/java/org/apache/isis/alternatives/security/file/authorization/FileAuthorizor.java (original)
+++ incubator/isis/trunk/alternatives/security/file/src/main/java/org/apache/isis/alternatives/security/file/authorization/FileAuthorizor.java Fri Jan 28 13:58:41 2011
@@ -46,7 +46,7 @@ import org.apache.isis.core.runtime.auth
 import org.apache.log4j.Logger;
 
 
-public class FileAuthorizor extends AuthorizorAbstract {
+public class FileAuthorizor extends AuthorizorAbstract implements FileAuthorizorMBean {
 
     private static final Logger LOG = Logger.getLogger(FileAuthorizor.class);
 
@@ -54,18 +54,17 @@ public class FileAuthorizor extends Auth
     private static final String RO = "-ro";
     private static final String RW = "-rw";
     
-
-    private final Map<String,List<String>> whiteListMap = new HashMap<String,List<String>>();
-    private final Map<String,List<String>> blackListMap = new HashMap<String,List<String>>();
+    private Map<String,List<String>> whiteListMap;
+    private Map<String,List<String>> blackListMap;
     
     private final ResourceStreamSource resourceStreamSource;
     private final boolean learn;
     
     private final String whiteListResourceName;
-    private final InputStream whiteListInputResource;
+    private InputStream whiteListInputResource;
     
     private final String blackListResourceName;
-    private final InputStream blackListInputResource;
+    private InputStream blackListInputResource;
 
     private boolean printedWarning;
     private boolean printedDebug;
@@ -76,25 +75,31 @@ public class FileAuthorizor extends Auth
         // read from config
     	this.resourceStreamSource = getConfiguration().getResourceStreamSource();
         
+    	this.learn = getConfiguration().getBoolean(FileAuthorizationConstants.LEARN, FileAuthorizationConstants.LEARN_DEFAULT);
         whiteListResourceName = getConfiguration().getString(FileAuthorizationConstants.WHITELIST_RESOURCE_KEY,FileAuthorizationConstants.WHITELIST_RESOURCE_DEFAULT);
         Assert.assertTrue(whiteListResourceName.length() > 0);
+        blackListResourceName = getConfiguration().getString(FileAuthorizationConstants.BLACKLIST_RESOURCE, FileAuthorizationConstants.BLACKLIST_RESOURCE_DEFAULT);
+        
+        findResources();
+        
+        BeanServer.getInstance().register("FileAuthorizor", this);
+    }
+
+
+    private void findResources() {
         whiteListInputResource = resourceStreamSource.readResource(whiteListResourceName);
-        
-        this.learn = getConfiguration().getBoolean(FileAuthorizationConstants.LEARN, FileAuthorizationConstants.LEARN_DEFAULT);
         if (whiteListInputResource == null) {
             throw new IsisException("Cannot read whitelist authorization file: " + whiteListResourceName);
         }
         
-        blackListResourceName = getConfiguration().getString(FileAuthorizationConstants.BLACKLIST_RESOURCE, FileAuthorizationConstants.BLACKLIST_RESOURCE_DEFAULT);
         if (blackListResourceName.length() > 0) {
             this.blackListInputResource = resourceStreamSource.readResource(blackListResourceName);
             if (blackListInputResource == null) {
-                // ... but if it's there we should be able to read it
-                throw new IsisException("Cannot read blacklist authorization file: " + blackListResourceName);
+                throw new IsisException("Blacklist authorization file exists, but it cannot be read: " + blackListResourceName);
             }
         } else {
         	blackListInputResource = null;
-        }
+        }
     }
 
     
@@ -108,11 +113,26 @@ public class FileAuthorizor extends Auth
         // initialize
         if (learn) {
             return;
-        }
+        }
+        whiteListMap = new HashMap<String,List<String>>();
+        blackListMap = new HashMap<String,List<String>>();
         cacheAuthorizationDetails(whiteListMap, whiteListInputResource);
         if (blackListInputResource != null) {
             cacheAuthorizationDetails(blackListMap, blackListInputResource);
-        }
+        }
+    }
+
+    public void reload() {
+        Map<String,List<String>> whiteListMap = new HashMap<String,List<String>>();
+        Map<String,List<String>> blackListMap = new HashMap<String,List<String>>();
+
+        findResources();
+        cacheAuthorizationDetails(whiteListMap, whiteListInputResource);
+        if (blackListInputResource != null) {
+            cacheAuthorizationDetails(blackListMap, blackListInputResource);
+            this.blackListMap = blackListMap;
+        }
+        this.whiteListMap = whiteListMap;
     }
 
 
@@ -144,7 +164,7 @@ public class FileAuthorizor extends Auth
         final String token2 = tokens.nextToken();
         final Identifier identifier = memberFromString(token1.trim());
         final List<String> roles = tokenizeRoles(token2);
-        String identityString = identifier.toIdentityString(Identifier.CLASS_MEMBERNAME_PARMS);
+        String identityString = identifier.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS);
         map.put(identityString, roles);
     }
 
@@ -211,7 +231,7 @@ public class FileAuthorizor extends Auth
         if (isQualifiedMatch(map, role, identifier.toIdentityString(Identifier.CLASS_MEMBERNAME), qualifiers)) {
         	return true;
         }
-        if (isQualifiedMatch(map, role, identifier.toIdentityString(Identifier.CLASS_MEMBERNAME_PARMS), qualifiers)) {
+        if (isQualifiedMatch(map, role, identifier.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS), qualifiers)) {
         	return true;
         }
         return false;
@@ -231,7 +251,7 @@ public class FileAuthorizor extends Auth
     }
 
     private boolean learn(final String role, final Identifier member) {
-        String identityString = member.toIdentityString(Identifier.CLASS_MEMBERNAME_PARMS);
+        String identityString = member.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS);
         if (whiteListMap.containsKey(identityString)) {
             final List<String> roles = whiteListMap.get(identityString);
             if (!roles.contains(role)) {