?? servicepermission.java
字號:
sb.append(REGISTER); } actions = sb.toString(); } return(actions); } /** * Returns a new <tt>PermissionCollection</tt> object for storing * <tt>ServicePermission<tt> objects. * * @return A new <tt>PermissionCollection</tt> object suitable for storing * <tt>ServicePermission</tt> objects. */ public PermissionCollection newPermissionCollection() { return (new ServicePermissionCollection()); } /** * Determines the equalty of two ServicePermission objects. * * Checks that specified object has the same class name * and action as this <tt>ServicePermission</tt>. * * @param obj The object to test for equality. * @return true if obj is a <tt>ServicePermission</tt>, and has the * same class name and actions as this <tt>ServicePermission</tt> object; <tt>false</tt> otherwise. */ public boolean equals(Object obj) { if (obj == this) { return(true); } if (!(obj instanceof ServicePermission)) { return(false); } ServicePermission p = (ServicePermission) obj; return((action_mask == p.action_mask) && getName().equals(p.getName())); } /** * Returns the hash code value for this object. * * @return Hash code value for this object. */ public int hashCode() { return(getName().hashCode() ^ getActions().hashCode()); } /** * Returns the current action mask. * Used by the ServicePermissionCollection object. * * @return The actions mask. */ int getMask() { return (action_mask); } /** * WriteObject is called to save the state of the ServicePermission * to a stream. The actions are serialized, and the superclass * takes care of the name. */ private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException { // Write out the actions. The superclass takes care of the name // call getActions to make sure actions field is initialized if (actions == null) getActions(); s.defaultWriteObject(); } /** * readObject is called to restore the state of the ServicePermission from * a stream. */ private synchronized void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the action, then initialize the rest s.defaultReadObject(); init(getMask(actions)); }}/** * Stores a set of ServicePermission permissions. * * @see java.security.Permission * @see java.security.Permissions * @see java.security.PermissionCollection */final class ServicePermissionCollection extends PermissionCollection{ /** * Table of permissions. * * @serial */ private Hashtable permissions; /** * Boolean saying if "*" is in the collection. * * @serial */ private boolean all_allowed; /** * Creates an empty ServicePermissions object. * */ public ServicePermissionCollection() { permissions = new Hashtable(); all_allowed = false; } /** * Adds a permission to the <tt>ServicePermission</tt> objects using the key for the hash as * the name. * * @param permission The Permission object to add. * * @exception IllegalArgumentException If the permission is not a ServicePermission object. * * @exception SecurityException If this <tt>ServicePermissionCollection</tt> object has been marked read-only. */ public void add(Permission permission) { if (! (permission instanceof ServicePermission)) throw new IllegalArgumentException("invalid permission: "+ permission); if (isReadOnly()) throw new SecurityException("attempt to add a Permission to a " + "readonly PermissionCollection"); ServicePermission sp = (ServicePermission) permission; String name = sp.getName(); ServicePermission existing = (ServicePermission) permissions.get(name); if (existing != null) { int oldMask = existing.getMask(); int newMask = sp.getMask(); if (oldMask != newMask) { permissions.put(name, new ServicePermission(name, oldMask | newMask)); } } else { permissions.put(name, permission); } if (!all_allowed) { if (name.equals("*")) all_allowed = true; } } /** * Determines if a set of permissions implies the permissions * expressed in <tt>permission</tt>. * * @param p The Permission object to compare. * * @return <tt>true</tt> if <tt>permission</tt> is a proper subset of a permission in * the set; <tt>false</tt> otherwise. */ public boolean implies(Permission permission) { if (!(permission instanceof ServicePermission)) return (false); ServicePermission sp = (ServicePermission) permission; ServicePermission x; int desired = sp.getMask(); int effective = 0; // short circuit if the "*" Permission was added if (all_allowed) { x = (ServicePermission) permissions.get("*"); if (x != null) { effective |= x.getMask(); if ((effective & desired) == desired) return (true); } } // strategy: // Check for full match first. Then work our way up the // name looking for matches on a.b.* String name = sp.getName(); x = (ServicePermission) permissions.get(name); if (x != null) { // we have a direct hit! effective |= x.getMask(); if ((effective & desired) == desired) return (true); } // work our way up the tree... int last, offset; offset = name.length()-1; while ((last = name.lastIndexOf(".", offset)) != -1) { name = name.substring(0, last+1) + "*"; x = (ServicePermission) permissions.get(name); if (x != null) { effective |= x.getMask(); if ((effective & desired) == desired) return (true); } offset = last -1; } // we don't have to check for "*" as it was already checked // at the top (all_allowed), so we just return false return (false); } /** * Returns an enumeration of all the <tt>ServicePermission</tt> objects in the * container. * * @return Enumeration of all the ServicePermission objects. */ public Enumeration elements() { return (permissions.elements()); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -