Checks the authority of a consumer to consume from a destination
439444
@Deprecated
    private void checkBrowseAuthority(DestinationHandler destination,
                                      String destinationName,
                                      SecurityContext secContext,
                                      boolean system)

                    throws SINotAuthorizedException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(
                        tc,
                        "checkBrowseAuthority",
                        new Object[] { destination,
                                      destinationName,
                                      secContext,
                                      Boolean.valueOf(system) });

        // Check authority to browse a destination
        if (!destination.isTemporary() && !system)
        {
            boolean allowed = true;
            boolean failingOpisIdentityAdopter = false;
            // Perform the alternate user check first. If an alternateUser was set then we 
            // need to determine whether the connected subject has the authority to perform
            // alternate user checks.

            if (secContext.isAlternateUserBased())
            {
                if (!destination.checkDestinationAccess(secContext,
                                                        OperationType.IDENTITY_ADOPTER))
                {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        SibTr.debug(tc, "checkBrowseAuthority", "not authorized to perform alternate user checks on this destination");

                    allowed = false;
                    failingOpisIdentityAdopter = true;
                }
            }

            if (allowed) // ok so far
            {
                // Check if its the default exc dest
                if (destinationName.startsWith(SIMPConstants.SYSTEM_DEFAULT_EXCEPTION_DESTINATION_PREFIX))
                {
                    //If its a def exc dest see if we have access to the prefix.
                    if (!_messageProcessor.
                                    getAccessChecker().
                                    checkDestinationAccess(secContext,
                                                           null, // home bus  
                                                           SIMPConstants.SYSTEM_DEFAULT_EXCEPTION_DESTINATION_PREFIX,
                                                           OperationType.RECEIVE))
                    {
                        allowed = false;
                    }
                }
                else
                {
                    if (!destination.checkDestinationAccess(secContext,
                                                            OperationType.BROWSE))
                    {
                        allowed = false;
                    }
                }
            }

            if (!allowed)
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                    SibTr.exit(tc, "checkBrowseAuthority", "not authorized to browse this destination");

                // Get the username
                String userName = secContext.getUserName(failingOpisIdentityAdopter);
                OperationType operationType =
                                failingOpisIdentityAdopter ? OperationType.IDENTITY_ADOPTER :
                                                OperationType.BROWSE;

                // Build the message for the Exception and the Notification
                String nlsMessage =
                                nls.getFormattedMessage("USER_NOT_AUTH_BROWSE_ERROR_CWSIP0304",
                                                        new Object[] { destination.getName(),
                                                                      userName },
                                                        null);

                // Fire a Notification if Eventing is enabled
                _accessChecker.
                                fireDestinationAccessNotAuthorizedEvent(destination.getName(),
                                                                        userName,
                                                                        operationType,
                                                                        nlsMessage);

                // Thrown if user denied access to destination
                throw new SINotAuthorizedException(nlsMessage);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "checkBrowseAuthority");
    }
922366
def ingest_user(self):
        ''''''
        # if there is an audit trail and it has records and the first
        # action is ingest, return the user
        if self.audit_trail and self.audit_trail.records \
           and self.audit_trail.records[0].action == 'ingest':
            return self.audit_trail.records[0].user
689044
def verify_ticket(self, ticket):
        """"""
        (response, charset) = self.get_verification_response(ticket)
        return self.verify_response(response, charset)
468703
def can_approve(self, user, **data):
        
        service_id = data.get('service_id', self.service_id)

        try:
            service = yield Service.get(service_id)

            is_repo_admin = user.is_org_admin(service.organisation_id)

            is_reseller_preverifying = user.is_reseller() and data.get('pre_verified', False)

            raise Return(is_repo_admin or is_reseller_preverifying)
        except couch.NotFound:
            pass

        raise Return(False)
775888
public static <T, C extends Collection<T>> void
    ifNotNullOrEmptyConsume(C collection, Consumer<C> consumer) {
        JMOptional.getOptional(collection).ifPresent(consumer);
    }
1236792
def consume(self, queue, consumer, consumer_tag='', no_local=False,
                no_ack=True, exclusive=False, nowait=True, ticket=None,
                cb=None):
        '''
        
        '''
        nowait = nowait and self.allow_nowait() and not cb

        if nowait and consumer_tag == '':
            consumer_tag = self._generate_consumer_tag()

        args = Writer()
        args.write_short(ticket or self.default_ticket).\
            write_shortstr(queue).\
            write_shortstr(consumer_tag).\
            write_bits(no_local, no_ack, exclusive, nowait).\
            write_table({})  # unused according to spec
        self.send_frame(MethodFrame(self.channel_id, 60, 20, args))

        if not nowait:
            self._pending_consumers.append((consumer, cb))
            self.channel.add_synchronous_cb(self._recv_consume_ok)
        else:
            self._consumer_cb[consumer_tag] = consumer
273771
public static <T, U> void consumeIfTrue(boolean bool, T target1, U target2,
            BiConsumer<T, U> biConsumer) {
        if (bool)
            biConsumer.accept(target1, target2);
    }
175301
private boolean checkDestinationAccess(
    DestinationHandler destination,
    String discriminator,
    String userId)
    throws SIDiscriminatorSyntaxException {
    if (tc.isEntryEnabled())
      SibTr.entry(
        tc,
        "checkDestinationAccess",
        new Object[] { destination, discriminator, userId });

    boolean allowed = true;

    // Map a null userid to an empty string
    if (userId == null) {
      userId = ""; // Empty string means those users that have not
      // been authenticated, but who are still, of course,
      // members of EVERYONE. 
    }

    // We use the userid flavour of security context as we need
    // to drive the userid flavour of the sib.security checkDestinationAccess
    // which is attuned for access checks for messages from foreign buses.
    SecurityContext secContext = new SecurityContext(userId, discriminator);

    // Check authority to access the destination    
    if (!destination
      .checkDestinationAccess(secContext, OperationType.RECEIVE)) 
    {
      if (tc.isDebugEnabled())
        SibTr.debug(
          tc,
          "checkDestinationAccess",
          "not authorized to produce to this destination");

      // Build the message for the Exception and the Notification
      String nlsMessage = 
      nls_cwsik.getFormattedMessage("DELIVERY_ERROR_SIRC_18", // USER_NOT_AUTH_SEND_ERROR_CWSIP0306
                                    new Object[] { destination.getName(), 
                                                   userId },
                                    null); 
                                    
      // Fire a Notification if Eventing is enabled
      iProxyHandler.
        getMessageProcessor().
        getAccessChecker().
        fireDestinationAccessNotAuthorizedEvent(destination.getName(),
                                        userId,
                                        OperationType.RECEIVE,
                                        nlsMessage);

      // sib.security will audit this
      allowed = false;
    }

    // Check authority to produce to discriminator
    if (allowed) {
      // If the discriminator is non-wildcarded, we can check authority to consume on
      // the discriminator.
      if (discriminator != null
        && !iProxyHandler
          .getMessageProcessor()
          .getMessageProcessorMatching()
          .isWildCarded(discriminator)) 
      {
        if (!destination
          .checkDiscriminatorAccess(secContext, OperationType.RECEIVE)) 
        {
          if (tc.isDebugEnabled())
            SibTr.debug(
              tc,
              "checkDestinationAccess",
              "not authorized to produce to this discriminator");

          // Write an audit record if access is denied
          SibTr
            .audit(
              tc,
              nls_cwsik
                .getFormattedMessage("DELIVERY_ERROR_SIRC_20",
          // USER_NOT_AUTH_SEND_ERROR_CWSIP0308
          new Object[] {
            destination.getName(),
            discriminator,
            userId },
            null));

          allowed = false;
        }
      }
    }

    if (tc.isEntryEnabled())
      SibTr.exit(tc, "checkDestinationAccess", new Boolean(allowed));
    return allowed;
  }
808242
public void setConsumerDispatcherStateFilter(ConsumerDispatcherState consumerDispatcherState)
  {
    if (tc.isEntryEnabled())
      SibTr.entry(tc, "setConsumerDispatcherStateFilter", consumerDispatcherState);

    this._consumerDispatcherState = consumerDispatcherState;
    this._subscriptionId = null;
    this._destination = null;
    
    if (tc.isEntryEnabled())
      SibTr.exit(tc, "setConsumerDispatcherStateFilter");
  }
869723
@Override
    public ConsumerDispatcher getDurableSubscriptionConsumerDispatcher(ConsumerDispatcherState subState)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "getDurableSubscriptionConsumerDispatcher", subState);

        ConsumerDispatcher consumerDispatcher = _pubSubRealization.
                        getDurableSubscriptionConsumerDispatcher(subState);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(
                       tc,
                       "getDurableSubscriptionConsumerDispatcher",
                       consumerDispatcher);

        return consumerDispatcher;
    }
1042349
public void notifyReceiveAllowed(DestinationHandler destinationHandler)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "notifyReceiveAllowed", new Object[] {destinationHandler});
      
    if(isPubSub())
    {
      // Notify consumers on this localization 
      SubscriptionTypeFilter filter = new SubscriptionTypeFilter();  
      filter.LOCAL = Boolean.TRUE;  
      SIMPIterator itr = getSubscriptionIndex().iterator(filter);  
      while(itr.hasNext())  
      {  
        ControllableSubscription subscription = (ControllableSubscription)itr.next(); 
        ConsumerDispatcher cd = (ConsumerDispatcher)subscription.getOutputHandler();
        if(cd != null) 
          cd.notifyReceiveAllowed(destinationHandler); 
      } 
      itr.finished(); 
    }
    else
    {
      //tell the local consumer dispatcher that this destinations receiveAllowed has changed
      ConsumerDispatcher cm = (ConsumerDispatcher)getLocalPtoPConsumerManager();
      if (cm != null)
      {
        cm.notifyReceiveAllowed(destinationHandler);
      }
    }

    //tell the any RME remote consumer dispatchers that this destinations receiveAllowed has changed
    notifyReceiveAllowedRCD(destinationHandler);
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "notifyReceiveAllowed");
  }
693652
public boolean isConsumerSetSuspended()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(this, tc, "isConsumerSetSuspended");
    
    boolean suspended = false;
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
      SibTr.debug(tc, "maxActiveMessagePrepareReadLock.lock(): " + maxActiveMessagePrepareLock);
    
    // Take the prepare read lock to prevent the state changing under us
    maxActiveMessagePrepareReadLock.lock();
    
    // Lock down the suspend state
    synchronized(maxActiveMessageLock)
    {
      suspended = consumerSetSuspended;
    }
    
    // Release the prepare lock
    maxActiveMessagePrepareReadLock.unlock();
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
      SibTr.debug(tc, "maxActiveMessagePrepareReadLock.unlock(): " + maxActiveMessagePrepareLock);
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(this, tc, "isConsumerSetSuspended", Boolean.valueOf(suspended));  
    
    return suspended;
  }
327638
public void stoppableConsumerSessionStopped () {
     if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "stoppableConsumerSessionStopped");

     try {
       stopInternal(false); // No need to notify our peer as the stop came from our peer
     } catch (Exception e) {
       FFDCFilter.processException(e, CLASS_NAME + ".processAsyncSessionStoppedCallback", CommsConstants.CONSUMERSESSIONPROXY_SESSION_STOPPED_03, this);
     }

     final AsynchConsumerCallback asynchConsumerCallback = proxyQueue.getAsynchConsumerCallback();
     if (asynchConsumerCallback instanceof StoppableAsynchConsumerCallback) {
       final StoppableAsynchConsumerCallback stoppableAsynchConsumerCallback = (StoppableAsynchConsumerCallback)asynchConsumerCallback;
       // Protect ourselves from the application as far as possible then call the application
       try {
         if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "** Calling application StoppableAsynchConsumerCallback");
         stoppableAsynchConsumerCallback.consumerSessionStopped();
       } catch (Throwable e) {
         FFDCFilter.processException(e, CLASS_NAME + ".stoppableConsumerSessionStopped", CommsConstants.CONSUMERSESSIONPROXY_SESSION_STOPPED_01, this);
       }
     } else {
       if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "asynchConsumerCallback not an instance of StoppableAsynchConsumerCallback is an instance of "+ asynchConsumerCallback.getClass().getName());
       SIErrorException e = new SIErrorException(nls.getFormattedMessage("WRONG_CLASS_CWSICO8022", new Object[] {asynchConsumerCallback.getClass().getName()}, null));
       FFDCFilter.processException(e, CLASS_NAME + ".processAsyncSessionStoppedCallback", CommsConstants.CONSUMERSESSIONPROXY_SESSION_STOPPED_02, this);
       SibTr.error(tc, "WRONG_CLASS_CWSICO8022", e);
       throw e;
     }

     if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "stoppableConsumerSessionStopped");
   }
220643
private void checkReceiveState()
                    throws SIIncorrectCallException, SISessionUnavailableException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "checkReceiveState");

        // Only valid if the consumer session is still open
        checkNotClosed();

        //if there is an AsynchConsumerCallback registered, throw an exception
        if (_asynchConsumerRegistered)
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "checkReceiveState", "asynchConsumerRegistered == true ");

            throw new SIIncorrectCallException(
                            nls.getFormattedMessage(
                                                    "RECEIVE_USAGE_ERROR_CWSIP0171",
                                                    new Object[] { _consumerDispatcher.getDestination().getName(),
                                                                  _messageProcessor.getMessagingEngineName() },
                                                    null));
        }
        // If we already have the waiting bit set it implies another
        // thread is sat waiting in a receive for this consumer (we release
        // the consumer lock while waiting so this is possible).
        else if (_waiting)
        {
            SIIncorrectCallException e =
                            new SIIncorrectCallException(
                                            nls.getFormattedMessage(
                                                                    "RECEIVE_USAGE_ERROR_CWSIP0178",
                                                                    new Object[] { _consumerDispatcher.getDestination().getName(),
                                                                                  _messageProcessor.getMessagingEngineName() },
                                                                    null));

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "checkReceiveState", "receive already in progress");

            throw e;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "checkReceiveState");
    }
1336708
def consumer(site, uri):
    """"""
    config = load_site_config(site)
    model = _get_model('consume', config, uri)
    consumestore = get_consumestore(
        model=model,
        method=_config.get('storage', 'file'),
        bucket=_config.get('s3_data_bucket', None)
    )
    consumestore.save_media()
    consumestore.save_data()
126909
def isAvailable(self, requester, access):
        
        debuglog("%s isAvailable(%s, %s): self.owners=%r"
                 % (self, requester, access, self.owners))
        num_excl, num_counting = self._claimed_excl, self._claimed_counting

        # Find all waiters ahead of the requester in the wait queue
        for idx, waiter in enumerate(self.waiting):
            if waiter[0] is requester:
                w_index = idx
                break
        else:
            w_index = len(self.waiting)
        ahead = self.waiting[:w_index]

        if access.mode == 'counting':
            # Wants counting access
            return num_excl == 0 and num_counting + len(ahead) < self.maxCount \
                and all([w[1].mode == 'counting' for w in ahead])
        # else Wants exclusive access
        return num_excl == 0 and num_counting == 0 and not ahead
1250108
def consume(self, no_ack=None):
        """"""
        no_ack = no_ack or self.no_ack
        self.backend.declare_consumer(queue=self.queue, no_ack=no_ack,
                                      callback=self._receive_callback,
                                      consumer_tag=self.consumer_tag,
                                      nowait=True)
        self.channel_open = True