src/java.base/share/classes/java/security/ProtectionDomain.java

Print this page
rev 10552 : 8055723[core]: Replace concat String to append in StringBuilder parameters
Contributed-by: Otavio Santana <otaviojava@java.net>


 268             return true;
 269         }
 270 
 271         if (!staticPermissions &&
 272             Policy.getPolicyNoCheck().implies(this, permission))
 273             return true;
 274         if (permissions != null)
 275             return permissions.implies(permission);
 276 
 277         return false;
 278     }
 279 
 280     // called by the VM -- do not remove
 281     boolean impliesCreateAccessControlContext() {
 282         return implies(SecurityConstants.CREATE_ACC_PERMISSION);
 283     }
 284 
 285     /**
 286      * Convert a ProtectionDomain to a String.
 287      */
 288     @Override public String toString() {

 289         String pals = "<no principals>";
 290         if (principals != null && principals.length > 0) {
 291             StringBuilder palBuf = new StringBuilder("(principals ");
 292 
 293             for (int i = 0; i < principals.length; i++) {
 294                 palBuf.append(principals[i].getClass().getName() +
 295                             " \"" + principals[i].getName() +
 296                             "\"");
 297                 if (i < principals.length-1)
 298                     palBuf.append(",\n");
 299                 else
 300                     palBuf.append(")\n");

 301             }
 302             pals = palBuf.toString();
 303         }
 304 
 305         // Check if policy is set; we don't want to load
 306         // the policy prematurely here
 307         PermissionCollection pc = Policy.isSet() && seeAllp() ?
 308                                       mergePermissions():
 309                                       getPermissions();
 310 
 311         return "ProtectionDomain "+
 312             " "+codesource+"\n"+
 313             " "+classloader+"\n"+
 314             " "+pals+"\n"+
 315             " "+pc+"\n";
 316     }
 317 
 318     /**
 319      * Return true (merge policy permissions) in the following cases:
 320      *
 321      * . SecurityManager is null
 322      *
 323      * . SecurityManager is not null,
 324      *          debug is not null,
 325      *          SecurityManager impelmentation is in bootclasspath,
 326      *          Policy implementation is in bootclasspath
 327      *          (the bootclasspath restrictions avoid recursion)
 328      *
 329      * . SecurityManager is not null,
 330      *          debug is null,
 331      *          caller has Policy.getPolicy permission
 332      */
 333     private static boolean seeAllp() {
 334         SecurityManager sm = System.getSecurityManager();
 335 




 268             return true;
 269         }
 270 
 271         if (!staticPermissions &&
 272             Policy.getPolicyNoCheck().implies(this, permission))
 273             return true;
 274         if (permissions != null)
 275             return permissions.implies(permission);
 276 
 277         return false;
 278     }
 279 
 280     // called by the VM -- do not remove
 281     boolean impliesCreateAccessControlContext() {
 282         return implies(SecurityConstants.CREATE_ACC_PERMISSION);
 283     }
 284 
 285     /**
 286      * Convert a ProtectionDomain to a String.
 287      */
 288     @Override
 289     public String toString() {
 290         String pals = "<no principals>";
 291         if (principals != null && principals.length > 0) {
 292             StringBuilder palBuilder = new StringBuilder("(principals ");
 293 
 294             for (int i = 0; i < principals.length; i++) {
 295                 palBuilder.append(principals[i].getClass().getName());
 296                 palBuilder.append(" \"").append(principals[i].getName());
 297                 palBuilder.append('"');
 298                 if (i < principals.length - 1) {
 299                     palBuilder.append(",\n");
 300                 } else {
 301                     palBuilder.append(")\n");
 302                 }
 303             }
 304             pals = palBuilder.toString();
 305         }
 306 
 307         // Check if policy is set; we don't want to load
 308         // the policy prematurely here
 309         PermissionCollection pc = Policy.isSet() && seeAllp() ? mergePermissions()
 310                 : getPermissions();
 311 
 312         return "ProtectionDomain " + " " + codesource + "\n" + " "
 313                 + classloader + "\n" + " " + pals + "\n" + " " + pc + "\n";




 314     }
 315 
 316     /**
 317      * Return true (merge policy permissions) in the following cases:
 318      *
 319      * . SecurityManager is null
 320      *
 321      * . SecurityManager is not null,
 322      *          debug is not null,
 323      *          SecurityManager impelmentation is in bootclasspath,
 324      *          Policy implementation is in bootclasspath
 325      *          (the bootclasspath restrictions avoid recursion)
 326      *
 327      * . SecurityManager is not null,
 328      *          debug is null,
 329      *          caller has Policy.getPolicy permission
 330      */
 331     private static boolean seeAllp() {
 332         SecurityManager sm = System.getSecurityManager();
 333