incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1098668 - in /incubator/isis/trunk/security/file/src: main/java/org/apache/isis/security/file/authentication/ main/java/org/apache/isis/security/file/authorization/ site/apt/
Date Mon, 02 May 2011 17:18:37 GMT
Author: danhaywood
Date: Mon May  2 17:18:36 2011
New Revision: 1098668

URL: http://svn.apache.org/viewvc?rev=1098668&view=rev
Log:
ISIS-33: code cleanup, site APT docs

Modified:
    incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationConstants.java
    incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationManagerInstaller.java
    incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticator.java
    incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationConstants.java
    incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationManagerInstaller.java
    incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizor.java
    incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizorMBean.java
    incubator/isis/trunk/security/file/src/site/apt/index.apt

Modified: incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationConstants.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationConstants.java?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationConstants.java
(original)
+++ incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationConstants.java
Mon May  2 17:18:36 2011
@@ -17,13 +17,13 @@
  *  under the License.
  */
 
+package org.apache.isis.security.file.authentication;
 
-package org.apache.isis.security.file.authentication;
-
-public class FileAuthenticationConstants {
-	
-	public static final String PASSWORDS_FILE = "security_file.passwords";
-
-	private FileAuthenticationConstants() {}
-
-}
+public class FileAuthenticationConstants {
+
+    public static final String PASSWORDS_FILE = "security_file.passwords";
+
+    private FileAuthenticationConstants() {
+    }
+
+}

Modified: incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationManagerInstaller.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationManagerInstaller.java?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationManagerInstaller.java
(original)
+++ incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticationManagerInstaller.java
Mon May  2 17:18:36 2011
@@ -17,28 +17,23 @@
  *  under the License.
  */
 
+package org.apache.isis.security.file.authentication;
 
-package org.apache.isis.security.file.authentication;
-
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.runtime.authentication.standard.Authenticator;
 import org.apache.isis.runtimes.dflt.runtime.authentication.AuthenticationManagerStandardInstallerAbstractForDfltRuntime;
 
-import com.google.inject.AbstractModule;
-import com.google.inject.Module;
-
-
-public class FileAuthenticationManagerInstaller extends AuthenticationManagerStandardInstallerAbstractForDfltRuntime
{
-
-    public static final String NAME = "file";
-
-	public FileAuthenticationManagerInstaller() {
-        super(NAME);
-    }
-
-    @Override
-    protected Authenticator createAuthenticator(final IsisConfiguration configuration) {
-        return new FileAuthenticator(configuration);
-    }
-
-}
+public class FileAuthenticationManagerInstaller extends AuthenticationManagerStandardInstallerAbstractForDfltRuntime
{
+
+    public static final String NAME = "file";
+
+    public FileAuthenticationManagerInstaller() {
+        super(NAME);
+    }
+
+    @Override
+    protected Authenticator createAuthenticator(final IsisConfiguration configuration) {
+        return new FileAuthenticator(configuration);
+    }
+
+}

Modified: incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticator.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticator.java?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticator.java
(original)
+++ incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authentication/FileAuthenticator.java
Mon May  2 17:18:36 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.security.file.authentication;
 
 import java.io.BufferedReader;
@@ -40,15 +39,16 @@ import com.google.common.base.Strings;
 import com.google.inject.Inject;
 
 public class FileAuthenticator extends PasswordRequestAuthenticatorAbstract {
-	
-	private final ResourceStreamSource resourceStreamSource;
 
-	@Inject
+    private final ResourceStreamSource resourceStreamSource;
+
+    @Inject
     public FileAuthenticator(final IsisConfiguration configuration) {
-    	super(configuration);
+        super(configuration);
         this.resourceStreamSource = configuration.getResourceStreamSource();
     }
 
+    @Override
     public final boolean isValid(final AuthenticationRequest request) {
         final AuthenticationRequestPassword passwordRequest = (AuthenticationRequestPassword)
request;
         final String username = passwordRequest.getName();
@@ -60,9 +60,11 @@ public class FileAuthenticator extends P
 
         BufferedReader reader = null;
         try {
-            InputStream readStream = resourceStreamSource.readResource(FileAuthenticationConstants.PASSWORDS_FILE);
+            final InputStream readStream =
+                resourceStreamSource.readResource(FileAuthenticationConstants.PASSWORDS_FILE);
             if (readStream == null) {
-                throw new IsisException("Failed to open password file: " + FileAuthenticationConstants.PASSWORDS_FILE
+ " from " + resourceStreamSource.getName());
+                throw new IsisException("Failed to open password file: " + FileAuthenticationConstants.PASSWORDS_FILE
+                    + " from " + resourceStreamSource.getName());
             }
             reader = new BufferedReader(new InputStreamReader(readStream));
             String line;
@@ -75,47 +77,46 @@ public class FileAuthenticator extends P
                 }
                 final String name = line.substring(0, line.indexOf(':'));
                 if (!name.equals(username)) {
-                	continue;
+                    continue;
                 }
-                
+
                 return isPasswordValidForUser(request, password, line);
             }
             return false;
         } catch (final IOException e) {
-            throw new IsisException("Failed to read password file: " + FileAuthenticationConstants.PASSWORDS_FILE
+ " from " + resourceStreamSource.getName());
+            throw new IsisException("Failed to read password file: " + FileAuthenticationConstants.PASSWORDS_FILE
+                + " from " + resourceStreamSource.getName());
         } finally {
-        	IoUtils.closeSafely(reader);
+            IoUtils.closeSafely(reader);
         }
 
     }
 
-	private boolean commentedOutOrEmpty(String line) {
-		return line.startsWith("#") || line.trim().length() == 0;
-	}
-
-	private boolean isPasswordValidForUser(
-			final AuthenticationRequest request,
-			final String password, String line) {
-		int posFirstColon = line.indexOf(':');
-		int posPasswordStart = posFirstColon + 1;
-		
-		int posSecondColonIfAny = line.indexOf(':', posPasswordStart);
-		int posPasswordEnd = posSecondColonIfAny == -1 ? line.length() : posSecondColonIfAny;
-		
-		String parsedPassword = line.substring(posPasswordStart, posPasswordEnd);
-		if (parsedPassword.equals(password)) {
-		    if (posSecondColonIfAny != -1) {
-		        setRoles(request, line.substring(posSecondColonIfAny + 1));
-		    }
-		    return true;
-		} else {
-		    return false;
-		}
-	}
+    private boolean commentedOutOrEmpty(final String line) {
+        return line.startsWith("#") || line.trim().length() == 0;
+    }
+
+    private boolean isPasswordValidForUser(final AuthenticationRequest request, final String
password, final String line) {
+        final int posFirstColon = line.indexOf(':');
+        final int posPasswordStart = posFirstColon + 1;
+
+        final int posSecondColonIfAny = line.indexOf(':', posPasswordStart);
+        final int posPasswordEnd = posSecondColonIfAny == -1 ? line.length() : posSecondColonIfAny;
+
+        final String parsedPassword = line.substring(posPasswordStart, posPasswordEnd);
+        if (parsedPassword.equals(password)) {
+            if (posSecondColonIfAny != -1) {
+                setRoles(request, line.substring(posSecondColonIfAny + 1));
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
 
     private final void setRoles(final AuthenticationRequest request, final String line) {
         final StringTokenizer tokens = new StringTokenizer(line, "|", false);
-        String[] roles = new String[tokens.countTokens()];
+        final String[] roles = new String[tokens.countTokens()];
         for (int i = 0; tokens.hasMoreTokens(); i++) {
             roles[i] = tokens.nextToken();
         }
@@ -123,4 +124,3 @@ public class FileAuthenticator extends P
     }
 
 }
-

Modified: incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationConstants.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationConstants.java?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationConstants.java
(original)
+++ incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationConstants.java
Mon May  2 17:18:36 2011
@@ -17,27 +17,27 @@
  *  under the License.
  */
 
+package org.apache.isis.security.file.authorization;
 
-package org.apache.isis.security.file.authorization;
-
 import org.apache.isis.core.commons.config.ConfigurationConstants;
 import org.apache.isis.core.runtime.authorization.AuthorizationManagerInstaller;
 import org.apache.isis.core.runtime.authorization.standard.AuthorizationConstants;
-
-public final class FileAuthorizationConstants {
-	
-	private static final String ROOT = 
-		ConfigurationConstants.ROOT + AuthorizationManagerInstaller.TYPE + "." + FileAuthorizationManagerInstaller.NAME
+ ".";
-	
-	public static final String WHITELIST_RESOURCE_KEY = ROOT + "whitelist";
-	public static final String WHITELIST_RESOURCE_DEFAULT = "security_file.allow";
-	
-	public static final String BLACKLIST_RESOURCE_KEY = ROOT + "blacklist";
-	public static final String BLACKLIST_RESOURCE_DEFAULT = "";
-	
-	public static final String LEARN = AuthorizationConstants.LEARN;
-	public static final boolean LEARN_DEFAULT = AuthorizationConstants.LEARN_DEFAULT;
-
-	private FileAuthorizationConstants(){}
-
-}
+
+public final class FileAuthorizationConstants {
+
+    private static final String ROOT = ConfigurationConstants.ROOT + AuthorizationManagerInstaller.TYPE
+ "."
+        + FileAuthorizationManagerInstaller.NAME + ".";
+
+    public static final String WHITELIST_RESOURCE_KEY = ROOT + "whitelist";
+    public static final String WHITELIST_RESOURCE_DEFAULT = "security_file.allow";
+
+    public static final String BLACKLIST_RESOURCE_KEY = ROOT + "blacklist";
+    public static final String BLACKLIST_RESOURCE_DEFAULT = "";
+
+    public static final String LEARN = AuthorizationConstants.LEARN;
+    public static final boolean LEARN_DEFAULT = AuthorizationConstants.LEARN_DEFAULT;
+
+    private FileAuthorizationConstants() {
+    }
+
+}

Modified: incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationManagerInstaller.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationManagerInstaller.java?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationManagerInstaller.java
(original)
+++ incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizationManagerInstaller.java
Mon May  2 17:18:36 2011
@@ -17,25 +17,23 @@
  *  under the License.
  */
 
+package org.apache.isis.security.file.authorization;
 
-package org.apache.isis.security.file.authorization;
-
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.runtime.authorization.standard.AuthorizationManagerStandardInstallerAbstract;
 import org.apache.isis.core.runtime.authorization.standard.Authorizor;
-
-
-public class FileAuthorizationManagerInstaller extends AuthorizationManagerStandardInstallerAbstract
{
-
-    public static final String NAME = "file";
-
-	public FileAuthorizationManagerInstaller() {
-        super(NAME);
-    }
-
-    @Override
-    protected Authorizor createAuthorizor(IsisConfiguration configuration) {
-        return new FileAuthorizor(configuration);
-    }
-
-}
+
+public class FileAuthorizationManagerInstaller extends AuthorizationManagerStandardInstallerAbstract
{
+
+    public static final String NAME = "file";
+
+    public FileAuthorizationManagerInstaller() {
+        super(NAME);
+    }
+
+    @Override
+    protected Authorizor createAuthorizor(final IsisConfiguration configuration) {
+        return new FileAuthorizor(configuration);
+    }
+
+}

Modified: incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizor.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizor.java?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizor.java
(original)
+++ incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizor.java
Mon May  2 17:18:36 2011
@@ -17,9 +17,8 @@
  *  under the License.
  */
 
+package org.apache.isis.security.file.authorization;
 
-package org.apache.isis.security.file.authorization;
-
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.IOException;
@@ -47,87 +46,91 @@ import org.apache.isis.core.runtime.auth
 import org.apache.log4j.Logger;
 
 import com.google.common.collect.Maps;
-
-
-public class FileAuthorizor extends AuthorizorAbstract implements FileAuthorizorMBean {
-
-    private static final Logger LOG = Logger.getLogger(FileAuthorizor.class);
-
-    private static final String NONE = "";
-    private static final String ACCESS_QUALIFIER_RO = "-ro";
-    private static final String ACCESS_QUALIFIER_RW = "-rw";
-    
-    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 InputStream whiteListInputResource;
-    
-    private final String blackListResourceName;
-    private InputStream blackListInputResource;
-
-    private boolean printedWarning;
-    private boolean printedDebug;
-
-    public FileAuthorizor(IsisConfiguration configuration) {
-    	super(configuration);
-
-        // 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_KEY,
FileAuthorizationConstants.BLACKLIST_RESOURCE_DEFAULT);
-        
+
+public class FileAuthorizor extends AuthorizorAbstract implements FileAuthorizorMBean {
+
+    private static final Logger LOG = Logger.getLogger(FileAuthorizor.class);
+
+    private static final String NONE = "";
+    private static final String ACCESS_QUALIFIER_RO = "-ro";
+    private static final String ACCESS_QUALIFIER_RW = "-rw";
+
+    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 InputStream whiteListInputResource;
+
+    private final String blackListResourceName;
+    private InputStream blackListInputResource;
+
+    private boolean printedWarning;
+    private boolean printedDebug;
+
+    public FileAuthorizor(final IsisConfiguration configuration) {
+        super(configuration);
+
+        // 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_KEY,
+                FileAuthorizationConstants.BLACKLIST_RESOURCE_DEFAULT);
+
         findResources();
     }
 
+    private void findResources() {
+        whiteListInputResource = resourceStreamSource.readResource(whiteListResourceName);
+        if (whiteListInputResource == null) {
+            throw new IsisException("Cannot read whitelist authorization file: " + whiteListResourceName);
+        }
+
+        if (blackListResourceName.length() > 0) {
+            this.blackListInputResource = resourceStreamSource.readResource(blackListResourceName);
+            if (blackListInputResource == null) {
+                throw new IsisException("Blacklist authorization file exists, but it cannot
be read: "
+                    + blackListResourceName);
+            }
+        } else {
+            blackListInputResource = null;
+        }
+    }
+
+    // //////////////////////////////////////////////////////////////
+    // init, shutdown
+    // //////////////////////////////////////////////////////////////
 
-    private void findResources() {
-        whiteListInputResource = resourceStreamSource.readResource(whiteListResourceName);
-        if (whiteListInputResource == null) {
-            throw new IsisException("Cannot read whitelist authorization file: " + whiteListResourceName);
-        }
-        
-        if (blackListResourceName.length() > 0) {
-            this.blackListInputResource = resourceStreamSource.readResource(blackListResourceName);
-            if (blackListInputResource == null) {
-                throw new IsisException("Blacklist authorization file exists, but it cannot
be read: " + blackListResourceName);
-            }
-        } else {
-        	blackListInputResource = null;
-        }
-    }
-
-    
-    ////////////////////////////////////////////////////////////////
-    // init, shutdown
-    ////////////////////////////////////////////////////////////////
-    
     @Override
-    public void init() {
+    public void init() {
         whiteListMap = Maps.newHashMap();
         blackListMap = Maps.newHashMap();
-        
-        // initialize
-        if (learn) {
+
+        // initialize
+        if (learn) {
             return;
-        }
-        cacheAuthorizationDetails(whiteListMap, whiteListInputResource);
-        if (blackListInputResource != null) {
-            cacheAuthorizationDetails(blackListMap, blackListInputResource);
         }
-        
+        cacheAuthorizationDetails(whiteListMap, whiteListInputResource);
+        if (blackListInputResource != null) {
+            cacheAuthorizationDetails(blackListMap, blackListInputResource);
+        }
+
         JmxBeanServer.getInstance().register("file-authorizer", this);
     }
 
+    @Override
     public void reload() {
-        Map<String,List<String>> whiteListMap = Maps.newHashMap();
-        Map<String,List<String>> blackListMap = Maps.newHashMap();
+        final Map<String, List<String>> whiteListMap = Maps.newHashMap();
+        final Map<String, List<String>> blackListMap = Maps.newHashMap();
 
         findResources();
         cacheAuthorizationDetails(whiteListMap, whiteListInputResource);
@@ -137,115 +140,112 @@ public class FileAuthorizor extends Auth
         }
         this.whiteListMap = whiteListMap;
     }
-
-
-    private void cacheAuthorizationDetails(final Map<String,List<String>> map,
final InputStream inputStream) {
-        try {
-        	if (LOG.isInfoEnabled()) {
-        		LOG.info("loading authorization details from " + whiteListResourceName);
-        	}
-            final BufferedReader buffReader = 
-            	new BufferedReader(new InputStreamReader(inputStream));
-            for (String line; (line = buffReader.readLine()) != null;) {
-                tokenizeLine(map, line);
-            }
-            buffReader.close();
-        } catch (final Exception e) {
-            throw new IsisException(e);
-        }
-    }
-
-    private void tokenizeLine(final Map<String,List<String>> map, final String
line) {
-        if (line.trim().startsWith("#") || line.trim().length() == 0) {
-            return;
+
+    private void cacheAuthorizationDetails(final Map<String, List<String>> map,
final InputStream inputStream) {
+        try {
+            if (LOG.isInfoEnabled()) {
+                LOG.info("loading authorization details from " + whiteListResourceName);
+            }
+            final BufferedReader buffReader = new BufferedReader(new InputStreamReader(inputStream));
+            for (String line; (line = buffReader.readLine()) != null;) {
+                tokenizeLine(map, line);
+            }
+            buffReader.close();
+        } catch (final Exception e) {
+            throw new IsisException(e);
+        }
+    }
+
+    private void tokenizeLine(final Map<String, List<String>> map, final String
line) {
+        if (line.trim().startsWith("#") || line.trim().length() == 0) {
+            return;
         }
-        int pos = line.trim().indexOf(">");
+        final int pos = line.trim().indexOf(">");
         if (pos == -1) {
-            final StringTokenizer tokens = new StringTokenizer(line.trim(), ":", false);
+            final StringTokenizer tokens = new StringTokenizer(line.trim(), ":", false);
             if (tokens.countTokens() != 2) {
                 throw new IsisConfigurationException("Invalid line: " + line);
             }
-            final String token1 = tokens.nextToken();
-            final String token2 = tokens.nextToken();
-            final Identifier identifier = memberFromString(token1.trim());
-            final List<String> roles = tokenizeRoles(token2);
-            String identityString = identifier.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS);
-            map.put(identityString, roles);
+            final String token1 = tokens.nextToken();
+            final String token2 = tokens.nextToken();
+            final Identifier identifier = memberFromString(token1.trim());
+            final List<String> roles = tokenizeRoles(token2);
+            final String identityString = identifier.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS);
+            map.put(identityString, roles);
         } else {
-            Map<String,List<String>> newRules = new HashMap<String,List<String>>();

-            for (String name: map.keySet()) {
-                String originalName = line.trim().substring(0, pos);
-                String redirectedName = line.trim().substring(pos + 1);
+            final Map<String, List<String>> newRules = new HashMap<String,
List<String>>();
+            for (final String name : map.keySet()) {
+                final String originalName = line.trim().substring(0, pos);
+                final String redirectedName = line.trim().substring(pos + 1);
                 if (name.startsWith(redirectedName)) {
-                    String id = originalName + name.substring(redirectedName.length());
-                    List<String> roles = map.get(name);
+                    final String id = originalName + name.substring(redirectedName.length());
+                    final List<String> roles = map.get(name);
                     newRules.put(id, roles);
                 }
             }
             map.putAll(newRules);
-        }
-    }
-
-    private Identifier memberFromString(final String identifier) {
-    	return Identifier.fromIdentityString(identifier);
-    }
-
-    private List<String> tokenizeRoles(final String allRoles) {
-        final List<String> roles = new ArrayList<String>();
-        final StringTokenizer tokens = new StringTokenizer(allRoles, "|", false);
-        while (tokens.hasMoreTokens()) {
-            String nextToken = tokens.nextToken();
-            String trimmedNextToken = nextToken.trim();
-            roles.add(trimmedNextToken);
-        }
-        return roles;
-    }
-
+        }
+    }
+
+    private Identifier memberFromString(final String identifier) {
+        return Identifier.fromIdentityString(identifier);
+    }
+
+    private List<String> tokenizeRoles(final String allRoles) {
+        final List<String> roles = new ArrayList<String>();
+        final StringTokenizer tokens = new StringTokenizer(allRoles, "|", false);
+        while (tokens.hasMoreTokens()) {
+            final String nextToken = tokens.nextToken();
+            final String trimmedNextToken = nextToken.trim();
+            roles.add(trimmedNextToken);
+        }
+        return roles;
+    }
+
     @Override
-    public void shutdown() {
-        if (learn) {
-            writeMap();
-        }
-    }
-
-
-    ////////////////////////////////////////////////////////////////
-    // API
-    ////////////////////////////////////////////////////////////////
-
+    public void shutdown() {
+        if (learn) {
+            writeMap();
+        }
+    }
+
+    // //////////////////////////////////////////////////////////////
+    // API
+    // //////////////////////////////////////////////////////////////
+
     @Override
-    public boolean isUsableInRole(final String role, final Identifier member) {
-        return isAuthorized(role, member, Arrays.asList(NONE, ACCESS_QUALIFIER_RW));
-    }
-
+    public boolean isUsableInRole(final String role, final Identifier member) {
+        return isAuthorized(role, member, Arrays.asList(NONE, ACCESS_QUALIFIER_RW));
+    }
+
     @Override
-    public boolean isVisibleInRole(final String role, final Identifier member) {
-        return isAuthorized(role, member, Arrays.asList(NONE, ACCESS_QUALIFIER_RO, ACCESS_QUALIFIER_RW));
-    }
-
-    private boolean isAuthorized(final String role, final Identifier member, final List<String>
qualifiers) {
-        if (learn) {
-            return learn(role, member);
-        }
-        return isWhiteListed(role, member, qualifiers) && 
-              !isBlackListed(role, member, qualifiers);
-    }
-
-    private boolean isWhiteListed(final String role, final Identifier member, final List<String>
qualifiers) {
-        return isListed(whiteListMap, role, member, qualifiers);
-    }
-
-    private boolean isBlackListed(final String role, final Identifier member, final List<String>
qualifiers) {
-        return isListed(blackListMap, role, member, qualifiers);
-    }
+    public boolean isVisibleInRole(final String role, final Identifier member) {
+        return isAuthorized(role, member, Arrays.asList(NONE, ACCESS_QUALIFIER_RO, ACCESS_QUALIFIER_RW));
+    }
+
+    private boolean isAuthorized(final String role, final Identifier member, final List<String>
qualifiers) {
+        if (learn) {
+            return learn(role, member);
+        }
+        return isWhiteListed(role, member, qualifiers) && !isBlackListed(role, member,
qualifiers);
+    }
+
+    private boolean isWhiteListed(final String role, final Identifier member, final List<String>
qualifiers) {
+        return isListed(whiteListMap, role, member, qualifiers);
+    }
+
+    private boolean isBlackListed(final String role, final Identifier member, final List<String>
qualifiers) {
+        return isListed(blackListMap, role, member, qualifiers);
+    }
 
     /*
-     * Work through the available entries from most specific to least.  When one exists then
determine the result of this method
-     * by looking for a compatible role between the entry and required role.
-     */
-    private boolean isListed(final Map<String,List<String>> map, final String
role, final Identifier identifier, final List<String> qualifiers) {
-        if (map.isEmpty()) {// quick fail
-            return false;
+     * Work through the available entries from most specific to least. When one exists then
determine the result of this
+     * method by looking for a compatible role between the entry and required role.
+     */
+    private boolean isListed(final Map<String, List<String>> map, final String
role, final Identifier identifier,
+        final List<String> qualifiers) {
+        if (map.isEmpty()) {// quick fail
+            return false;
         }
         List<String> roles;
         roles = rolesFor(map, identifier.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS));
@@ -259,76 +259,76 @@ public class FileAuthorizor extends Auth
             roles = rolesFor(map, "*#" + identifier.toIdentityString(Identifier.MEMBERNAME_ONLY));
         }
         if (roles != null) {
-        for (final String qualifier: qualifiers) {
-            final String qualifiedRole = role + qualifier;
-            if (roles.contains(qualifiedRole)) {
+            for (final String qualifier : qualifiers) {
+                final String qualifiedRole = role + qualifier;
+                if (roles.contains(qualifiedRole)) {
                     return true;
                 }
             }
         }
-        return false;
-    }
-
-    private List<String> rolesFor(Map<String, List<String>> map, String
key) {
+        return false;
+    }
+
+    private List<String> rolesFor(final Map<String, List<String>> map,
final String key) {
         if (map.containsKey(key)) {
-           return map.get(key);
+            return map.get(key);
         } else {
             return null;
         }
     }
 
-    private boolean learn(final String role, final Identifier member) {
-        String identityString = member.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS);
-        if (whiteListMap.containsKey(identityString)) {
-            final List<String> roles = whiteListMap.get(identityString);
-            if (!roles.contains(role)) {
-                roles.add(role);
-            }
-        } else {
-            whiteListMap.put(identityString, Arrays.asList(new String[] { role }));
-        }
-        
-        // REVIEW: might be too labour intensive
-        writeMap();
-        return true;
-    }
-    
-    private void writeMap() {
-        try {
-            OutputStream whiteListOutputResource = resourceStreamSource.writeResource(whiteListResourceName);
+    private boolean learn(final String role, final Identifier member) {
+        final String identityString = member.toIdentityString(Identifier.CLASS_MEMBERNAME_PARAMETERS);
+        if (whiteListMap.containsKey(identityString)) {
+            final List<String> roles = whiteListMap.get(identityString);
+            if (!roles.contains(role)) {
+                roles.add(role);
+            }
+        } else {
+            whiteListMap.put(identityString, Arrays.asList(new String[] { role }));
+        }
+
+        // REVIEW: might be too labour intensive
+        writeMap();
+        return true;
+    }
+
+    private void writeMap() {
+        try {
+            final OutputStream whiteListOutputResource = resourceStreamSource.writeResource(whiteListResourceName);
             if (whiteListOutputResource == null) {
-                if (!printedWarning) {
-                	LOG.warn("unable to write out authorisation details");
-                	printedWarning = true; // just to stop flooding log
-                }
-            	return;
-            }
-            if (LOG.isDebugEnabled() && !printedDebug) {
-            	LOG.debug("writing authorisation details to " + whiteListResourceName);
-            	printedDebug = true; // just to stop flooding log
-            }
-            final OutputStreamWriter fileWriter = new OutputStreamWriter(whiteListOutputResource);
-            final BufferedWriter buffWriter = new BufferedWriter(fileWriter);
-            Set<Entry<String, List<String>>> entrySet = whiteListMap.entrySet();
-            for (int i = 0; i < entrySet.size(); i++) {
-                final Map.Entry<String,List<String>> entry = (Map.Entry<String,List<String>>)
entrySet.toArray()[i];
-                final StringBuffer buff = new StringBuffer();
-                buff.append(entry.getKey()).append(":");
-                final List<String> roles = entry.getValue();
-                for (int j = 0; j < roles.size(); j++) {
-                    buff.append(roles.get(j));
-                    if (j < roles.size() - 1) {
-                        buff.append("|");
-                    }
-                }
-                buffWriter.write(buff.toString());
-                buffWriter.newLine();
-            }
-            buffWriter.flush();
-            buffWriter.close();
-        } catch (final IOException e) {
-            throw new IsisException(e);
-        }
-    }
-
-}
+                if (!printedWarning) {
+                    LOG.warn("unable to write out authorisation details");
+                    printedWarning = true; // just to stop flooding log
+                }
+                return;
+            }
+            if (LOG.isDebugEnabled() && !printedDebug) {
+                LOG.debug("writing authorisation details to " + whiteListResourceName);
+                printedDebug = true; // just to stop flooding log
+            }
+            final OutputStreamWriter fileWriter = new OutputStreamWriter(whiteListOutputResource);
+            final BufferedWriter buffWriter = new BufferedWriter(fileWriter);
+            final Set<Entry<String, List<String>>> entrySet = whiteListMap.entrySet();
+            for (int i = 0; i < entrySet.size(); i++) {
+                final Map.Entry<String, List<String>> entry = (Map.Entry<String,
List<String>>) entrySet.toArray()[i];
+                final StringBuffer buff = new StringBuffer();
+                buff.append(entry.getKey()).append(":");
+                final List<String> roles = entry.getValue();
+                for (int j = 0; j < roles.size(); j++) {
+                    buff.append(roles.get(j));
+                    if (j < roles.size() - 1) {
+                        buff.append("|");
+                    }
+                }
+                buffWriter.write(buff.toString());
+                buffWriter.newLine();
+            }
+            buffWriter.flush();
+            buffWriter.close();
+        } catch (final IOException e) {
+            throw new IsisException(e);
+        }
+    }
+
+}

Modified: incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizorMBean.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizorMBean.java?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizorMBean.java
(original)
+++ incubator/isis/trunk/security/file/src/main/java/org/apache/isis/security/file/authorization/FileAuthorizorMBean.java
Mon May  2 17:18:36 2011
@@ -22,4 +22,3 @@ public interface FileAuthorizorMBean {
 
     void reload();
 }
-

Modified: incubator/isis/trunk/security/file/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/security/file/src/site/apt/index.apt?rev=1098668&r1=1098667&r2=1098668&view=diff
==============================================================================
--- incubator/isis/trunk/security/file/src/site/apt/index.apt (original)
+++ incubator/isis/trunk/security/file/src/site/apt/index.apt Mon May  2 17:18:36 2011
@@ -18,5 +18,24 @@
 
 
 Security File Implementation
+ 
+ The <file security> module is a simple implementation of Isis' authentication and
+ authorization APIs, that uses flat files store user/passwords/roles (for authentication)
+ and role-based permissions (for authorization).
+ 
+ Because of critical information stored in flat files, this implementation is unlikely to

+ be suitable for deployment, but it is valuable both for prototyping and building
+ up roles/permission sets (eg to be imported into some other implementation).  It is
+ also useful as a example implementation that can be enhanced as required.
+ 
+ 
+Alternatives
 
- ...
\ No newline at end of file
+  Alternatives include:
+  
+  * the {{{../dflt/index.html}default}} (no-op) security implementation, for prototyping
use only
+
+  * the {{{../ldap/index.html}LDAP}} security
+
+  []
+ 
\ No newline at end of file



Mime
View raw message