/** * Package private constructor used by EndpointPermissionCollection. * * @param name class name * @param mask action mask */ EndpointPermission(String name, int mask) { super(name); setTransients(parseFilter(name), mask); this.endpoint = null; this.properties = null; }
/** * Returns a new {@code PermissionCollection} object for storing * {@code EndpointPermission} objects. * * @return A new {@code PermissionCollection} object suitable for storing * {@code EndpointPermission} objects. */ public PermissionCollection newPermissionCollection() { return new EndpointPermissionCollection(); }
/** * Return the list of intents implemented by this endpoint. * * The intents are based on the service.intents on an imported service, * except for any intents that are additionally provided by the importing * distribution provider. All qualified intents must have been expanded. * * This value of the intents is stored in the * {@link RemoteConstants#SERVICE_INTENTS} service property. * * @return An unmodifiable list of expanded intents that are provided by * this endpoint. */ public List<String> getIntents() { return getStringPlusProperty(SERVICE_INTENTS); }
super(createName(endpoint)); setTransients(null, parseActions(actions)); Map<String, Object> props; if ((localFrameworkUUID != null) && localFrameworkUUID.equals(endpoint.getFrameworkUUID())) { props = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); props.putAll(endpoint.getProperties()); props.put(ENDPOINT_FRAMEWORK_UUID, new String[] {endpoint.getFrameworkUUID(), "<<LOCAL>>"}); } else { props = endpoint.getProperties(); this.properties = new EndpointDescription.UnmodifiableDictionary<String, Object>(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(parseFilter(getName()), parseActions(actions)); }
/** * Answers if this Endpoint Description refers to the same service instance * as the given Endpoint Description. * * Two Endpoint Descriptions point to the same service if they have the same * id or their framework UUIDs and remote service ids are equal. * * @param other The Endpoint Description to look at * @return True if this endpoint description points to the same service as * the other */ public boolean isSameService(EndpointDescription other) { if (this.equals(other)) { return true; } if (this.getFrameworkUUID() == null) { return false; } return (this.getServiceId() == other.getServiceId()) && this.getFrameworkUUID().equals(other.getFrameworkUUID()); }
/** * Returns the hash code value for this object. * * @return Hash code value for this object. */ public int hashCode() { int h = 31 * 17 + getName().hashCode(); h = 31 * h + getActions().hashCode(); if (endpoint != null) { h = 31 * h + endpoint.hashCode(); } return h; }
throw new IllegalArgumentException("invalid permission: " + permission); if (isReadOnly()) { throw new SecurityException("attempt to add a Permission to a " + "readonly PermissionCollection"); final String name = ep.getName(); synchronized (this) { final int newMask = ep.action_mask; if (oldMask != newMask) { pc.put(name, new EndpointPermission(name, oldMask | newMask));
/** * Determines the equality of two EndpointPermission objects. * * Checks that specified object has the same name, actions and endpoint as * this {@code EndpointPermission}. * * @param obj The object to test for equality. * @return true If obj is a {@code EndpointPermission}, and has the same * name, actions and endpoint as this {@code EndpointPermission} * object; {@code false} otherwise. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof EndpointPermission)) { return false; } EndpointPermission ep = (EndpointPermission) obj; return (action_mask == ep.action_mask) && getName().equals(ep.getName()) && ((endpoint == ep.endpoint) || ((endpoint != null) && (ep.endpoint != null) && endpoint.equals(ep.endpoint))); }
/** * Returns a hash code value for the object. * * @return An integer which is a hash code value for this object. */ public int hashCode() { return getId().hashCode(); }
/** * Determines if a {@code EndpointPermission} 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. */ public boolean implies(Permission p) { if (!(p instanceof EndpointPermission)) { return false; } EndpointPermission requested = (EndpointPermission) p; if (endpoint != 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); }
/** * Create a new EndpointPermission with the specified filter. * * <p> * The filter will be evaluated against the endpoint properties of a * requested EndpointPermission. * * <p> * There are three possible actions: {@code read}, {@code import} and * {@code export}. The {@code read} action allows the owner of this * permission to see the presence of distributed services. The * {@code import} action allows the owner of this permission to import an * endpoint. The {@code export} action allows the owner of this permission * to export a service. * * @param filterString The filter string or "*" to match all * endpoints. * @param actions The actions {@code read}, {@code import}, or * {@code export}. * @throws IllegalArgumentException If the filter has an invalid syntax or * the actions are not valid. */ public EndpointPermission(String filterString, String actions) { this(filterString, parseActions(actions)); }
/** * 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 (endpoint != 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 EndpointPermission which has already be * validated as a proper argument. The requested EndpointPermission * 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(EndpointPermission requested, int effective) { /* check actions first - much faster */ effective |= action_mask; final int desired = requested.action_mask; if ((effective & desired) != desired) { return false; } /* if we have no filter */ Filter f = filter; if (f == null) { // it's "*" return true; } return f.matchCase(requested.getProperties()); }
try { getPackageVersion(packageName); } catch (IllegalArgumentException e) { IllegalArgumentException iae = new IllegalArgumentException("Improper version for package " + packageName);
/** * Tests the properties of this {@code EndpointDescription} against the * given filter using a case insensitive match. * * @param filter The filter to test. * @return {@code true} If the properties of this * {@code EndpointDescription} match the filter, {@code false} * otherwise. * @throws IllegalArgumentException If {@code filter} contains an invalid * filter string that cannot be parsed. */ public boolean matches(String filter) { Filter f; try { f = FrameworkUtil.createFilter(filter); } catch (InvalidSyntaxException e) { IllegalArgumentException iae = new IllegalArgumentException(e.getMessage()); iae.initCause(e); throw iae; } Dictionary<String, Object> d = new UnmodifiableDictionary<String, Object>(properties); /* * we can use matchCase here since properties already supports case * insensitive key lookup. */ return f.matchCase(d); }
/** * Compares this {@code EndpointDescription} object to another object. * * <p> * An Endpoint Description is considered to be <b>equal to</b> another * Endpoint Description if their ids are equal. * * @param other The {@code EndpointDescription} object to be compared. * @return {@code true} if {@code object} is a {@code EndpointDescription} * and is equal to this object; {@code false} otherwise. */ public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof EndpointDescription)) { return false; } return getId().equals(((EndpointDescription) other).getId()); }
/** * Returns the configuration types. * * A distribution provider exports a service with an endpoint. This endpoint * uses some kind of communications protocol with a set of configuration * parameters. There are many different types but each endpoint is * configured by only one configuration type. However, a distribution * provider can be aware of different configuration types and provide * synonyms to increase the change a receiving distribution provider can * create a connection to this endpoint. * * This value of the configuration types is stored in the * {@link RemoteConstants#SERVICE_IMPORTED_CONFIGS} service property. * * @return An unmodifiable list of the configuration types used for the * associated endpoint and optionally synonyms. */ public List<String> getConfigurationTypes() { return getStringPlusProperty(SERVICE_IMPORTED_CONFIGS); }
if (iter.next().implies0(requested, effective)) { return true;
/** * Create a permission name from a EndpointDescription. * * @param endpoint EndpointDescription to use to create permission name. * @return permission name. */ private static String createName(EndpointDescription endpoint) { if (endpoint == null) { throw new IllegalArgumentException("invalid endpoint: null"); } StringBuffer sb = new StringBuffer("(" + ENDPOINT_ID + "="); sb.append(endpoint.getId()); sb.append(")"); return sb.toString(); }