harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r463145 - in /incubator/harmony/enhanced/classlib/trunk/modules/auth: ./ src/main/java/common/org/apache/harmony/auth/internal/nls/ src/main/java/common/org/apache/harmony/auth/login/ src/test/java/common/org/apache/harmony/auth/login/ src/...
Date Thu, 12 Oct 2006 07:34:37 GMT
Author: smishura
Date: Thu Oct 12 00:34:33 2006
New Revision: 463145

URL: http://svn.apache.org/viewvc?view=rev&rev=463145
Log:
Fix for HARMONY-1715 ([classlib][auth] javax.security.auth.login.Configuration.getConfiguration()
does not throw SecurityException)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/auth/build.xml
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/nls/messages.properties
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/login/DefaultConfiguration.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/build.xml
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/build.xml?view=diff&rev=463145&r1=463144&r2=463145
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/build.xml Thu Oct 12 00:34:33 2006
@@ -179,6 +179,7 @@
 
             <classpath>
                 <pathelement path="${hy.auth.src.test.resources}"/>
+                <pathelement path="${hy.auth.bin.test}"/>
             </classpath>
 
             <formatter type="xml" />

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/nls/messages.properties?view=diff&rev=463145&r1=463144&r2=463145
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/nls/messages.properties
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/internal/nls/messages.properties
Thu Oct 12 00:34:33 2006
@@ -98,3 +98,4 @@
 auth.50=\n\tInvalid options format {0}
 auth.51=\n\tInvalid token: {0}
 auth.52=Error code: {0}
+auth.53=Unable to locate a login configuration

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/login/DefaultConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/login/DefaultConfiguration.java?view=diff&rev=463145&r1=463144&r2=463145
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/login/DefaultConfiguration.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/org/apache/harmony/auth/login/DefaultConfiguration.java
Thu Oct 12 00:34:33 2006
@@ -20,6 +20,7 @@
 import java.io.File;
 import java.net.URL;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -30,6 +31,7 @@
 import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
 
+import org.apache.harmony.auth.internal.nls.Messages;
 import org.apache.harmony.security.fortress.PolicyUtils;
 
 /**
@@ -52,10 +54,6 @@
     // location of login configuration file
     private static final String LOGIN_CONFIG_URL_PREFIX = "login.config.url."; //$NON-NLS-1$
 
-    // default a config file from user's home directory
-    private static final String JAVA_LOGIN_CONF_FILE = "file:" + System.getProperty("user.home")
+ //$NON-NLS-1$ //$NON-NLS-2$
-            +File.separatorChar + ".java.login.config"; //$NON-NLS-1$
-
     // creates a AuthPermission object 
     private static final AuthPermission REFRESH_LOGIN_CONFIGURATION = new AuthPermission(
             "refreshLoginConfiguration"); //$NON-NLS-1$
@@ -69,11 +67,8 @@
      */
     public DefaultConfiguration() {
         super();
-        try {
-            init();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+
+        init();
     }
 
     @Override
@@ -95,11 +90,8 @@
             sm.checkPermission(REFRESH_LOGIN_CONFIGURATION);
         }
         configutations.clear();
-        try {
-            init();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+
+        init();
     }
 
     /**
@@ -122,11 +114,30 @@
                 //new SecurityException("Unable to load a login configuration file");
             }
         }
+        
         // if location is not define then get a config file from user's directory 
         if (policyLocations.length == 0) {
+            
+            // check presence of ${user.home}/.java.login.config
+            File userLoginConfig = AccessController
+                    .doPrivileged(new PrivilegedAction<File>() {
+                        public File run() {
+                            File f = new File(System.getProperty("user.home") + //$NON-NLS-1$
+                                    File.separatorChar + ".java.login.config"); //$NON-NLS-1$
+                            if (f.exists()) {
+                                return f;
+                            }
+                            return null;
+                        }
+                    });
+            if (userLoginConfig == null) {
+                // auth.53: Unable to locate a login configuration
+                throw new SecurityException(Messages.getString("auth.53")); //$NON-NLS-1$
+            }
+            
             try {
-                fresh.putAll(DefaultConfigurationParser.configParser(new URL(
-                        JAVA_LOGIN_CONF_FILE), system, fresh));
+                fresh.putAll(DefaultConfigurationParser.configParser(
+                        userLoginConfig.toURL(), system, fresh));
             } catch (Exception e) {
                 //TODO: log warning
                 //throw new SecurityException ("Unable to load a login configuration file");

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java?view=diff&rev=463145&r1=463144&r2=463145
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/login/DefaultConfigurationTest.java
Thu Oct 12 00:34:33 2006
@@ -87,19 +87,12 @@
 	 * XXX: load a default config file
 	 */
 	public static void testLoadConfigFile() throws Exception {
-			DefaultConfiguration dc = null;
-			dc = new DefaultConfiguration();
-			assertNotNull(dc);
-			ents = dc.getAppConfigurationEntry("Login1");
-			assertNull(ents);
-			ents = dc.getAppConfigurationEntry(null);
-			assertNull(ents);
 			Security.setProperty("login.config.url.1", "file:"
 					+ defaultConfFile.getCanonicalPath());
 			Security.setProperty("login.config.url.2", "file:"
 					+ new File(otherConfFile).getCanonicalPath());
 
-			dc = new DefaultConfiguration();
+            DefaultConfiguration dc = new DefaultConfiguration();
 			ents = dc.getAppConfigurationEntry("LoginNew");
 			assertNotNull(ents);
 			assertEquals("com.intel.security.auth.module.LoginModule1", ents[0].getLoginModuleName());

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java?view=diff&rev=463145&r1=463144&r2=463145
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/login/ConfigurationTest.java
Thu Oct 12 00:34:33 2006
@@ -22,8 +22,10 @@
 
 package org.apache.harmony.auth.tests.javax.security.auth.login;
 
+import java.io.File;
 import java.security.Permission;
 import java.security.Security;
+import java.util.Properties;
 
 import javax.security.auth.AuthPermission;
 import javax.security.auth.login.AppConfigurationEntry;
@@ -33,6 +35,7 @@
 
 import org.apache.harmony.auth.tests.support.TestUtils;
 
+import tests.support.Support_Exec;
 import tests.support.resource.Support_Resources;
 
 /**
@@ -174,13 +177,13 @@
             // test: loading custom test provider
             Security.setProperty(LOGIN_CONFIG_PROVIDER, ConfTestProvider.class
                     .getName());
-            Configuration.setConfiguration(null); // reset config
+            Configuration.setConfiguration(null); // reset default config
             assertEquals(ConfTestProvider.class, Configuration
                     .getConfiguration().getClass());
 
             // test: loading absent class as test provider
             Security.setProperty(LOGIN_CONFIG_PROVIDER, "ThereIsNoSuchClass");
-            Configuration.setConfiguration(null); // reset config
+            Configuration.setConfiguration(null); // reset default config
             try {
                 Configuration.getConfiguration();
                 fail("No SecurityException on failed provider");
@@ -192,7 +195,7 @@
             // a name of this unit test is used as config provider
             Security.setProperty(LOGIN_CONFIG_PROVIDER, this.getClass()
                     .getName());
-            Configuration.setConfiguration(null);// reset config
+            Configuration.setConfiguration(null);// reset default config
             try {
                 Configuration.getConfiguration();
                 fail("No expected ClassCastException");
@@ -205,7 +208,58 @@
                     (oldProvider == null) ? "" : oldProvider);
         }
     }
-    
+
+    /**
+     * Tests reading config files by default provider
+     */
+    public void test_defaultProvider() throws Exception {
+
+        // test: there are no config files to be read
+        // Regression for HARMONY-1715
+
+        // no login.config.url.N security properties should be set
+        String javaSecurityFile = TestUtils
+                .createJavaPropertiesFile(new Properties());
+
+        // tmp user home to avoid presence of ${user.home}/.java.login.config
+        String tmpUserHome = System.getProperty("java.io.tmpdir")
+                + File.separatorChar + "tmpUserHomeForConfigurationTest";
+        File dir = new File(tmpUserHome);
+        if (!dir.exists()) {
+            dir.mkdirs();
+            dir.deleteOnExit();
+        }
+        String javaLoginConfig = tmpUserHome + File.separatorChar
+                + ".java.login.config";
+        assertFalse("There should be no login config file: " + javaLoginConfig,
+                new File(javaLoginConfig).exists());
+
+        String[] arg = new String[] { "-Duser.home=" + tmpUserHome,
+                "-Djava.security.properties=" + javaSecurityFile,
+                NoConfigFileToBeRead.class.getName() };
+
+        Support_Exec.execJava(arg, null, true);
+    }
+
+    public static class NoConfigFileToBeRead {
+
+        // the test is based on assumption that security properties 
+        // login.config.url.N are unset and there is no file
+        // ${user.home}/.java.login.config
+        public static void main(String[] args) {
+
+            //reset path to alternative configuration file
+            TestUtils.setSystemProperty(AUTH_LOGIN_CONFIG, null);
+
+            Configuration.setConfiguration(null); // reset default config
+            try {
+                Configuration.getConfiguration();
+                TestCase.fail("No expected SecurityException");
+            } catch (SecurityException e) {
+            }
+        }
+    }
+
     public static void main(String[] args) {
         junit.textui.TestRunner.run(ConfigurationTest.class);
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java?view=diff&rev=463145&r1=463144&r2=463145
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/support/TestUtils.java
Thu Oct 12 00:34:33 2006
@@ -22,6 +22,10 @@
 
 package org.apache.harmony.auth.tests.support;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.Security;
 import java.util.Properties;
 
 /**
@@ -76,5 +80,41 @@
             properties.setProperty(key, value);
         }
         System.setProperties(properties);
+    }
+    
+    /**
+     * Creates security properties file.
+     * 
+     * The method puts to the file all initial security providers and adds
+     * passed custom properties.
+     * 
+     * @param props -
+     *            security properties to be added to properties file
+     * @return path to created file.
+     * @throws IOException
+     *             if failed to create the file
+     */
+    public static String createJavaPropertiesFile(Properties props)
+            throws IOException {
+
+        File f = File.createTempFile("java", "security");
+        f.deleteOnExit();
+
+        FileOutputStream out = new FileOutputStream(f);
+
+        Properties propsToFlush = new Properties(props);
+        
+        int i = 1;
+        String provider = "security.provider.1";
+        while (Security.getProperty(provider) != null) {
+            propsToFlush.setProperty(provider, Security.getProperty(provider));
+            provider = "security.provider." + i++;
+        }
+
+        propsToFlush.store(out, null);
+
+        out.close();
+
+        return f.getAbsolutePath();
     }
 }



Mime
View raw message