// OpenSession opens a session between an application and a token.
5549
func (c *Ctx) OpenSession(slotID uint, flags uint) (SessionHandle, error) {
	var s C.CK_SESSION_HANDLE
	e := C.OpenSession(c.ctx, C.CK_ULONG(slotID), C.CK_ULONG(flags), C.CK_SESSION_HANDLE_PTR(&s))
	return SessionHandle(s), toError(e)
}
69671
func newSession(config *Config, conn io.ReadWriteCloser, client bool) *Session {
	logger := config.Logger
	if logger == nil {
		logger = log.New(config.LogOutput, "", log.LstdFlags)
	}

	s := &Session{
		config:     config,
		logger:     logger,
		conn:       conn,
		bufRead:    bufio.NewReader(conn),
		pings:      make(map[uint32]chan struct{}),
		streams:    make(map[uint32]*Stream),
		inflight:   make(map[uint32]struct{}),
		synCh:      make(chan struct{}, config.AcceptBacklog),
		acceptCh:   make(chan *Stream, config.AcceptBacklog),
		sendCh:     make(chan sendReady, 64),
		recvDoneCh: make(chan struct{}),
		shutdownCh: make(chan struct{}),
	}
	if client {
		s.nextStreamID = 1
	} else {
		s.nextStreamID = 2
	}
	go s.recv()
	go s.send()
	if config.EnableKeepAlive {
		go s.keepalive()
	}
	return s
}
949713
func (s *SSO) StartSession(w http.ResponseWriter, cs crowd.Session) {
	ck := http.Cookie{
		Name:    s.CookieConfig.Name,
		Domain:  s.CookieConfig.Domain,
		Secure:  s.CookieConfig.Secure,
		Value:   cs.Token,
		Expires: cs.Expires,
	}
	http.SetCookie(w, &ck)
}
927888
func (s *Semaphore) createSession() (string, error) {
	session := s.c.Session()
	se := &SessionEntry{
		Name:     s.opts.SessionName,
		TTL:      s.opts.SessionTTL,
		Behavior: SessionBehaviorDelete,
	}
	id, _, err := session.Create(se, nil)
	if err != nil {
		return "", err
	}
	return id, nil
}
31493
func (s *server) UpdateSession(req UpdateRequest) error {
	if err := req.Check(); err != nil {
		return trace.Wrap(err)
	}

	key := activeKey(req.Namespace, string(req.ID))

	// Try several times, then give up
	for i := 0; i < sessionUpdateAttempts; i++ {
		item, err := s.bk.Get(context.TODO(), key)
		if err != nil {
			return trace.Wrap(err)
		}

		var session Session
		if err := json.Unmarshal(item.Value, &session); err != nil {
			return trace.Wrap(err)
		}

		if req.TerminalParams != nil {
			session.TerminalParams = *req.TerminalParams
		}
		if req.Active != nil {
			session.Active = *req.Active
		}
		if req.Parties != nil {
			session.Parties = *req.Parties
		}
		newValue, err := json.Marshal(session)
		if err != nil {
			return trace.Wrap(err)
		}
		newItem := backend.Item{
			Key:     key,
			Value:   newValue,
			Expires: s.clock.Now().UTC().Add(s.activeSessionTTL),
		}

		_, err = s.bk.CompareAndSwap(context.TODO(), *item, newItem)
		if err != nil {
			if trace.IsCompareFailed(err) || trace.IsConnectionProblem(err) {
				s.clock.Sleep(sessionUpdateRetryPeriod)
				continue
			}
			return trace.Wrap(err)
		} else {
			return nil
		}
	}
	return trace.ConnectionProblem(nil, "failed concurrently update the session")
}
486950
func (sm *Manager) UserSession(ctx context.Context) (*types.UserSession, error) {
	var mgr mo.SessionManager

	pc := property.DefaultCollector(sm.client)
	err := pc.RetrieveOne(ctx, sm.Reference(), []string{"currentSession"}, &mgr)
	if err != nil {
		// It's OK if we can't retrieve properties because we're not authenticated
		if f, ok := err.(types.HasFault); ok {
			switch f.Fault().(type) {
			case *types.NotAuthenticated:
				return nil, nil
			}
		}

		return nil, err
	}

	return mgr.CurrentSession, nil
}
1220600
func NewSession(name, addr, keyfile string) Session {
	return &samSession{
		name:       name,
		addr:       addr,
		minversion: "3.0",
		maxversion: "3.0",
		keys:       NewKeyfile(keyfile),
	}
}
144178
func (engine *Engine) NewSession() *Session {
	session := &Session{engine: engine}
	session.Init()
	return session
}
440591
func (c *cmd) createSession() (string, error) {
	var id string
	var err error
	if c.conf.foreignDC {
		id, err = c.createSessionForeign()
	} else {
		id, err = c.createSessionLocal()
	}
	if err == nil {
		c.stopCh = make(chan struct{})
		go c.renewSession(id, c.stopCh)
	}
	return id, err
}
148139
func (a *authHandler) loadSession(r *http.Request) error {
	value := r.Header[a.headerKey]
	var id string

	if len(value) > 0 {
		id = value[0]
	} else {
		id = r.URL.Query().Get("session")
	}

	if id == "" {
		return fmt.Errorf("Header %s and session was empty", a.headerKey)
	}

	ses, err := a.backend.Read(id)

	if err != nil {
		return err
	}

	context.Set(r, a.contextKey, ses)
	return nil
}
626311
func (conn *Connection) CreateSession(username string,
	password string) (*CookieAuth, error) {
	sessUrl, err := buildUrl("_session")
	if err != nil {
		return &CookieAuth{}, err
	}
	var headers = make(map[string]string)
	body := "name=" + username + "&password=" + password
	headers["Content-Type"] = "application/x-www-form-urlencoded"
	resp, err := conn.request("POST", sessUrl,
		strings.NewReader(body), headers, nil)
	if err != nil {
		return &CookieAuth{}, err
	}
	defer resp.Body.Close()
	authToken := func() string {
		for _, cookie := range resp.Cookies() {
			if cookie.Name == "AuthSession" {
				return cookie.Value
			}
		}
		return ""
	}()
	return &CookieAuth{AuthToken: authToken}, nil
}
986281
func (c *dbinitCmd) mongoSession() (*mgo.Session, error) {
	if c.dbType != "mongo" {
		return nil, nil
	}
	url := ""
	if c.user == "" || c.password == "" {
		url = c.host
	} else {
		url = c.user + ":" + c.password + "@" + c.host + "/" + c.dbName
	}
	return mgo.Dial(url)
}
225438
func (s *AWSSessionCredentials) SetSessionToken(v string) *AWSSessionCredentials {
	s.SessionToken = &v
	return s
}
1295119
func (c *Client) UpdateSession(req session.UpdateRequest) error {
	if err := req.Check(); err != nil {
		return trace.Wrap(err)
	}
	_, err := c.PutJSON(c.Endpoint("namespaces", req.Namespace, "sessions", string(req.ID)), updateSessionReq{Update: req})
	return trace.Wrap(err)
}
448493
func (c *Client) NewSession() (*Session, error) {
	ch, in, err := c.OpenChannel("session", nil)
	if err != nil {
		return nil, err
	}
	return newSession(ch, in)
}
1177966
func (s *Service) PutSession(ctx context.Context, sn *influxdb.Session) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		if err := s.putSession(ctx, tx, sn); err != nil {
			return err
		}
		return nil
	})
}
733187
func (s *AwsCredentials) SetSessionToken(v string) *AwsCredentials {
	s.SessionToken = &v
	return s
}