📄 useradminpermission.java
字号:
private static boolean match_credential(char[] a, int i) { return ((a[i - 9] == 'c' || a[i - 9] == 'C') && (a[i - 8] == 'r' || a[i - 8] == 'R') && (a[i - 7] == 'e' || a[i - 7] == 'E') && (a[i - 6] == 'd' || a[i - 6] == 'D') && (a[i - 5] == 'e' || a[i - 5] == 'E') && (a[i - 4] == 'n' || a[i - 4] == 'N') && (a[i - 3] == 't' || a[i - 3] == 'T') && (a[i - 2] == 'i' || a[i - 2] == 'I') && (a[i - 1] == 'a' || a[i - 1] == 'A') && (a[i - 0] == 'l' || a[i - 0] == 'L')); } /** * Checks if this <tt>UserAdminPermission</tt> object "implies" * the specified permission. * <P> * More specifically, this method returns <tt>true</tt> if: * <p> * <ul> * <li> <i>p</i> is an instanceof <tt>UserAdminPermission</tt>, * <li> <i>p</i>'s actions are a proper subset of this object's actions, * and * <li> <i>p</i>'s name is implied by this object's name. For example, * "java.*" implies "java.home". * </ul> * * @param p * the permission to check against. * * @return <tt>true</tt> if the specified permission is implied by this * object; <tt>false</tt> otherwise. */ public boolean implies(Permission p) { if (p instanceof UserAdminPermission) { UserAdminPermission target = (UserAdminPermission) p; return (// Check that the we have the requested action ((target.action_mask & action_mask) == target.action_mask) && // If the target action mask is ACTION_NONE, it must be an // admin permission, and then we must be that too (target.action_mask != ACTION_NONE || action_mask == ACTION_NONE) && // Check that name name matches super.implies(p)); } return (false); } /** * Returns the canonical string representation of the actions, separated by * comma. * * @return the canonical string representation of the actions. */ public String getActions() { if (actions == null) { StringBuffer sb = new StringBuffer(); boolean comma = false; if ((action_mask & ACTION_CHANGE_CREDENTIAL) == ACTION_CHANGE_CREDENTIAL) { sb.append(CHANGE_CREDENTIAL); comma = true; } if ((action_mask & ACTION_CHANGE_PROPERTY) == ACTION_CHANGE_PROPERTY) { if (comma) sb.append(','); sb.append(CHANGE_PROPERTY); comma = true; } if ((action_mask & ACTION_GET_CREDENTIAL) == ACTION_GET_CREDENTIAL) { if (comma) sb.append(','); sb.append(GET_CREDENTIAL); } actions = sb.toString(); } return (actions); } /** * Returns a new <tt>PermissionCollection</tt> object for storing * <tt>UserAdminPermission</tt> objects. * * @return a new <tt>PermissionCollection</tt> object suitable for storing * <tt>UserAdminPermission</tt> objects. */ public PermissionCollection newPermissionCollection() { return (new UserAdminPermissionCollection()); } /** * Checks two <tt>UserAdminPermission</tt> objects for equality. Checks * that <tt>obj</tt> is a <tt>UserAdminPermission</tt>, and has the * same name and actions as this object. * * @param obj * the object to be compared for equality with this object. * * @return <tt>true</tt> if <tt>obj</tt> is a * <tt>UserAdminPermission</tt> object, and has the same name and * actions as this <tt>UserAdminPermission</tt> object. */ public boolean equals(Object obj) { if (obj == this) { return (true); } if (obj instanceof UserAdminPermission) { UserAdminPermission uap = (UserAdminPermission) obj; return ((action_mask == uap.action_mask) && getName().equals( uap.getName())); } return (false); } /** * Returns the hash code of this <tt>UserAdminPermission</tt> object. */ public int hashCode() { return (getName().hashCode() ^ getActions().hashCode()); } /** * Returns the current action mask. Used by the * <tt>UserAdminPermissionCollection</tt> class. * * @return the actions mask. */ int getMask() { return (action_mask); } /** * writeObject is called to save the state of this object 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(); } /* * Restores this object from a stream (i.e., deserializes it). */ private synchronized void readObject(java.io.ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject(); init(getMask(actions)); } /** * Returns a string describing this <tt>UserAdminPermission</tt> object. * This string must be in <tt>PermissionInfo</tt> encoded format. * * @return The <tt>PermissionInfo</tt> encoded string for this * <tt>UserAdminPermission</tt> object. * TODO@see org.osgi.service.permissionadmin.PermissionInfo#getEncoded */ public String toString() { if (description == null) { StringBuffer sb = new StringBuffer(); sb.append('('); sb.append(getClass().getName()); sb.append(" \""); sb.append(getName()); String actions = getActions(); if (actions.length() > 0) { sb.append("\" \""); sb.append(actions); } sb.append("\")"); description = sb.toString(); } return (description); }}/** * A <tt>UserAdminPermissionCollection</tt> stores a set of * <tt>UserAdminPermission</tt> permissions. */final class UserAdminPermissionCollection extends PermissionCollection { private static final long serialVersionUID = 1L; /** * Table of permissions. * * @serial */ private Hashtable permissions; /** * Boolean saying if "*" is in the collection. * * @serial */ private boolean all_allowed; /** * Creates an empty <tt>UserAdminPermissionCollection</tt> object. */ public UserAdminPermissionCollection() { permissions = new Hashtable(); all_allowed = false; } /** * Adds the given permission to this <tt>UserAdminPermissionCollection</tt>. * The key for the hash is the name. * * @param permission * the <tt>Permission</tt> object to add. * * @throws IllegalArgumentException * If the given permission is not a <tt>UserAdminPermission</tt> * @throws SecurityException * If this <tt>UserAdminPermissionCollection</tt> object has * been marked readonly */ public void add(Permission permission) { if (!(permission instanceof UserAdminPermission)) throw new IllegalArgumentException("Invalid permission: " + permission); if (isReadOnly()) { throw new SecurityException("Attempt to add a Permission to a " + "readonly PermissionCollection"); } UserAdminPermission uap = (UserAdminPermission) permission; String name = uap.getName(); UserAdminPermission existing = (UserAdminPermission) permissions .get(name); if (existing != null) { int oldMask = existing.getMask(); int newMask = uap.getMask(); if (oldMask != newMask) { permissions.put(name, new UserAdminPermission(name, oldMask | newMask)); } } else { permissions.put(name, permission); } if (!all_allowed) { if (name.equals("*")) all_allowed = true; } } /** * Checks to see if this <tt>PermissionCollection</tt> implies the given * permission. * * @param permission * the <tt>Permission</tt> object to check against * * @return true if the given permission is implied by this * <tt>PermissionCollection</tt>, false otherwise. */ public boolean implies(Permission permission) { if (!(permission instanceof UserAdminPermission)) { return (false); } UserAdminPermission uap = (UserAdminPermission) permission; UserAdminPermission x; int desired = uap.getMask(); int effective = 0; // Short circuit if the "*" Permission was added. // desired can only be ACTION_NONE when name is "admin". if (all_allowed && desired != UserAdminPermission.ACTION_NONE) { x = (UserAdminPermission) 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 = uap.getName(); x = (UserAdminPermission) 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; int offset = name.length() - 1; while ((last = name.lastIndexOf(".", offset)) != -1) { name = name.substring(0, last + 1) + "*"; x = (UserAdminPermission) 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>UserAdminPermission</tt> objects * in the container. * * @return an enumeration of all the <tt>UserAdminPermission</tt> objects. */ public Enumeration elements() { return (permissions.elements()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -