harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386061 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit: javax/security/auth/ org/apache/harmony/security/test/ org/apache/harmony/security/x/security/auth/login/
Date Wed, 15 Mar 2006 12:21:17 GMT
Author: tellison
Date: Wed Mar 15 04:21:13 2006
New Revision: 386061

URL: http://svn.apache.org/viewcvs?rev=386061&view=rev
Log:
Apply patch HARMONY-200 (2 security tests must correctly restore environment)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/javax/security/auth/PolicyTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/test/TestUtils.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/x/security/auth/login/DefaultConfigurationTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/javax/security/auth/PolicyTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/javax/security/auth/PolicyTest.java?rev=386061&r1=386060&r2=386061&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/javax/security/auth/PolicyTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/javax/security/auth/PolicyTest.java Wed Mar 15 04:21:13 2006
@@ -1,376 +1,374 @@
-/*
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-/**
-* @author Alexey V. Varlamov
-* @version $Revision$
-*/
-
-package javax.security.auth;
-
-import java.io.File;
-import java.io.FilePermission;
-import java.net.URL;
-import java.security.AllPermission;
-import java.security.CodeSigner;
-import java.security.CodeSource;
-import java.security.Permission;
-import java.security.PermissionCollection;
-import java.security.Security;
-import java.security.cert.Certificate;
-import java.util.Enumeration;
-
-import junit.framework.TestCase;
-import org.apache.harmony.security.test.SecurityChecker;
-
-
-/**
- * Tests Policy class
- */
-public class PolicyTest extends TestCase {
-
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(PolicyTest.class);
-    }
-
-    /**
-     * Tests that setPolicy() is properly secured via SecurityManager.
-     */
-    public void testSetPolicy() {
-        SecurityManager old = System.getSecurityManager();
-        Policy oldPolicy = null;
-        oldPolicy = Policy.getPolicy();
-
-        try {
-            SecurityChecker checker = new SecurityChecker(new AuthPermission(
-                    "setPolicy"), true);
-            System.setSecurityManager(checker);
-            Policy custom = new TestProvider();
-            Policy.setPolicy(custom);
-            assertTrue(checker.checkAsserted);
-            assertSame(custom, Policy.getPolicy());
-
-            checker.reset();
-            checker.enableAccess = false;
-            try {
-                Policy.setPolicy(new TestProvider());
-                fail("SecurityException is intercepted");
-            } catch (SecurityException ok) {
-            }
-        } finally {
-            System.setSecurityManager(old);
-            Policy.setPolicy(oldPolicy);
-        }
-    }
-
-    /**
-     * Tests that getPolicy() is properly secured via SecurityManager.
-     */
-    public void testGetPolicy_CheckPermission() {
-        SecurityManager old = System.getSecurityManager();
-        Policy oldPolicy = null;
-        oldPolicy = Policy.getPolicy();
-
-        try {
-            Policy.setPolicy(new TestProvider());
-            SecurityChecker checker = new SecurityChecker(new AuthPermission(
-                    "getPolicy"), true);
-            System.setSecurityManager(checker);
-            Policy.getPolicy();
-            assertTrue(checker.checkAsserted);
-
-            checker.reset();
-            checker.enableAccess = false;
-            try {
-                Policy.getPolicy();
-                fail("SecurityException is intercepted");
-            } catch (SecurityException ok) {
-            }
-        } finally {
-            System.setSecurityManager(old);
-            Policy.setPolicy(oldPolicy);
-        }
-    }
-
-    public static class TestProvider extends Policy {
-
-        public PermissionCollection getPermissions(Subject subject,
-                CodeSource cs) {
-            return null;
-        }
-
-        public void refresh() {
-        }
-    }
-
-    public static class FakePolicy {
-        // This is not policy class
-    }
-    /**
-     * Tests loading of a default provider, both valid and invalid class
-     * references.
-     */
-    public void testGetPolicy_LoadDefaultProvider() {
-        Policy oldPolicy = null;
-        try {
-            oldPolicy = Policy.getPolicy();
-        } catch (Throwable ignore) {
-        }
-        String POLICY_PROVIDER = "auth.policy.provider";
-        String oldProvider = Security.getProperty(POLICY_PROVIDER);
-        try {
-            Security.setProperty(POLICY_PROVIDER, TestProvider.class.getName());
-            Policy.setPolicy(null);
-            Policy p = Policy.getPolicy();
-            assertNotNull(p);
-            assertEquals(TestProvider.class.getName(), p.getClass().getName());
-
-            // absent class
-            Security.setProperty(POLICY_PROVIDER, "a.b.c.D");
-            Policy.setPolicy(null);
-            try {
-                p = Policy.getPolicy();
-                fail("No SecurityException on failed provider");
-            } catch (SecurityException ok) {
-            }
-            
-            // not a policy class
-            Security.setProperty(POLICY_PROVIDER, FakePolicy.class.getName());
-            Policy.setPolicy(null);
-            try {
-                p = Policy.getPolicy();
-                fail("No expected SecurityException");
-            } catch (SecurityException ok) {
-            }
-        } finally {
-            Security.setProperty(POLICY_PROVIDER, (oldProvider == null) ? ""
-                    : oldProvider);
-            Policy.setPolicy(oldPolicy);
-        }
-    }
-
-    //
-    //
-    //
-    //
-    //
-
-    static String outputPath = System.getProperty("TEST_SRC_DIR", "test"
-            + File.separator + "common" + File.separator + "unit");
-
-    static String inputFile1 = outputPath + File.separator + "javax"
-            + File.separator + "security" + File.separator + "auth"
-            + File.separator + "jaas_policy1.txt";
-
-    static String inputFile2 = outputPath + File.separator + "javax"
-            + File.separator + "security" + File.separator + "auth"
-            + File.separator + "jaas_policy2.txt";
-
-    public void test_GetPermissions() throws Exception {
-
-        PermissionCollection c;
-        Permission per;
-        Subject subject;
-        Enumeration e;
-        CodeSource source;
-
-        String POLICY_PROP = "java.security.auth.policy";
-
-        String oldProp = System.getProperty(POLICY_PROP);
-        try {
-            System.setProperty(POLICY_PROP, inputFile1);
-
-            Policy p = Policy.getPolicy();
-            p.refresh();
-
-            //
-            // Both parameters are null
-            //
-
-            c = p.getPermissions(null, null);
-            assertFalse("Read only for empty", c.isReadOnly());
-            assertFalse("Elements for empty", c.elements().hasMoreElements());
-
-            //
-            // Subject parameter is provided (CodeBase is not important)
-            //
-            // Principal javax.security.auth.MyPrincipal "duke"
-            //
-
-            // no prinipals at all
-            subject = new Subject();
-            c = p.getPermissions(subject, null);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            // different name "kuke" not "duke"
-            subject.getPrincipals().add(new MyPrincipal("kuke"));
-            c = p.getPermissions(subject, null);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            // different class with required principal's name
-            subject.getPrincipals().add(new OtherPrincipal("duke"));
-            c = p.getPermissions(subject, null);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            // subclass with required principal's name
-            subject.getPrincipals().add(new FakePrincipal("duke"));
-            c = p.getPermissions(subject, null);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            // add required principal's name
-            subject.getPrincipals().add(new MyPrincipal("duke"));
-
-            e = p.getPermissions(subject, null).elements();
-
-            per = (Permission) e.nextElement();
-            assertFalse("Elements: ", e.hasMoreElements());
-            assertEquals("Permission: ", per, new FilePermission("/home/duke",
-                    "read, write"));
-
-            // check: CodeBase is not important
-            source = new CodeSource(new URL("http://dummy.xxx"),
-                    (Certificate[]) null);
-            c = p.getPermissions(subject, source);
-            assertTrue("Elements: ", c.elements().hasMoreElements());
-
-            source = new CodeSource(new URL("http://dummy.xxx"),
-                    (CodeSigner[]) null);
-            c = p.getPermissions(subject, source);
-            assertTrue("Elements: ", c.elements().hasMoreElements());
-
-            //
-            // Subject and CodeBase parameter are provided
-            //
-            // Principal javax.security.auth.MyPrincipal "dummy"
-            // CodeBase "http://dummy.xxx"
-            //
-            source = new CodeSource(new URL("http://dummy.xxx"),
-                    (Certificate[]) null);
-            subject = new Subject();
-            subject.getPrincipals().add(new MyPrincipal("dummy"));
-
-            e = p.getPermissions(subject, source).elements();
-            per = (Permission) e.nextElement();
-            assertFalse("Elements: ", e.hasMoreElements());
-            assertEquals("Permission: ", per, new RuntimePermission(
-                    "createClassLoader"));
-
-            // reset subject : no prinipals at all
-            subject = new Subject();
-            c = p.getPermissions(subject, source);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            // different name "kuke" not "dummy"
-            subject.getPrincipals().add(new MyPrincipal("kuke"));
-            c = p.getPermissions(subject, null);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            // different class with required principal's name
-            subject.getPrincipals().add(new OtherPrincipal("dummy"));
-            c = p.getPermissions(subject, null);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            //
-            // Principal javax.security.auth.MyPrincipal "my"
-            // Principal javax.security.auth.OtherPrincipal "other"
-            //
-            subject = new Subject();
-            subject.getPrincipals().add(new MyPrincipal("my"));
-            c = p.getPermissions(subject, null);
-            assertFalse("Elements: ", c.elements().hasMoreElements());
-
-            subject.getPrincipals().add(new OtherPrincipal("other"));
-            e = p.getPermissions(subject, null).elements();
-            per = (Permission) e.nextElement();
-            assertFalse("Elements: ", e.hasMoreElements());
-            assertEquals("Permission: ", per, new AllPermission());
-
-            //
-            // Principal javax.security.auth.MyPrincipal "bunny"
-            //
-            subject = new Subject();
-            subject.getPrincipals().add(new MyPrincipal("bunny"));
-
-            e = p.getPermissions(subject, null).elements();
-
-            Permission[] get = new Permission[2];
-            get[0] = (Permission) e.nextElement();
-            get[1] = (Permission) e.nextElement();
-            assertFalse("Elements: ", e.hasMoreElements());
-
-            Permission[] set = new Permission[2];
-            set[0] = new FilePermission("/home/bunny", "read, write");
-            set[1] = new RuntimePermission("stopThread");
-
-            if (get[0].equals(set[0])) {
-                assertEquals("Permission: ", set[1], get[1]);
-            } else {
-                assertEquals("Permission: ", set[0], get[1]);
-                assertEquals("Permission: ", set[1], get[0]);
-            }
-
-        } finally {
-            System.setProperty(POLICY_PROP, (oldProp == null) ? "" : oldProp);
-        }
-    }
-
-    public void test_Refresh() {
-
-        PermissionCollection c;
-        Permission per;
-        Subject subject;
-        Enumeration e;
-
-        String POLICY_PROP = "java.security.auth.policy";
-
-        String oldProp = System.getProperty(POLICY_PROP);
-        try {
-            //
-            // first policy file to be read
-            //
-            System.setProperty(POLICY_PROP, inputFile1);
-
-            Policy p = Policy.getPolicy();
-            p.refresh();
-
-            subject = new Subject();
-            subject.getPrincipals().add(new MyPrincipal("duke"));
-
-            e = p.getPermissions(subject, null).elements();
-
-            per = (Permission) e.nextElement();
-            assertFalse("Elements: ", e.hasMoreElements());
-            assertEquals("Permission: ", per, new FilePermission("/home/duke",
-                    "read, write"));
-
-            //
-            // second policy file to be read
-            //
-            System.setProperty(POLICY_PROP, inputFile2);
-
-            p.refresh();
-
-            e = p.getPermissions(subject, null).elements();
-
-            per = (Permission) e.nextElement();
-            assertFalse("Elements: ", e.hasMoreElements());
-            assertEquals("Permission: ", per, new RuntimePermission(
-                    "createClassLoader"));
-        } finally {
-            System.setProperty(POLICY_PROP, (oldProp == null) ? "" : oldProp);
-        }
-    }
-}
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Alexey V. Varlamov
+* @version $Revision$
+*/
+
+package javax.security.auth;
+
+import java.io.File;
+import java.io.FilePermission;
+import java.net.URL;
+import java.security.AllPermission;
+import java.security.CodeSigner;
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.util.Enumeration;
+
+import junit.framework.TestCase;
+import org.apache.harmony.security.test.SecurityChecker;
+import org.apache.harmony.security.test.TestUtils;
+
+
+/**
+ * Tests Policy class
+ */
+public class PolicyTest extends TestCase {
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(PolicyTest.class);
+    }
+
+    /**
+     * Tests that setPolicy() is properly secured via SecurityManager.
+     */
+    public void testSetPolicy() {
+        SecurityManager old = System.getSecurityManager();
+        Policy oldPolicy = null;
+        oldPolicy = Policy.getPolicy();
+
+        try {
+            SecurityChecker checker = new SecurityChecker(new AuthPermission(
+                    "setPolicy"), true);
+            System.setSecurityManager(checker);
+            Policy custom = new TestProvider();
+            Policy.setPolicy(custom);
+            assertTrue(checker.checkAsserted);
+            assertSame(custom, Policy.getPolicy());
+
+            checker.reset();
+            checker.enableAccess = false;
+            try {
+                Policy.setPolicy(new TestProvider());
+                fail("SecurityException is intercepted");
+            } catch (SecurityException ok) {
+            }
+        } finally {
+            System.setSecurityManager(old);
+            Policy.setPolicy(oldPolicy);
+        }
+    }
+
+    /**
+     * Tests that getPolicy() is properly secured via SecurityManager.
+     */
+    public void testGetPolicy_CheckPermission() {
+        SecurityManager old = System.getSecurityManager();
+        Policy oldPolicy = null;
+        oldPolicy = Policy.getPolicy();
+
+        try {
+            Policy.setPolicy(new TestProvider());
+            SecurityChecker checker = new SecurityChecker(new AuthPermission(
+                    "getPolicy"), true);
+            System.setSecurityManager(checker);
+            Policy.getPolicy();
+            assertTrue(checker.checkAsserted);
+
+            checker.reset();
+            checker.enableAccess = false;
+            try {
+                Policy.getPolicy();
+                fail("SecurityException is intercepted");
+            } catch (SecurityException ok) {
+            }
+        } finally {
+            System.setSecurityManager(old);
+            Policy.setPolicy(oldPolicy);
+        }
+    }
+
+    public static class TestProvider extends Policy {
+
+        public PermissionCollection getPermissions(Subject subject,
+                CodeSource cs) {
+            return null;
+        }
+
+        public void refresh() {
+        }
+    }
+
+    public static class FakePolicy {
+        // This is not policy class
+    }
+    /**
+     * Tests loading of a default provider, both valid and invalid class
+     * references.
+     */
+    public void testGetPolicy_LoadDefaultProvider() {
+        Policy oldPolicy = null;
+        try {
+            oldPolicy = Policy.getPolicy();
+        } catch (Throwable ignore) {
+        }
+        String POLICY_PROVIDER = "auth.policy.provider";
+        String oldProvider = Security.getProperty(POLICY_PROVIDER);
+        try {
+            Security.setProperty(POLICY_PROVIDER, TestProvider.class.getName());
+            Policy.setPolicy(null);
+            Policy p = Policy.getPolicy();
+            assertNotNull(p);
+            assertEquals(TestProvider.class.getName(), p.getClass().getName());
+
+            // absent class
+            Security.setProperty(POLICY_PROVIDER, "a.b.c.D");
+            Policy.setPolicy(null);
+            try {
+                p = Policy.getPolicy();
+                fail("No SecurityException on failed provider");
+            } catch (SecurityException ok) {
+            }
+            
+            // not a policy class
+            Security.setProperty(POLICY_PROVIDER, FakePolicy.class.getName());
+            Policy.setPolicy(null);
+            try {
+                p = Policy.getPolicy();
+                fail("No expected SecurityException");
+            } catch (SecurityException ok) {
+            }
+        } finally {
+            TestUtils.setSystemProperty(POLICY_PROVIDER, oldProvider);
+            Policy.setPolicy(oldPolicy);
+        }
+    }
+
+    //
+    //
+    //
+    //
+    //
+
+    static String outputPath = System.getProperty("TEST_SRC_DIR", "test"
+            + File.separator + "common" + File.separator + "unit");
+
+    static String inputFile1 = outputPath + File.separator + "javax"
+            + File.separator + "security" + File.separator + "auth"
+            + File.separator + "jaas_policy1.txt";
+
+    static String inputFile2 = outputPath + File.separator + "javax"
+            + File.separator + "security" + File.separator + "auth"
+            + File.separator + "jaas_policy2.txt";
+
+    private static final String POLICY_PROP = "java.security.auth.policy";
+    
+    public void test_GetPermissions() throws Exception {
+
+        PermissionCollection c;
+        Permission per;
+        Subject subject;
+        Enumeration e;
+        CodeSource source;
+
+        String oldProp = System.getProperty(POLICY_PROP);
+        try {
+            System.setProperty(POLICY_PROP, inputFile1);
+
+            Policy p = Policy.getPolicy();
+            p.refresh();
+
+            //
+            // Both parameters are null
+            //
+
+            c = p.getPermissions(null, null);
+            assertFalse("Read only for empty", c.isReadOnly());
+            assertFalse("Elements for empty", c.elements().hasMoreElements());
+
+            //
+            // Subject parameter is provided (CodeBase is not important)
+            //
+            // Principal javax.security.auth.MyPrincipal "duke"
+            //
+
+            // no prinipals at all
+            subject = new Subject();
+            c = p.getPermissions(subject, null);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            // different name "kuke" not "duke"
+            subject.getPrincipals().add(new MyPrincipal("kuke"));
+            c = p.getPermissions(subject, null);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            // different class with required principal's name
+            subject.getPrincipals().add(new OtherPrincipal("duke"));
+            c = p.getPermissions(subject, null);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            // subclass with required principal's name
+            subject.getPrincipals().add(new FakePrincipal("duke"));
+            c = p.getPermissions(subject, null);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            // add required principal's name
+            subject.getPrincipals().add(new MyPrincipal("duke"));
+
+            e = p.getPermissions(subject, null).elements();
+
+            per = (Permission) e.nextElement();
+            assertFalse("Elements: ", e.hasMoreElements());
+            assertEquals("Permission: ", per, new FilePermission("/home/duke",
+                    "read, write"));
+
+            // check: CodeBase is not important
+            source = new CodeSource(new URL("http://dummy.xxx"),
+                    (Certificate[]) null);
+            c = p.getPermissions(subject, source);
+            assertTrue("Elements: ", c.elements().hasMoreElements());
+
+            source = new CodeSource(new URL("http://dummy.xxx"),
+                    (CodeSigner[]) null);
+            c = p.getPermissions(subject, source);
+            assertTrue("Elements: ", c.elements().hasMoreElements());
+
+            //
+            // Subject and CodeBase parameter are provided
+            //
+            // Principal javax.security.auth.MyPrincipal "dummy"
+            // CodeBase "http://dummy.xxx"
+            //
+            source = new CodeSource(new URL("http://dummy.xxx"),
+                    (Certificate[]) null);
+            subject = new Subject();
+            subject.getPrincipals().add(new MyPrincipal("dummy"));
+
+            e = p.getPermissions(subject, source).elements();
+            per = (Permission) e.nextElement();
+            assertFalse("Elements: ", e.hasMoreElements());
+            assertEquals("Permission: ", per, new RuntimePermission(
+                    "createClassLoader"));
+
+            // reset subject : no prinipals at all
+            subject = new Subject();
+            c = p.getPermissions(subject, source);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            // different name "kuke" not "dummy"
+            subject.getPrincipals().add(new MyPrincipal("kuke"));
+            c = p.getPermissions(subject, null);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            // different class with required principal's name
+            subject.getPrincipals().add(new OtherPrincipal("dummy"));
+            c = p.getPermissions(subject, null);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            //
+            // Principal javax.security.auth.MyPrincipal "my"
+            // Principal javax.security.auth.OtherPrincipal "other"
+            //
+            subject = new Subject();
+            subject.getPrincipals().add(new MyPrincipal("my"));
+            c = p.getPermissions(subject, null);
+            assertFalse("Elements: ", c.elements().hasMoreElements());
+
+            subject.getPrincipals().add(new OtherPrincipal("other"));
+            e = p.getPermissions(subject, null).elements();
+            per = (Permission) e.nextElement();
+            assertFalse("Elements: ", e.hasMoreElements());
+            assertEquals("Permission: ", per, new AllPermission());
+
+            //
+            // Principal javax.security.auth.MyPrincipal "bunny"
+            //
+            subject = new Subject();
+            subject.getPrincipals().add(new MyPrincipal("bunny"));
+
+            e = p.getPermissions(subject, null).elements();
+
+            Permission[] get = new Permission[2];
+            get[0] = (Permission) e.nextElement();
+            get[1] = (Permission) e.nextElement();
+            assertFalse("Elements: ", e.hasMoreElements());
+
+            Permission[] set = new Permission[2];
+            set[0] = new FilePermission("/home/bunny", "read, write");
+            set[1] = new RuntimePermission("stopThread");
+
+            if (get[0].equals(set[0])) {
+                assertEquals("Permission: ", set[1], get[1]);
+            } else {
+                assertEquals("Permission: ", set[0], get[1]);
+                assertEquals("Permission: ", set[1], get[0]);
+            }
+
+        } finally {
+            TestUtils.setSystemProperty(POLICY_PROP, oldProp);
+        }
+    }
+
+    public void test_Refresh() {
+
+        PermissionCollection c;
+        Permission per;
+        Subject subject;
+        Enumeration e;
+
+        String oldProp = System.getProperty(POLICY_PROP);
+        try {
+            //
+            // first policy file to be read
+            //
+            System.setProperty(POLICY_PROP, inputFile1);
+
+            Policy p = Policy.getPolicy();
+            p.refresh();
+
+            subject = new Subject();
+            subject.getPrincipals().add(new MyPrincipal("duke"));
+
+            e = p.getPermissions(subject, null).elements();
+
+            per = (Permission) e.nextElement();
+            assertFalse("Elements: ", e.hasMoreElements());
+            assertEquals("Permission: ", per, new FilePermission("/home/duke",
+                    "read, write"));
+
+            //
+            // second policy file to be read
+            //
+            System.setProperty(POLICY_PROP, inputFile2);
+
+            p.refresh();
+
+            e = p.getPermissions(subject, null).elements();
+
+            per = (Permission) e.nextElement();
+            assertFalse("Elements: ", e.hasMoreElements());
+            assertEquals("Permission: ", per, new RuntimePermission(
+                    "createClassLoader"));
+        } finally {
+            TestUtils.setSystemProperty(POLICY_PROP, oldProp);
+        }
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/test/TestUtils.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/test/TestUtils.java?rev=386061&r1=386060&r2=386061&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/test/TestUtils.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/test/TestUtils.java Wed Mar 15 04:21:13 2006
@@ -1,68 +1,85 @@
-/*
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-/**
-* @author Vladimir N. Molotkov
-* @version $Revision$
-*/
-
-package org.apache.harmony.security.test;
-
-import java.io.File;
-
-/**
- * Test utility class
- * 
- */
-public class TestUtils {
-    /**
-     * Relative (to the project home) test root path
-     */
-    public static final String TEST_ROOT = System.getProperty("TEST_SRC_DIR", "test/common/unit")+ File.separator;
-
-    /**
-     * No need to instantiate
-     */
-    private TestUtils() {
-    }
-
-    /**
-     * Prints byte array <code>data</code> as hex to the
-     * <code>System.out</code> in the customizable form.
-     *
-     * @param perLine how many numbers put on single line
-     * @param prefix custom output number prefix
-     * @param delimiter custom output number delimiter
-     * @param data data to be printed
-     */
-    public static void printAsHex(int perLine,
-                                  String prefix,
-                                  String delimiter,
-                                  byte[] data) {
-        for (int i=0; i<data.length; i++) {
-            String tail = Integer.toHexString(0x000000ff & data[i]);
-            if (tail.length() == 1) {
-                tail = "0" + tail; 
-            }
-            System.out.print(prefix + "0x" + tail + delimiter);
-
-            if (((i+1)%perLine) == 0) {
-                System.out.println("");
-            }
-        }
-        System.out.println("");
-    }
-}
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.test;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * Test utility class
+ * 
+ */
+public class TestUtils {
+    /**
+     * Relative (to the project home) test root path
+     */
+    public static final String TEST_ROOT = System.getProperty("TEST_SRC_DIR", "test/common/unit")+ File.separator;
+
+    /**
+     * No need to instantiate
+     */
+    private TestUtils() {
+    }
+
+    /**
+     * Prints byte array <code>data</code> as hex to the
+     * <code>System.out</code> in the customizable form.
+     *
+     * @param perLine how many numbers put on single line
+     * @param prefix custom output number prefix
+     * @param delimiter custom output number delimiter
+     * @param data data to be printed
+     */
+    public static void printAsHex(int perLine,
+                                  String prefix,
+                                  String delimiter,
+                                  byte[] data) {
+        for (int i=0; i<data.length; i++) {
+            String tail = Integer.toHexString(0x000000ff & data[i]);
+            if (tail.length() == 1) {
+                tail = "0" + tail; 
+            }
+            System.out.print(prefix + "0x" + tail + delimiter);
+
+            if (((i+1)%perLine) == 0) {
+                System.out.println("");
+            }
+        }
+        System.out.println("");
+    }
+    
+    /**
+     * Sets system property
+     *
+     * @param key - the name of the system property.
+     * @param value - the value to be set
+     */
+    public static void setSystemProperty(String key, String value) {
+        Properties properties = System.getProperties();
+        if (value == null) {
+            properties.remove(key);
+        } else {
+            properties.setProperty(key, value);
+        }
+        System.setProperties(properties);
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/x/security/auth/login/DefaultConfigurationTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/x/security/auth/login/DefaultConfigurationTest.java?rev=386061&r1=386060&r2=386061&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/x/security/auth/login/DefaultConfigurationTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/test/common/unit/org/apache/harmony/security/x/security/auth/login/DefaultConfigurationTest.java Wed Mar 15 04:21:13 2006
@@ -1,273 +1,274 @@
-/*
- *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-/**
-* @author Maxim V. Makarov
-* @version $Revision$
-*/
-
-package org.apache.harmony.security.x.security.auth.login;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.security.Permission;
-import java.security.Security;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.security.auth.AuthPermission;
-import javax.security.auth.login.AppConfigurationEntry;
-
-import junit.framework.TestCase;
-import org.apache.harmony.security.x.security.auth.login.DefaultConfiguration;
-
-
-/**
- * Tests default configuration implementation.  
- */
-
-public class DefaultConfigurationTest extends TestCase {
-
-    static String outputPath = System.getProperty("TEST_SRC_DIR", "test/common/unit");
-    
-    static String otherConfFile = outputPath + File.separator + "org" + 
-        File.separator + "apache" + File.separator + "harmony" + 
-        File.separator + "security" + File.separator + "x" + 
-        File.separator + "security"  + File.separator + "auth" +
-        File.separator + "login"  + File.separator + "jaas.conf";
-
-	private static File defaultConfFile;
-
-	static AppConfigurationEntry[] ents = null;
-
-	SecurityManager old = System.getSecurityManager();
-
-	String oldp1 = null;
-	String oldp2 = null;
-
-	public void setUp() throws Exception {
-		createConfFile();
-		try {
-			oldp1 = Security.getProperty("login.config.url.1");
-			oldp2 = Security.getProperty("login.config.url.2");
-		} catch (NullPointerException e) {
-		}
-
-	}
-
-	public void tearDown() throws Exception {
-		System.setSecurityManager(old);
-		try {
-			Security.setProperty("login.config.url.1", oldp1);
-			Security.setProperty("login.config.url.2", oldp2);
-		} catch (NullPointerException e) {
-		}
-		defaultConfFile.delete();
-	}
-
-	public static void main(String[] args) {
-		junit.textui.TestRunner.run(DefaultConfigurationTest.class);
-	}
-	
-	/**
-	 * loading a config file specified on the security property  
-	 * using login.config.url.1
-	 * 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();
-			ents = dc.getAppConfigurationEntry("LoginNew");
-			assertNotNull(ents);
-			assertEquals("com.intel.security.auth.module.LoginModule1", ents[0].getLoginModuleName());
-			Map m = new HashMap();
-			m.put("debug", "true");
-			m.put("test", "false");
-			assertEquals(m, ents[0].getOptions());
-			assertEquals("LoginModuleControlFlag: optional", ents[0].getControlFlag().toString());
-
-			ents = dc.getAppConfigurationEntry("Login1");
-			assertNotNull(ents);
-			for (int i = 0; i < ents.length; i++) {
-				assertEquals("com.intel.security.auth.module.LoginModule1",
-						ents[i].getLoginModuleName());
-				m.clear();
-				m.put("debug1", "true");
-				m.put("test1", "false");
-				assertEquals(m, ents[i].getOptions());
-				assertEquals("LoginModuleControlFlag: required", ents[i]
-						.getControlFlag().toString());
-			}
-			
-			
-			
-	}
-	/**
-	 * loading a config file specified on the system property
-	 * using -Djava.security.auth.login.config    
-	 */
-	public void testLoadConfigFile_1() throws IOException {
-		try {
-		String oldp = System.getProperty("java.security.auth.login.config");	
-		System.setProperty("java.security.auth.login.config", 
-				new File(otherConfFile).getCanonicalPath());
-		DefaultConfiguration dc = new DefaultConfiguration();
-		assertNotNull(dc);
-		
-		ents = dc.getAppConfigurationEntry("Login2");
-		assertNotNull(ents);
-		ents = dc.getAppConfigurationEntry("other");
-		assertNotNull(ents);
-		ents = dc.getAppConfigurationEntry("Login1");
-		assertNotNull(ents);
-		Map m = new HashMap();
-		for (int i = 0; i < ents.length; i++) {
-			assertEquals("com.intel.security.auth.module.LoginModule1",
-					ents[i].getLoginModuleName());
-			m.clear();
-			m.put("debug1", "true");
-			m.put("test1", "false");
-			assertEquals(m, ents[i].getOptions());
-			assertEquals("LoginModuleControlFlag: required", ents[i]
-					.getControlFlag().toString());
-		}
-		
-		ents = dc.getAppConfigurationEntry("Login7");
-		assertNotNull(ents);
-
-		
-		assertEquals("com.intel.security.auth.module.LoginModule1", ents[0].getLoginModuleName());
-		assertEquals("com.intel.security.auth.module.LoginModule2", ents[1].getLoginModuleName());
-		assertEquals("com.intel.security.auth.module.LoginModule3", ents[2].getLoginModuleName());
-		assertEquals("com.intel.security.auth.module.LoginModule4",  ents[3].getLoginModuleName());
-		
-		assertEquals("LoginModuleControlFlag: required", ents[0].getControlFlag().toString());
-		assertEquals("LoginModuleControlFlag: optional", ents[1].getControlFlag().toString());
-		assertEquals("LoginModuleControlFlag: sufficient", ents[2].getControlFlag().toString());
-		assertEquals("LoginModuleControlFlag: requisite", ents[3].getControlFlag().toString());
-		
-		m.clear();
-		m.put("AAAA", "true");
-		m.put("BBB", "false");
-		assertEquals(m, ents[0].getOptions());
-		m.clear();
-		m.put("debug2", "true");
-		assertEquals(m, ents[1].getOptions());
-		m.clear();
-		m.put("debug2", "false");
-		assertEquals(m, ents[2].getOptions());
-		m.clear();
-		m.put("ticketCache", System.getProperty("user.home")+ File.separator+"tickets");
-		m.put("useTicketCache", "true");
-		assertEquals(m, ents[3].getOptions());
-
-		} finally {
-			System.setProperty("java.security.auth.login.config","");
-		}
-	}
-	/**
-	 * test of the refresh method
-	 */
-	public void testRefresh() throws IOException {
-		try {
-			String oldp = System.getProperty("java.security.auth.login.config");	
-			System.setProperty("java.security.auth.login.config", 
-					new File(otherConfFile).getCanonicalPath());
-
-		DefaultConfiguration dc = new DefaultConfiguration();
-		MySecurityManager checker = new MySecurityManager(new AuthPermission(
-				"refreshLoginConfiguration"), true);
-		System.setSecurityManager(checker);
-		dc.refresh();
-		assertTrue(checker.checkAsserted);
-		checker.reset();
-		checker.enableAccess = false;
-		try {
-			dc.refresh();
-			fail("No expected SecurityException");
-		} catch (SecurityException ex) {
-		}
-		} finally {
-		    System.setProperty("java.security.auth.login.config","");
-		}
-
-	}
-
-	private static void createConfFile() throws SecurityException, IOException {
-		
-		defaultConfFile = File.createTempFile(".java.login.config", null);
-
-		String newConfFile = "LoginNew {\n com.intel.security.auth.module.LoginModule1 optional"
-			+ " debug=\"true\" test=false;\n};";
-
-		byte[] b = newConfFile.getBytes();
-
-		OutputStream os = new FileOutputStream(defaultConfFile);
-		for (int j = 0; j < b.length; j++) {
-			os.write(b[j]);
-		}
-		os.flush();
-		os.close();
-	}
-
-	/**
-	 * Easy the SecurityManager class
-	 * 
-	 */
-
-	class MySecurityManager extends SecurityManager {
-
-		public boolean enableAccess;
-
-		public Permission checkTarget;
-
-		public boolean checkAsserted;
-
-		public MySecurityManager(Permission target, boolean enable) {
-			checkAsserted = false;
-			checkTarget = target;
-			enableAccess = enable;
-		}
-
-		public void checkPermission(Permission p) {
-			if (p instanceof AuthPermission && checkTarget.equals(p)) {
-				checkAsserted = true;
-				if (!enableAccess) {
-					throw new SecurityException();
-				}
-			}
-		}
-
-		public MySecurityManager reset() {
-			checkAsserted = false;
-			return this;
-		}
-	}
-	
-}
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+* @author Maxim V. Makarov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.x.security.auth.login;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.security.Permission;
+import java.security.Security;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.AuthPermission;
+import javax.security.auth.login.AppConfigurationEntry;
+
+import junit.framework.TestCase;
+import org.apache.harmony.security.test.TestUtils;
+import org.apache.harmony.security.x.security.auth.login.DefaultConfiguration;
+
+
+/**
+ * Tests default configuration implementation.  
+ */
+
+public class DefaultConfigurationTest extends TestCase {
+
+    private static final String LOGIN_CONFIG = "java.security.auth.login.config";
+    
+    static String outputPath = System.getProperty("TEST_SRC_DIR", "test/common/unit");
+    
+    static String otherConfFile = outputPath + File.separator + "org" + 
+        File.separator + "apache" + File.separator + "harmony" + 
+        File.separator + "security" + File.separator + "x" + 
+        File.separator + "security"  + File.separator + "auth" +
+        File.separator + "login"  + File.separator + "jaas.conf";
+
+	private static File defaultConfFile;
+
+	static AppConfigurationEntry[] ents = null;
+
+	SecurityManager old = System.getSecurityManager();
+
+	String oldp1 = null;
+	String oldp2 = null;
+
+	public void setUp() throws Exception {
+		createConfFile();
+		
+		oldp1 = Security.getProperty("login.config.url.1");
+		oldp2 = Security.getProperty("login.config.url.2");
+	}
+
+	public void tearDown() throws Exception {
+		System.setSecurityManager(old);
+
+		TestUtils.setSystemProperty("login.config.url.1", oldp1);
+		TestUtils.setSystemProperty("login.config.url.2", oldp2);
+
+		defaultConfFile.delete();
+	}
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(DefaultConfigurationTest.class);
+	}
+	
+	/**
+	 * loading a config file specified on the security property  
+	 * using login.config.url.1
+	 * 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();
+			ents = dc.getAppConfigurationEntry("LoginNew");
+			assertNotNull(ents);
+			assertEquals("com.intel.security.auth.module.LoginModule1", ents[0].getLoginModuleName());
+			Map m = new HashMap();
+			m.put("debug", "true");
+			m.put("test", "false");
+			assertEquals(m, ents[0].getOptions());
+			assertEquals("LoginModuleControlFlag: optional", ents[0].getControlFlag().toString());
+
+			ents = dc.getAppConfigurationEntry("Login1");
+			assertNotNull(ents);
+			for (int i = 0; i < ents.length; i++) {
+				assertEquals("com.intel.security.auth.module.LoginModule1",
+						ents[i].getLoginModuleName());
+				m.clear();
+				m.put("debug1", "true");
+				m.put("test1", "false");
+				assertEquals(m, ents[i].getOptions());
+				assertEquals("LoginModuleControlFlag: required", ents[i]
+						.getControlFlag().toString());
+			}
+			
+			
+			
+	}
+	/**
+	 * loading a config file specified on the system property
+	 * using -Djava.security.auth.login.config    
+	 */
+	public void testLoadConfigFile_1() throws IOException {
+		
+	    String oldp = System.getProperty(LOGIN_CONFIG);	
+		try {
+		System.setProperty(LOGIN_CONFIG, 
+				new File(otherConfFile).getCanonicalPath());
+		DefaultConfiguration dc = new DefaultConfiguration();
+		assertNotNull(dc);
+		
+		ents = dc.getAppConfigurationEntry("Login2");
+		assertNotNull(ents);
+		ents = dc.getAppConfigurationEntry("other");
+		assertNotNull(ents);
+		ents = dc.getAppConfigurationEntry("Login1");
+		assertNotNull(ents);
+		Map m = new HashMap();
+		for (int i = 0; i < ents.length; i++) {
+			assertEquals("com.intel.security.auth.module.LoginModule1",
+					ents[i].getLoginModuleName());
+			m.clear();
+			m.put("debug1", "true");
+			m.put("test1", "false");
+			assertEquals(m, ents[i].getOptions());
+			assertEquals("LoginModuleControlFlag: required", ents[i]
+					.getControlFlag().toString());
+		}
+		
+		ents = dc.getAppConfigurationEntry("Login7");
+		assertNotNull(ents);
+
+		
+		assertEquals("com.intel.security.auth.module.LoginModule1", ents[0].getLoginModuleName());
+		assertEquals("com.intel.security.auth.module.LoginModule2", ents[1].getLoginModuleName());
+		assertEquals("com.intel.security.auth.module.LoginModule3", ents[2].getLoginModuleName());
+		assertEquals("com.intel.security.auth.module.LoginModule4",  ents[3].getLoginModuleName());
+		
+		assertEquals("LoginModuleControlFlag: required", ents[0].getControlFlag().toString());
+		assertEquals("LoginModuleControlFlag: optional", ents[1].getControlFlag().toString());
+		assertEquals("LoginModuleControlFlag: sufficient", ents[2].getControlFlag().toString());
+		assertEquals("LoginModuleControlFlag: requisite", ents[3].getControlFlag().toString());
+		
+		m.clear();
+		m.put("AAAA", "true");
+		m.put("BBB", "false");
+		assertEquals(m, ents[0].getOptions());
+		m.clear();
+		m.put("debug2", "true");
+		assertEquals(m, ents[1].getOptions());
+		m.clear();
+		m.put("debug2", "false");
+		assertEquals(m, ents[2].getOptions());
+		m.clear();
+		m.put("ticketCache", System.getProperty("user.home")+ File.separator+"tickets");
+		m.put("useTicketCache", "true");
+		assertEquals(m, ents[3].getOptions());
+
+		} finally {
+		    TestUtils.setSystemProperty(LOGIN_CONFIG, oldp);
+		}
+	}
+	/**
+	 * test of the refresh method
+	 */
+	public void testRefresh() throws IOException {
+	    
+	    String oldp = System.getProperty(LOGIN_CONFIG);
+		try {
+			System.setProperty(LOGIN_CONFIG, 
+					new File(otherConfFile).getCanonicalPath());
+
+		DefaultConfiguration dc = new DefaultConfiguration();
+		MySecurityManager checker = new MySecurityManager(new AuthPermission(
+				"refreshLoginConfiguration"), true);
+		System.setSecurityManager(checker);
+		dc.refresh();
+		assertTrue(checker.checkAsserted);
+		checker.reset();
+		checker.enableAccess = false;
+		try {
+			dc.refresh();
+			fail("No expected SecurityException");
+		} catch (SecurityException ex) {
+		}
+		} finally {
+		    TestUtils.setSystemProperty(LOGIN_CONFIG, oldp);
+		}
+
+	}
+
+	private static void createConfFile() throws SecurityException, IOException {
+		
+		defaultConfFile = File.createTempFile(".java.login.config", null);
+
+		String newConfFile = "LoginNew {\n com.intel.security.auth.module.LoginModule1 optional"
+			+ " debug=\"true\" test=false;\n};";
+
+		byte[] b = newConfFile.getBytes();
+
+		OutputStream os = new FileOutputStream(defaultConfFile);
+		for (int j = 0; j < b.length; j++) {
+			os.write(b[j]);
+		}
+		os.flush();
+		os.close();
+	}
+
+	/**
+	 * Easy the SecurityManager class
+	 * 
+	 */
+
+	class MySecurityManager extends SecurityManager {
+
+		public boolean enableAccess;
+
+		public Permission checkTarget;
+
+		public boolean checkAsserted;
+
+		public MySecurityManager(Permission target, boolean enable) {
+			checkAsserted = false;
+			checkTarget = target;
+			enableAccess = enable;
+		}
+
+		public void checkPermission(Permission p) {
+			if (p instanceof AuthPermission && checkTarget.equals(p)) {
+				checkAsserted = true;
+				if (!enableAccess) {
+					throw new SecurityException();
+				}
+			}
+		}
+
+		public MySecurityManager reset() {
+			checkAsserted = false;
+			return this;
+		}
+	}
+	
+}



Mime
View raw message