/// <summary> /// Adds a permission to this UnresolvedPermissionCollection. /// The key for the hash is the unresolved permission's type (class) name. /// </summary> /// <param name="permission"> the Permission object to add. </param> public override void Add(Permission permission) { if (!(permission is UnresolvedPermission)) { throw new IllegalArgumentException("invalid permission: " + permission); } UnresolvedPermission up = (UnresolvedPermission)permission; List <UnresolvedPermission> v; lock (this) { v = Perms.Get(up.Name); if (v == null) { v = new List <UnresolvedPermission>(); Perms.Put(up.Name, v); } } lock (v) { v.Add(up); } }
/// <summary> /// Checks two UnresolvedPermission objects for equality. /// Checks that <i>obj</i> is an UnresolvedPermission, and has /// the same type (class) name, permission name, actions, and /// certificates as this object. /// /// <para> To determine certificate equality, this method only compares /// actual signer certificates. Supporting certificate chains /// are not taken into consideration by this method. /// /// </para> /// </summary> /// <param name="obj"> the object we are testing for equality with this object. /// </param> /// <returns> true if obj is an UnresolvedPermission, and has the same /// type (class) name, permission name, actions, and /// certificates as this object. </returns> public override bool Equals(Object obj) { if (obj == this) { return(true); } if (!(obj is UnresolvedPermission)) { return(false); } UnresolvedPermission that = (UnresolvedPermission)obj; // check type if (!this.Type.Equals(that.Type)) { return(false); } // check name if (this.Name == null) { if (that.Name != null) { return(false); } } else if (!this.Name.Equals(that.Name)) { return(false); } // check actions if (this.Actions_Renamed == null) { if (that.Actions_Renamed != null) { return(false); } } else { if (!this.Actions_Renamed.Equals(that.Actions_Renamed)) { return(false); } } // check certs if ((this.Certs == null && that.Certs != null) || (this.Certs != null && that.Certs == null) || (this.Certs != null && that.Certs != null && this.Certs.Length != that.Certs.Length)) { return(false); } int i, j; bool match; for (i = 0; this.Certs != null && i < this.Certs.Length; i++) { match = false; for (j = 0; j < that.Certs.Length; j++) { if (this.Certs[i].Equals(that.Certs[j])) { match = true; break; } } if (!match) { return(false); } } for (i = 0; that.Certs != null && i < that.Certs.Length; i++) { match = false; for (j = 0; j < this.Certs.Length; j++) { if (that.Certs[i].Equals(this.Certs[j])) { match = true; break; } } if (!match) { return(false); } } return(true); }
/// <summary> /// Resolves any unresolved permissions of type p. /// </summary> /// <param name="p"> the type of unresolved permission to resolve /// </param> /// <returns> PermissionCollection containing the unresolved permissions, /// or null if there were no unresolved permissions of type p. /// </returns> private PermissionCollection GetUnresolvedPermissions(Permission p) { // Called from within synchronized method so permsMap doesn't need lock UnresolvedPermissionCollection uc = (UnresolvedPermissionCollection)PermsMap[typeof(UnresolvedPermission)]; // we have no unresolved permissions if uc is null if (uc == null) { return(null); } IList <UnresolvedPermission> unresolvedPerms = uc.GetUnresolvedPermissions(p); // we have no unresolved permissions of this type if unresolvedPerms is null if (unresolvedPerms == null) { return(null); } java.security.cert.Certificate[] certs = null; Object[] signers = p.GetType().Signers; int n = 0; if (signers != null) { for (int j = 0; j < signers.Length; j++) { if (signers[j] is java.security.cert.Certificate) { n++; } } certs = new java.security.cert.Certificate[n]; n = 0; for (int j = 0; j < signers.Length; j++) { if (signers[j] is java.security.cert.Certificate) { certs[n++] = (java.security.cert.Certificate)signers[j]; } } } PermissionCollection pc = null; lock (unresolvedPerms) { int len = unresolvedPerms.Count; for (int i = 0; i < len; i++) { UnresolvedPermission up = unresolvedPerms[i]; Permission perm = up.Resolve(p, certs); if (perm != null) { if (pc == null) { pc = p.NewPermissionCollection(); if (pc == null) { pc = new PermissionsHash(); } } pc.Add(perm); } } } return(pc); }