private bool defaultImplies(ProtectionDomain domain, Permission permission) { if (domain == null && permission == null) { throw new java.lang.NullPointerException(); } bool implies = false; if (domain != null) { PermissionCollection total = getPermissions(domain); PermissionCollection inherent = domain.getPermissions(); if (inherent != null) { java.util.Enumeration <Permission> en = inherent.elements(); while (en.hasMoreElements()) { total.add(en.nextElement()); } } try { implies = total.implies(permission); } catch (java.lang.NullPointerException) { // return false instead of throwing the NullPointerException implies = false; } } return(implies); }
/** * Returns a {@code PermissionCollection} describing what permissions are * allowed for the specified {@code ProtectionDomain} (more specifically, * its {@code CodeSource}) based on the current security policy. * <p /> * Note that this method is not called for classes which are in the * system domain (i.e. system classes). System classes are always * given full permissions (i.e. AllPermission). This can not be changed by * installing a new policy. * * @param domain * the {@code ProtectionDomain} to compute the permissions for. * @return the permissions that are granted to the specified {@code * CodeSource}. */ public PermissionCollection getPermissions(ProtectionDomain domain) { Permissions permissions = new Permissions(); if (domain != null) { try { PermissionCollection cds = getPermissions(domain .getCodeSource()); if (cds != Policy.UNSUPPORTED_EMPTY_COLLECTION) { java.util.Enumeration <Permission> elements = cds.elements(); while (elements.hasMoreElements()) { permissions.add(elements.nextElement()); } } } catch (java.lang.NullPointerException) { // ignore the exception, just add nothing to the result set } PermissionCollection pds = domain.getPermissions(); if (pds != null) { java.util.Enumeration <Permission> pdElements = pds.elements(); while (pdElements.hasMoreElements()) { permissions.add(pdElements.nextElement()); } } } return(permissions); }