final String name = cp.getName(); final Filter f = cp.filter; synchronized (this) { final int newMask = cp.action_mask; if (oldMask != newMask) { pc.put(name, new CapabilityPermission(name, oldMask | newMask));
/** * WriteObject is called to save the state of this permission 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 { if (bundle != null) { throw new NotSerializableException("cannot serialize"); } // 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(); }
/** * Internal implies method. Used by the implies and the permission * collection implies methods. * * @param requested The requested CapabilityPermission which has already be * validated as a proper argument. The requested CapabilityPermission * must not have a filter expression. * @param effective The effective actions with which to start. * @return {@code true} if the specified permission is implied by this * object; {@code false} otherwise. */ boolean implies0(CapabilityPermission requested, int effective) { /* check actions first - much faster */ effective |= action_mask; final int desired = requested.action_mask; if ((effective & desired) != desired) { return false; } /* Get filter if any */ Filter f = filter; if (f == null) { return super.implies(requested); } return f.matches(requested.getProperties()); }
/** * readObject is called to restore the state of this permission from a * stream. */ private synchronized void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the action, then initialize the rest s.defaultReadObject(); setTransients(getName(), parseActions(actions)); }
/** * Returns the hash code value for this object. * * @return Hash code value for this object. */ @Override public int hashCode() { int h = 31 * 17 + getName().hashCode(); h = 31 * h + getActions().hashCode(); if (attributes != null) { h = 31 * h + attributes.hashCode(); } if (bundle != null) { h = 31 * h + bundle.hashCode(); } return h; }
/** * Creates a new requested {@code CapabilityPermission} object to be used by * code that must perform {@code checkPermission} for the {@code require} * action. {@code CapabilityPermission} objects created with this * constructor cannot be added to a {@code CapabilityPermission} permission * collection. * * @param namespace The requested capability namespace. * @param attributes The requested capability attributes. * @param providingBundle The bundle providing the requested capability. * @param actions The action {@code require}. * @throws IllegalArgumentException If the specified action is not * {@code require} or attributes or providingBundle are {@code null} * . */ public CapabilityPermission(String namespace, Map<String, ?> attributes, Bundle providingBundle, String actions) { super(namespace); setTransients(namespace, parseActions(actions)); if (attributes == null) { throw new IllegalArgumentException("attributes must not be null"); } if (providingBundle == null) { throw new IllegalArgumentException("bundle must not be null"); } this.attributes = new HashMap<String, Object>(attributes); this.bundle = providingBundle; if ((action_mask & ACTION_ALL) != ACTION_REQUIRE) { throw new IllegalArgumentException("invalid action string"); } }
@Override boolean hasProvidePermission(BundleCapabilityImpl bc) { final BundleImpl b = bc.getBundleGeneration().bundle; if (b.id != 0) { final PermissionCollection pc = ph.getPermissionCollection(new Long(b.id)); return pc.implies(new CapabilityPermission(bc.getNamespace(), CapabilityPermission.PROVIDE)); } return true; }
/** * Called by constructors and when deserialized. * * @param mask action mask */ private void setTransients(String name, int mask) { if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) { throw new IllegalArgumentException("invalid action string"); } action_mask = mask; filter = parseFilter(name); }
/** * Determines if a {@code CapabilityPermission} object "implies" the * specified permission. * * @param p The target permission to check. * @return {@code true} if the specified permission is implied by this * object; {@code false} otherwise. */ @Override public boolean implies(Permission p) { if (!(p instanceof CapabilityPermission)) { return false; } CapabilityPermission requested = (CapabilityPermission) p; if (bundle != null) { return false; } // if requested permission has a filter, then it is an invalid argument if (requested.filter != null) { return false; } return implies0(requested, ACTION_NONE); }
/** * Package private constructor used by CapabilityPermissionCollection. * * @param name class name * @param mask action mask */ CapabilityPermission(String name, int mask) { super(name); setTransients(name, mask); this.attributes = null; this.bundle = null; }
/** * Determines the equality of two CapabilityPermission objects. * * Checks that specified object has the same name and action as this * {@code CapabilityPermission}. * * @param obj The object to test for equality. * @return true if obj is a {@code CapabilityPermission}, and has the same * name and actions as this {@code CapabilityPermission} object; * {@code false} otherwise. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CapabilityPermission)) { return false; } CapabilityPermission cp = (CapabilityPermission) obj; return (action_mask == cp.action_mask) && getName().equals(cp.getName()) && ((attributes == cp.attributes) || ((attributes != null) && (attributes.equals(cp.attributes)))) && ((bundle == cp.bundle) || ((bundle != null) && bundle.equals(cp.bundle))); }
this(name, parseActions(actions)); if ((this.filter != null) && ((action_mask & ACTION_ALL) != ACTION_REQUIRE)) { throw new IllegalArgumentException("invalid action string for filter expression");
/** * readObject is called to restore the state of this permission from a * stream. */ private synchronized void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the action, then initialize the rest s.defaultReadObject(); setTransients(getName(), parseActions(actions)); }
@Override boolean hasRequirePermission(BundleRequirementImpl br) { final BundleImpl b = br.getBundleGeneration().bundle; if (b.id != 0) { final PermissionCollection pc = ph.getPermissionCollection(new Long(b.id)); return pc.implies(new CapabilityPermission(br.getNamespace(), CapabilityPermission.REQUIRE)); } return true; }
/** * Called by constructors and when deserialized. * * @param mask action mask */ private void setTransients(String name, int mask) { if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) { throw new IllegalArgumentException("invalid action string"); } action_mask = mask; filter = parseFilter(name); }
/** * Determines if a {@code CapabilityPermission} object "implies" the * specified permission. * * @param p The target permission to check. * @return {@code true} if the specified permission is implied by this * object; {@code false} otherwise. */ @Override public boolean implies(Permission p) { if (!(p instanceof CapabilityPermission)) { return false; } CapabilityPermission requested = (CapabilityPermission) p; if (bundle != null) { return false; } // if requested permission has a filter, then it is an invalid argument if (requested.filter != null) { return false; } return implies0(requested, ACTION_NONE); }
/** * Package private constructor used by CapabilityPermissionCollection. * * @param name class name * @param mask action mask */ CapabilityPermission(String name, int mask) { super(name); setTransients(name, mask); this.attributes = null; this.bundle = null; }
props.put("capability.namespace", getName()); if (bundle == null) { return properties = props;
/** * readObject is called to restore the state of this permission from a * stream. */ private synchronized void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the action, then initialize the rest s.defaultReadObject(); setTransients(getName(), parseActions(actions)); }