final String name = ap.getName(); synchronized (this) { Map<String, AdaptPermission> pc = permissions; final int newMask = ap.action_mask; if (oldMask != newMask) { pc.put(name, new AdaptPermission(existing.filter, oldMask | newMask));
/** * Returns the hash code value for this object. * * @return A hash code value for this object. */ @Override public int hashCode() { int h = 31 * 17 + getName().hashCode(); h = 31 * h + getActions().hashCode(); if (bundle != null) { h = 31 * h + bundle.hashCode(); } return h; }
/** * Internal implies method. Used by the implies and the permission * collection implies methods. * * @param requested The requested AdaptPermission which has already be * validated as a proper argument. The requested AdaptPermission 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(AdaptPermission 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 */ Filter f = filter; if (f == null) { // it's "*" return true; } 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(parseFilter(getName()), parseActions(actions)); }
this(parseFilter(filter), parseActions(actions));
/** * Determines if the specified permission is implied by this object. * * <p> * This method checks that the filter of the target is implied by the adapt * class name of this object. The list of {@code AdaptPermission} actions * must either match or allow for the list of the target object to imply the * target {@code AdaptPermission} action. * <p> * * @param p The requested permission. * @return {@code true} if the specified permission is implied by this * object; {@code false} otherwise. */ @Override public boolean implies(Permission p) { if (!(p instanceof AdaptPermission)) { return false; } AdaptPermission requested = (AdaptPermission) 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); }
private void loadProvider(final Bundle bundle) { if (bundle.getState() == Bundle.UNINSTALLED) { return; } try { checkPermission(new AdminPermission(bundle, AdminPermission.RESOURCE)); checkPermission(new AdaptPermission(BundleWiring.class.getName(), bundle, AdaptPermission.ADAPT)); final BundleContext bundleContext = bundle.getBundleContext(); if (bundleContext == null) { LOGGER.debug("Bundle {} has no context (state={}), skipping loading provider", bundle.getSymbolicName(), toStateString(bundle.getState())); } else { loadProvider(bundleContext, bundle.adapt(BundleWiring.class)); } } catch (final SecurityException e) { LOGGER.debug("Cannot access bundle [{}] contents. Ignoring.", bundle.getSymbolicName(), e); } catch (final Exception e) { LOGGER.warn("Problem checking bundle {} for Log4j 2 provider.", bundle.getSymbolicName(), e); } }
/** * Creates a new requested {@code AdaptPermission} object to be used by the * code that must perform {@code checkPermission}. {@code AdaptPermission} * objects created with this constructor cannot be added to an * {@code AdaptPermission} permission collection. * * @param adaptClass The name of the type to which an object can be adapted. * @param adaptableBundle The bundle associated with the object being * adapted. * @param actions {@code adapt}. */ public AdaptPermission(String adaptClass, Bundle adaptableBundle, String actions) { super(adaptClass); setTransients(null, parseActions(actions)); this.bundle = adaptableBundle; if (adaptClass == null) { throw new NullPointerException("adaptClass must not be null"); } if (adaptableBundle == null) { throw new NullPointerException("adaptableBundle must not be null"); } }
/** * WriteObject is called to save the state of this permission 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 { 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(); }
/** * Package private constructor used by AdaptPermissionCollection. * * @param filter name filter * @param mask action mask */ AdaptPermission(Filter filter, int mask) { super((filter == null) ? "*" : filter.toString()); setTransients(filter, mask); this.bundle = null; }
/** * Determines the equality of two {@code AdaptPermission} objects. * * This method checks that specified permission has the same name and * {@code AdaptPermission} actions as this {@code AdaptPermission} object. * * @param obj The object to test for equality with this * {@code AdaptPermission} object. * @return {@code true} if {@code obj} is a {@code AdaptPermission}, and has * the same name and actions as this {@code AdaptPermission} object; * {@code false} otherwise. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof AdaptPermission)) { return false; } AdaptPermission cp = (AdaptPermission) obj; return (action_mask == cp.action_mask) && getName().equals(cp.getName()) && ((bundle == cp.bundle) || ((bundle != null) && bundle.equals(cp.bundle))); }
/** * 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(parseFilter(getName()), parseActions(actions)); }
if (perm.implies0(requested, effective)) { return true;
/** * Check for permission to get a service. */ private <A> void checkAdaptPermission(Class<A> adapterType) { SecurityManager sm = System.getSecurityManager(); if (sm == null) { return; } sm.checkPermission(new AdaptPermission(adapterType.getName(), this, AdaptPermission.ADAPT)); }
this(parseFilter(filter), parseActions(actions));
/** * WriteObject is called to save the state of this permission 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 { 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(); }
/** * Package private constructor used by AdaptPermissionCollection. * * @param filter name filter * @param mask action mask */ AdaptPermission(Filter filter, int mask) { super((filter == null) ? "*" : filter.toString()); setTransients(filter, mask); this.bundle = null; }
map.put("adaptClass", getName()); if (bundle != null) { AccessController.doPrivileged(new PrivilegedAction<Void>() {
/** * 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(parseFilter(getName()), parseActions(actions)); }
/** * Returns the hash code value for this object. * * @return A hash code value for this object. */ public int hashCode() { int h = 31 * 17 + getName().hashCode(); h = 31 * h + getActions().hashCode(); if (bundle != null) { h = 31 * h + bundle.hashCode(); } return h; }