/** * Indicates whether the specified permission is implied by this permission. * * @param permission * the permission to check against this permission. * @return {@code true} if the specified permission is implied by this * permission, {@code false} otherwise. */ public override bool implies(Permission permission) { if (permission != null && permission.getClass() == this.getClass()) { String name = getName(); String thatName = permission.getName(); if (this is java.lang.RuntimePermission) { if (thatName.equals("exitVM")) { thatName = "exitVM.*"; } if (name.equals("exitVM")) { name = "exitVM.*"; } } return(nameImplies(name, thatName)); } return(false); }
/** * Adds a permission to the collection. The first added permission must be a * subclass of BasicPermission, next permissions must be of the same class * as the first one. * * @see java.security.PermissionCollection#add(java.security.Permission) */ public override void add(Permission permission) { if (isReadOnly()) { throw new java.lang.SecurityException("collection is read-only"); //$NON-NLS-1$ } if (permission == null) { throw new java.lang.IllegalArgumentException("invalid null permission"); //$NON-NLS-1$ } java.lang.Class inClass = permission.getClass(); if (permClass != null) { if (permClass != inClass) { throw new java.lang.IllegalArgumentException("invalid permission: " + permission); } } else if (!(permission is BasicPermission)) { throw new java.lang.IllegalArgumentException("invalid permission: " + permission); } else { // this is the first element provided that another thread did not add lock (this) { if (permClass != null && inClass != permClass) { throw new java.lang.IllegalArgumentException("invalid permission: " + permission); } permClass = inClass; } } String name = permission.getName(); items.put(name, permission); allEnabled = allEnabled || (name.length() == 1 && '*' == name.charAt(0)); }
/* * Adds an unresolved permission to this {@code * UnresolvedPermissionCollection}. * * @param permission * the permission to be added. * @throws SecurityException * if this collection is read only. * @throws IllegalArgumentException * if {@code permission} is {@code null} or not an {@code * UnresolvedPermission}. */ public override void add(Permission permission) { if (isReadOnly()) { throw new java.lang.SecurityException("collection is read-only"); //$NON-NLS-1$ } if (permission == null || permission.getClass() != typeof(UnresolvedPermission).getClass()) { throw new java.lang.IllegalArgumentException("invalid permission: " + permission); } lock (klasses) { String klass = permission.getName(); java.util.Collection <Permission> klassMates = (java.util.Collection <Permission>)klasses.get(klass); if (klassMates == null) { klassMates = new java.util.HashSet <Permission>(); klasses.put(klass, klassMates); } klassMates.add(permission); } }
/** * Indicates whether the argument permission is implied by the receiver. * * @return boolean {@code true} if the argument permission is implied by the * receiver, and {@code false} if it is not. * @param permission * the permission to check. * @see Permission */ public override bool implies(Permission permission) { if (permission == null || permission.getClass() != permClass) { return(false); } if (allEnabled) { return(true); } String checkName = permission.getName(); //first check direct coincidence if (items.containsKey(checkName)) { return(true); } //Special treat with RuntimePermission exitVM.* if (items.containsKey("exitVM") || items.containsKey("exitVM.*")) { if (checkName.endsWith("exitVM")) { return(true); } if (checkName.startsWith("exitVM.") && checkName.length() > "exitVM.".length()) { return(true); } } //now check if there are suitable wildcards //suppose we have "a.b.c", let's check "a.b.*" and "a.*" char[] name = checkName.toCharArray(); //I presume that "a.b.*" does not imply "a.b." //so the dot at end is ignored int pos = name.Length - 2; for (; pos >= 0; pos--) { if (name[pos] == '.') { break; } } while (pos >= 0) { name[pos + 1] = '*'; if (items.containsKey(new String(name, 0, pos + 2))) { return(true); } for (--pos; pos >= 0; pos--) { if (name[pos] == '.') { break; } } } return(false); }