harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r832730 - in /harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security: Policy.java ProtectionDomain.java
Date Wed, 04 Nov 2009 12:55:06 GMT
Author: tellison
Date: Wed Nov  4 12:55:06 2009
New Revision: 832730

URL: http://svn.apache.org/viewvc?rev=832730&view=rev
Log:
Part of HARMONY-6367 ([classlib] Some Methods doesn't have security Permissions check as compared
to SUN JDK)
Ensure that there is a getPolicy check during ProtectionDomain#toString()

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Policy.java
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/ProtectionDomain.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Policy.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Policy.java?rev=832730&r1=832729&r2=832730&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Policy.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Policy.java
Wed Nov  4 12:55:06 2009
@@ -44,7 +44,7 @@
             "setPolicy"); //$NON-NLS-1$
 
     // The SecurityPermission required to get current Policy.
-    private static final SecurityPermission GET_POLICY = new SecurityPermission(
+    static final SecurityPermission GET_POLICY = new SecurityPermission(
             "getPolicy"); //$NON-NLS-1$
 
     // The policy currently in effect. 

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/ProtectionDomain.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/ProtectionDomain.java?rev=832730&r1=832729&r2=832730&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/ProtectionDomain.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/ProtectionDomain.java
Wed Nov  4 12:55:06 2009
@@ -244,13 +244,17 @@
 
         if (dynamicPerms) {
             if (Policy.isSet()) {
-                PermissionCollection perms;
-                perms = Policy.getAccessiblePolicy().getPermissions(this);
-                if (perms == null) {
-                    buf.append("\t\t<no dynamic permissions>\n"); //$NON-NLS-1$
+                if (canGetPolicy()) {
+                    PermissionCollection perms;
+                    perms = Policy.getAccessiblePolicy().getPermissions(this);
+                    if (perms == null) {
+                        buf.append("\t\t<no dynamic permissions>\n"); //$NON-NLS-1$
+                    } else {
+                        buf.append("\t\tdynamic: ").append(perms.toString()) //$NON-NLS-1$
+                                .append("\n"); //$NON-NLS-1$
+                    }
                 } else {
-                    buf.append("\t\tdynamic: ").append(perms.toString()) //$NON-NLS-1$
-                            .append("\n"); //$NON-NLS-1$
+                    buf.append("\t\t<no rights to retrieve dynamic permissions>\n");
//$NON-NLS-1$
                 }
             } else {
                 buf.append("\t\t<no dynamic permissions>\n"); //$NON-NLS-1$
@@ -258,4 +262,20 @@
         }
         return buf.toString();
     }
+    
+    /*
+     * Returns true if the caller has permission to retrieve the current
+     * security policy settings, or false if not.
+     */
+    private boolean canGetPolicy() {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null) {
+            try {
+                sm.checkPermission(Policy.GET_POLICY);
+            } catch (SecurityException e) {
+                return false;
+            }
+        }
+        return true;
+    }
 }



Mime
View raw message