retrieve a subject based on a token. Valid means we return a participant
       invalid means we return None
13218
def validate_token(self, token):
    '''
    '''
    from expfactory.database.models import Participant
    p = Participant.query.filter(Participant.token == token).first()
    if p is not None:
        if p.token.endswith(('finished','revoked')):
            p = None
        else:
            p = p.id
    return p
1358924
def get_authenticated_subjects(cert_pem):
    
    if isinstance(cert_pem, str):
        cert_pem = cert_pem.encode('utf-8')
    return d1_common.cert.subjects.extract_subjects(cert_pem)
928359
def get_participants(self, obj):
        
        # we set the many to many serialization to False, because we only want it with retrieve requests
        if self.callback is None:
            return [participant.id for participant in obj.participants.all()]
        else:
            # we do not want user information
            return self.callback(obj)
455060
def _get_subject_uri(self, guid=None):
        
        uri = self.uri + '/v1/subject'
        if guid:
            uri += '/' + urllib.quote_plus(guid)
        return uri
592014
def subject(self):
        
        # Fetch subject from first message.
        subject = self.message.get('Subject', '')
        subject, _ = re.subn(r'\s+', ' ', subject)
        return subject
113097
def lookup(self, topic):
        """"""
        nsq.assert_valid_topic_name(topic)
        return self._request('GET', '/lookup', fields={'topic': topic})
759443
def nodes(self, type=None, failed=False, participant_id=None):
        
        if type is None:
            type = Node

        if not issubclass(type, Node):
            raise TypeError("{} is not a valid node type.".format(type))

        if failed not in ["all", False, True]:
            raise ValueError("{} is not a valid node failed".format(failed))

        if participant_id is not None:
            if failed == "all":
                return type.query.filter_by(
                    network_id=self.id, participant_id=participant_id
                ).all()
            else:
                return type.query.filter_by(
                    network_id=self.id, participant_id=participant_id, failed=failed
                ).all()
        else:
            if failed == "all":
                return type.query.filter_by(network_id=self.id).all()
            else:
                return type.query.filter_by(failed=failed, network_id=self.id).all()
1049145
def subject(self):
        """"""
        return Subject([(s.oid, s.value) for s in self.x509.subject])
54987
def _identify(self, subject):
        
        ourPrivateCert = self.service.certificateStorage.getPrivateCertificate(
            str(subject)
        )
        ourCA = Certificate(ourPrivateCert.original)
        return dict(certificate=ourCA)
908950
def _get_subject(self):
        
        subject_context = SubjectContext(yosai=self, security_manager=self.security_manager)
        subject = self.security_manager.create_subject(subject_context=subject_context)
        global_subject_context.stack.append(subject)
        return subject
998092
def subject
      return nil unless subject_decorator
      if subject_decorator.respond_to?(:call)
        subject_decorator.call()
      elsif respond_to?(subject_decorator)
        self.send(subject_decorator)
      else
        nil
      end
    end
475587
def get_subject(self):
        
        assert self.assertion.subject
        subject = self.assertion.subject
        subjconf = []

        if not self.verify_attesting_entity(subject.subject_confirmation):
            raise VerificationError("No valid attesting address")

        for subject_confirmation in subject.subject_confirmation:
            _data = subject_confirmation.subject_confirmation_data

            if subject_confirmation.method == SCM_BEARER:
                if not self._bearer_confirmed(_data):
                    continue
            elif subject_confirmation.method == SCM_HOLDER_OF_KEY:
                if not self._holder_of_key_confirmed(_data):
                    continue
            elif subject_confirmation.method == SCM_SENDER_VOUCHES:
                pass
            else:
                raise ValueError("Unknown subject confirmation method: %s" % (
                    subject_confirmation.method,))

            _recip = _data.recipient
            if not _recip or not self.verify_recipient(_recip):
                raise VerificationError("No valid recipient")

            subjconf.append(subject_confirmation)

        if not subjconf:
            raise VerificationError("No valid subject confirmation")

        subject.subject_confirmation = subjconf

        # The subject may contain a name_id

        if subject.name_id:
            self.name_id = subject.name_id
        elif subject.encrypted_id:
            # decrypt encrypted ID
            _name_id_str = self.sec.decrypt(
                subject.encrypted_id.encrypted_data.to_string())
            _name_id = saml.name_id_from_string(_name_id_str)
            self.name_id = _name_id

        logger.info("Subject NameID: %s", self.name_id)
        return self.name_id
57163
def valid(cls, token, **kwargs):
        
        try:
            token = yield cls.get(token)
        except couch.NotFound:
            raise Return(False)

        raise Return(token.ttl >= datetime.utcnow())
584544
def get_root_subject(self):
        ''

        manifest = URIRef(self.manifest)

        if list(self.rdf.triples((manifest, None, None))):
            return manifest
        else:
            return self.rdf.subjects(None, self.manifest).next()
804103
def get_hypothesis( token )
      return winner if winner.present?
      return nil unless subject = Subject.find_by_token( token )

      if join = HypothesisSubject.find_by_experiment_id_and_subject_id( id, subject.id )
        hypotheses.each { |h| return h if h.id == join.hypothesis_id }
        return nil
      end

      hypothesis = choose_hypothesis
      HypothesisSubject.create( :hypothesis_id => hypothesis.id, :subject_id => subject.id, :experiment_id => id )

      return hypothesis
    end
1235935
private static SubjectAware findInternal(boolean recursive,
    Annotation... annotations)
  {
    SubjectAware subjectAware = null;

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().isAssignableFrom(SubjectAware.class))
      {
        subjectAware = (SubjectAware) annotation;

        break;
      }
    }

    if ((subjectAware == null) && recursive)
    {
      for (Annotation annotation : annotations)
      {
        subjectAware = findInternal(false,
          annotation.annotationType().getAnnotations());
      }
    }

    return subjectAware;
  }
433929
def token_getter(provider, token=None):
        
        session_key = provider + '_token'
        if token is None:
            token = session.get(session_key)
        return token