qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oru...@apache.org
Subject svn commit: r1417346 - in /qpid/branches/java-broker-config-qpid-4390/qpid/java: broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/acc...
Date Wed, 05 Dec 2012 10:46:46 GMT
Author: orudyy
Date: Wed Dec  5 10:46:45 2012
New Revision: 1417346

URL: http://svn.apache.org/viewvc?rev=1417346&view=rev
Log:
QPID-4390: Change the signature of AccessControlFactory#createInstance to pass attributes
as a Map

Added:
    qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
Modified:
    qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
    qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
    qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
    qpid/branches/java-broker-config-qpid-4390/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java

Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java?rev=1417346&r1=1417345&r2=1417346&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
(original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactory.java
Wed Dec  5 10:46:45 2012
@@ -20,18 +20,40 @@
  */
 package org.apache.qpid.server.security.access.plugins;
 
+import java.io.File;
+import java.util.Map;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
 import org.apache.qpid.server.plugin.AccessControlFactory;
 import org.apache.qpid.server.security.AccessControl;
 
 public class DefaultAccessControlFactory implements AccessControlFactory
 {
-    public AccessControl createInstance(String aclConfiguration)
+    public static final String ATTRIBUTE_ACL_FILE = "aclFile";
+
+    public AccessControl createInstance(Map<String, Object> aclConfiguration)
     {
-        if(aclConfiguration == null)
+        if (aclConfiguration != null)
         {
-            return null;
+            Object aclFile = aclConfiguration.get(ATTRIBUTE_ACL_FILE);
+            if (aclFile != null)
+            {
+                if (aclFile instanceof String)
+                {
+                    String aclPath = (String) aclFile;
+                    if (!new File(aclPath).exists())
+                    {
+                        throw new IllegalConfigurationException("ACL file '" + aclPath +
"' is not found");
+                    }
+                    return new DefaultAccessControl(aclPath);
+                }
+                else
+                {
+                    throw new IllegalConfigurationException("Expected '" + ATTRIBUTE_ACL_FILE
+ "' attribute value of type String but was " + aclFile.getClass()
+                            + ": " + aclFile);
+                }
+            }
         }
-
-        return new DefaultAccessControl(aclConfiguration);
+        return null;
     }
 }

Added: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java?rev=1417346&view=auto
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
(added)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker-plugins/access-control/src/test/java/org/apache/qpid/server/security/access/plugins/DefaultAccessControlFactoryTest.java
Wed Dec  5 10:46:45 2012
@@ -0,0 +1,69 @@
+package org.apache.qpid.server.security.access.plugins;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.security.AccessControl;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+
+public class DefaultAccessControlFactoryTest extends QpidTestCase
+{
+    public void testCreateInstanceWhenAclFileIsNotPresent()
+    {
+        DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        AccessControl acl = factory.createInstance(attributes);
+        assertNull("ACL was created without a configuration file", acl);
+    }
+
+    public void testCreateInstanceWhenAclFileIsSpecified()
+    {
+        File aclFile = TestFileUtils.createTempFile(this, ".acl", "ACL ALLOW all all");
+        DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile.getAbsolutePath());
+        AccessControl acl = factory.createInstance(attributes);
+
+        assertNotNull("ACL was not created from acl file: " + aclFile.getAbsolutePath(),
acl);
+    }
+
+    public void testCreateInstanceWhenAclFileIsSpecifiedButDoesNotExist()
+    {
+        File aclFile = new File(TMP_FOLDER, "my-non-existing-acl-" + System.currentTimeMillis());
+        assertFalse("ACL file " + aclFile.getAbsolutePath() + " actually exists but should
not", aclFile.exists());
+        DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile.getAbsolutePath());
+        try
+        {
+            factory.createInstance(attributes);
+            fail("It should not be possible to create ACL from non existing file");
+        }
+        catch (IllegalConfigurationException e)
+        {
+            assertTrue("Unexpected exception message", Pattern.matches("ACL file '.*' is
not found", e.getMessage()));
+        }
+    }
+
+    public void testCreateInstanceWhenAclFileIsSpecifiedAsNonString()
+    {
+        DefaultAccessControlFactory factory = new DefaultAccessControlFactory();
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        Integer aclFile = new Integer(0);
+        attributes.put(DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE, aclFile);
+        try
+        {
+            factory.createInstance(attributes);
+            fail("It should not be possible to create ACL from Integer");
+        }
+        catch (IllegalConfigurationException e)
+        {
+            assertEquals("Unexpected exception message", "Expected '" + DefaultAccessControlFactory.ATTRIBUTE_ACL_FILE
+                    + "' attribute value of type String but was " + Integer.class + ": "
+ aclFile, e.getMessage());
+        }
+    }
+}

Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java?rev=1417346&r1=1417345&r2=1417346&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
(original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/AccessControlFactory.java
Wed Dec  5 10:46:45 2012
@@ -18,9 +18,11 @@
  */
 package org.apache.qpid.server.plugin;
 
+import java.util.Map;
+
 import org.apache.qpid.server.security.AccessControl;
 
 public interface AccessControlFactory
 {
-    AccessControl createInstance(String aclFile);
+    AccessControl createInstance(Map<String, Object> attributes);
 }

Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java?rev=1417346&r1=1417345&r2=1417346&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
(original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/security/SecurityManager.java
Wed Dec  5 10:46:45 2012
@@ -130,9 +130,11 @@ public class SecurityManager
 
     public SecurityManager(String aclFile)
     {
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put("aclFile", aclFile);
         for (AccessControlFactory provider : (new QpidServiceLoader<AccessControlFactory>()).instancesOf(AccessControlFactory.class))
         {
-            AccessControl accessControl = provider.createInstance(aclFile);
+            AccessControl accessControl = provider.createInstance(attributes);
             if(accessControl != null)
             {
                 addHostPlugin(accessControl);

Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java?rev=1417346&r1=1417345&r2=1417346&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
(original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java
Wed Dec  5 10:46:45 2012
@@ -24,6 +24,8 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
+import java.io.FileOutputStream;
+
 import junit.framework.TestCase;
 
 import org.apache.qpid.util.FileUtils;
@@ -110,4 +112,42 @@ public class TestFileUtils
         dst.deleteOnExit();
         return dst;
     }
+
+    /**
+     * Creates a temporary file for given test with given suffix in file name.
+     * The given content is stored in the file using UTF-8 encoding.
+     */
+    public static File createTempFile(TestCase testcase, String suffix, String content)
+    {
+        File file = createTempFile(testcase, suffix);
+        if (content != null)
+        {
+            FileOutputStream fos =  null;
+            try
+            {
+                fos = new FileOutputStream(file);
+                fos.write(content.getBytes("UTF-8"));
+                fos.flush();
+            }
+            catch (Exception e)
+            {
+                throw new RuntimeException("Cannot add the content into temp file " + file.getAbsolutePath(),
e);
+            }
+            finally
+            {
+                if (fos != null)
+                {
+                    try
+                    {
+                        fos.close();
+                    }
+                    catch (IOException e)
+                    {
+                        throw new RuntimeException("Cannot close output stream into temp
file " + file.getAbsolutePath(), e);
+                    }
+                }
+            }
+        }
+        return file;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message