/** * Returns a new {@code PermissionCollection} object suitable for storing * {@code CoordinationPermission} objects. * * @return A new {@code PermissionCollection} object. */ public PermissionCollection newPermissionCollection() { return new CoordinationPermissionCollection(); }
/** * 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)); }
/** * Determines if the specified permission is implied by this object. * * <p> * This method checks that the filter of the target is implied by the * coordination name of this object. The list of * {@code CoordinationPermission} actions must either match or allow for the * list of the target object to imply the target * {@code CoordinationPermission} action. * <p> * * @param p The requested permission. * @return {@code true} if the specified permission is implied by this * object; {@code false} otherwise. */ public boolean implies(Permission p) { if (!(p instanceof CoordinationPermission)) { return false; } CoordinationPermission requested = (CoordinationPermission) 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); }
throw new IllegalArgumentException("invalid permission: " + permission); if (isReadOnly()) { throw new SecurityException("attempt to add a Permission to a " + "readonly PermissionCollection"); final String name = cp.getName(); synchronized (this) { Map<String, CoordinationPermission> pc = permissions; final int newMask = cp.action_mask; if (oldMask != newMask) { pc.put(name, new CoordinationPermission(existing.filter, oldMask | newMask));
/** * Create a new Coordination Exception with a cause. * * @param message The detail message for this exception. * @param coordination The Coordination associated with this exception. * @param cause The cause associated with this exception. * @param type The type of this exception. * @throws IllegalArgumentException If the specified type is {@link #FAILED} * and the specified cause is {@code null}. */ public CoordinationException(String message, Coordination coordination, int type, Throwable cause) { super(message, cause); this.type = type; if (coordination == null) { this.id = -1L; this.name = "<>"; } else { this.id = coordination.getId(); this.name = coordination.getName(); } if ((type == FAILED) && (cause == null)) { throw new IllegalArgumentException("A cause must be specified for type FAILED"); } }
this(parseFilter(filter), 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; }
/** * Creates a new requested {@code CoordinationPermission} object to be used * by the code that must perform {@code checkPermission}. * {@code CoordinationPermission} objects created with this constructor * cannot be added to an {@code CoordinationPermission} permission * collection. * * @param coordinationName The name of the requested Coordination. * @param coordinationBundle The bundle which * {@link Coordination#getBundle() created} the requested * Coordination. * @param actions {@code admin}, {@code initiate} or {@code participate} * (canonical order). */ public CoordinationPermission(String coordinationName, Bundle coordinationBundle, String actions) { super(coordinationName); setTransients(null, parseActions(actions)); this.bundle = coordinationBundle; if (coordinationName == null) { throw new NullPointerException("coordinationName must not be null"); } if (coordinationBundle == null) { throw new NullPointerException("coordinationBundle must not be null"); } }
public Object run() { map.put("id", new Long(bundle.getBundleId())); map.put("location", bundle.getLocation()); String name = bundle.getSymbolicName(); if (name != null) { map.put("name", name); } SignerProperty signer = new SignerProperty(bundle); if (signer.isBundleSigned()) { map.put("signer", signer); } return null; } });
/** * Determines the equality of two {@code CoordinationPermission} objects. * * This method checks that specified permission has the same name and * {@code CoordinationPermission} actions as this * {@code CoordinationPermission} object. * * @param obj The object to test for equality with this * {@code CoordinationPermission} object. * @return {@code true} if {@code obj} is a {@code CoordinationPermission}, * and has the same name and actions as this * {@code CoordinationPermission} object; {@code false} otherwise. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CoordinationPermission)) { return false; } CoordinationPermission cp = (CoordinationPermission) obj; return (action_mask == cp.action_mask) && getName().equals(cp.getName()) && ((bundle == cp.bundle) || ((bundle != null) && bundle.equals(cp.bundle))); }
/** * Package private constructor used by CoordinationPermissionCollection. * * @param filter name filter * @param mask action mask */ CoordinationPermission(Filter filter, int mask) { super((filter == null) ? "*" : filter.toString()); setTransients(filter, mask); this.bundle = 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(); }
/** * Internal implies method. Used by the implies and the permission * collection implies methods. * * @param requested The requested CoordinationPermission which has already * be validated as a proper argument. The requested * CoordinationPermission 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(CoordinationPermission 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()); }
Coordination getTopCoordination() { Coordination coordination = coordinator.peek(); while (coordination != null && coordination.getEnclosingCoordination() != null) { coordination = coordination.getEnclosingCoordination(); } return coordination; }
/** * Create a new Coordination Exception. * * @param message The detail message for this exception. * @param coordination The Coordination associated with this exception. * @param type The type of this exception. * @throws IllegalArgumentException If the specified type is {@link #FAILED} * . */ public CoordinationException(String message, Coordination coordination, int type) { super(message); this.type = type; if (coordination == null) { this.id = -1L; this.name = "<>"; } else { this.id = coordination.getId(); this.name = coordination.getName(); } if (type == FAILED) { throw new IllegalArgumentException("A cause must be specified for type FAILED"); } }
/** * Returns a new {@code PermissionCollection} object suitable for storing * {@code CoordinationPermission} objects. * * @return A new {@code PermissionCollection} object. */ @Override public PermissionCollection newPermissionCollection() { return new CoordinationPermissionCollection(); }
if (perm.implies0(requested, effective)) { return true;
map.put("coordination.name", getName()); if (bundle != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() {
/** * Returns a new {@code PermissionCollection} object suitable for storing * {@code CoordinationPermission} objects. * * @return A new {@code PermissionCollection} object. */ public PermissionCollection newPermissionCollection() { return new CoordinationPermissionCollection(); }
/** * Returns a new {@code PermissionCollection} object suitable for storing * {@code CoordinationPermission} objects. * * @return A new {@code PermissionCollection} object. */ public PermissionCollection newPermissionCollection() { return new CoordinationPermissionCollection(); }