コード例 #1
0
  /**
   * Checks if the specified {@code permission} is implied by this permission. The method returns
   * true under the following conditions:
   *
   * <UL>
   *   <LI>This permission was created by specifying a filter (see {@link
   *       #ApplicationAdminPermission(String, String)})
   *   <LI>The implied {@code otherPermission} was created for a particular {@link
   *       ApplicationDescriptor} (see {@link #ApplicationAdminPermission(ApplicationDescriptor,
   *       String)})
   *   <LI>The {@code filter} of this permission mathes the {@code ApplicationDescriptor} specified
   *       in the {@code otherPermission}. If the filter in this permission is the {@code
   *       &lt;&lt;SELF&gt;&gt;} pseudo target, then the currentApplicationId set in the {@code
   *       otherPermission} is compared to the application Id of the target {@code
   *       ApplicationDescriptor}.
   *   <LI>The list of permitted actions in this permission contains all actions required in the
   *       {@code otherPermission}
   * </UL>
   *
   * Otherwise the method returns false.
   *
   * @param otherPermission the implied permission
   * @return true if this permission implies the {@code otherPermission}, false otherwise.
   */
  public boolean implies(Permission otherPermission) {
    if (otherPermission == null) return false;

    if (!(otherPermission instanceof ApplicationAdminPermission)) return false;

    ApplicationAdminPermission other = (ApplicationAdminPermission) otherPermission;

    if (!filter.equals("*")) {
      if (other.applicationDescriptor == null) return false;

      if (filter.equals("<<SELF>>")) {
        if (other.applicationID == null) return false; /* it cannot be, this might be a bug */

        if (!other.applicationID.equals(other.applicationDescriptor.getApplicationId()))
          return false;
      } else {
        Hashtable props = new Hashtable();
        props.put("pid", other.applicationDescriptor.getApplicationId());
        props.put("signer", new SignerWrapper(other.applicationDescriptor));

        Filter flt = getFilter();
        if (flt == null) return false;

        if (!flt.match(props)) return false;
      }
    }

    if (!actionsVector.containsAll(other.actionsVector)) return false;

    return true;
  }
コード例 #2
0
ファイル: RemoteOSGiServiceImpl.java プロジェクト: smee/amor
  private NetworkChannelFactory getNetworkChannelFactory(final String protocol)
      throws RemoteOSGiException {
    try {
      final Filter filter =
          RemoteOSGiActivator.getActivator()
              .getContext()
              .createFilter(
                  "(" //$NON-NLS-1$
                      + NetworkChannelFactory.PROTOCOL_PROPERTY
                      + "="
                      + protocol //$NON-NLS-1$
                      + ")"); //$NON-NLS-1$
      final ServiceReference[] refs = networkChannelFactoryTracker.getServiceReferences();

      if (refs != null) {
        for (int i = 0; i < refs.length; i++) {
          if (filter.match(refs[i])) {
            return (NetworkChannelFactory) networkChannelFactoryTracker.getService(refs[i]);
          }
        }
      }
      throw new RemoteOSGiException(
          "No NetworkChannelFactory for " //$NON-NLS-1$
              + protocol
              + " found."); //$NON-NLS-1$

    } catch (final InvalidSyntaxException e) {
      // does not happen
      e.printStackTrace();
      return null;
    }
  }
コード例 #3
0
 public void serviceChanged(ServiceEvent serviceEvent) {
   int serviceEventType = serviceEvent.getType();
   switch (serviceEventType) {
     case ServiceEvent.REGISTERED:
       {
         ServiceReference serviceReference = serviceEvent.getServiceReference();
         Filter filter = (Filter) serviceReference.getProperty(UPnPEventListener.UPNP_FILTER);
         if (filter == null) {
           addNewListener(serviceReference);
         } else if (filter.match(properties)) {
           addNewListener(serviceReference);
         }
       }
       ;
       break;
     case ServiceEvent.MODIFIED:
       {
       }
       ;
       break;
     case ServiceEvent.UNREGISTERING:
       {
         removeListener(serviceEvent.getServiceReference());
       }
       ;
       break;
   }
 }
コード例 #4
0
 private void createNotifier(String deviceId) {
   ServiceReference[] serviceListeners = null;
   ServiceReference serviceReference = null;
   Filter filter = null;
   String eventListenerFilter =
       "(" + Constants.OBJECTCLASS + "=" + UPnPEventListener.class.getName() + ")";
   properties = new Properties();
   properties.put(UPnPDevice.ID, deviceId);
   properties.put(UPnPService.ID, serviceId);
   try {
     serviceListeners = context.getServiceReferences(UPnPEventListener.class.getName(), null);
     if (serviceListeners != null && serviceListeners.length > 0) {
       for (int i = 0; i < serviceListeners.length; i++) {
         serviceReference = serviceListeners[i];
         filter = (Filter) serviceReference.getProperty(UPnPEventListener.UPNP_FILTER);
         if (filter == null) {
           eventListeners.add(serviceReference);
         } else if (filter.match(properties)) {
           addNewListener(serviceReference);
         }
       }
     }
   } catch (Exception e) {
   }
   try {
     String filterString = eventListenerFilter;
     context.addServiceListener(this, filterString);
   } catch (Exception e) {
   }
 }
コード例 #5
0
ファイル: RemoteOSGiServiceImpl.java プロジェクト: smee/amor
 /**
  * @param ref
  * @param event
  */
 private static void match(final ServiceReference ref, final RemoteServiceEvent event) {
   final Filter filter = (Filter) ref.getProperty(RemoteServiceListener.FILTER);
   if (filter == null
       || filter.match(
           ((RemoteServiceReferenceImpl) event.getRemoteReference()).getProperties())) {
     final RemoteServiceListener listener =
         (RemoteServiceListener) remoteServiceListenerTracker.getService(ref);
     if (listener != null) {
       listener.remoteServiceEvent(event);
     }
   }
 }
コード例 #6
0
  public List<ServiceState> getServiceReferencesInternal(
      AbstractBundle bundleState, String clazz, Filter filter, boolean checkAssignable) {
    if (bundleState == null) throw new IllegalArgumentException("Null bundleState");

    List<ServiceName> serviceNames;
    if (clazz != null) {
      serviceNames = serviceNameMap.get(clazz);
      if (serviceNames == null) serviceNames = new ArrayList<ServiceName>();

      // Add potentially registered xservcie
      ServiceName xserviceName = ServiceName.of(ModuleContext.XSERVICE_PREFIX, clazz);
      ServiceController<?> xservice = serviceContainer.getService(xserviceName);
      if (xservice != null) serviceNames.add(xserviceName);
    } else {
      // [MSC-9] Add ability to query the ServiceContainer
      Set<ServiceName> allServiceNames = new HashSet<ServiceName>();
      for (List<ServiceName> auxList : serviceNameMap.values()) allServiceNames.addAll(auxList);

      serviceNames = new ArrayList<ServiceName>(allServiceNames);
    }

    if (serviceNames.isEmpty()) return Collections.emptyList();

    if (filter == null) filter = NoFilter.INSTANCE;

    List<ServiceState> result = new ArrayList<ServiceState>();
    for (ServiceName serviceName : serviceNames) {
      ServiceController<?> controller = serviceContainer.getService(serviceName);
      if (controller == null)
        throw new IllegalStateException("Cannot obtain service for: " + serviceName);

      Object value = controller.getValue();

      // Create the ServiceState on demand for an XService instance
      // [TODO] This should be done eagerly to keep the serviceId constant
      // [TODO] service events for XService lifecycle changes
      // [MSC-17] Canonical ServiceName string representation
      if (value instanceof ServiceState == false
          && serviceName.toString().contains(ModuleContext.XSERVICE_PREFIX)) {
        long serviceId = getNextServiceId();
        Bundle bundle = packageAdmin.getBundle(value.getClass());
        AbstractBundle owner = AbstractBundle.assertBundleState(bundle);
        value =
            new ServiceState(
                owner,
                serviceId,
                new ServiceName[] {serviceName},
                new String[] {clazz},
                value,
                null);
      }

      ServiceState serviceState = (ServiceState) value;
      if (filter.match(serviceState) == false) continue;

      Object rawValue = serviceState.getRawValue();

      checkAssignable &= (clazz != null);
      checkAssignable &= (bundleState.getBundleId() != 0);
      checkAssignable &= !(rawValue instanceof ServiceFactory);
      if (checkAssignable == false || serviceState.isAssignableTo(bundleState, clazz)) {
        result.add(serviceState);
      }
    }

    // Sort the result
    Collections.sort(result, ServiceReferenceComparator.getInstance());
    Collections.reverse(result);

    return Collections.unmodifiableList(result);
  }
 @Override
 protected boolean matches(final ServiceReference<S> capability, final Filter filter) {
   return (filter == null) || filter.match(capability);
 }