// EndSession invalidates the current Crowd session and cookie
506288
func (s *SSO) EndSession(w http.ResponseWriter, r *http.Request) {
	currentCookie, _ := r.Cookie(s.CookieConfig.Name)
	newCookie := &http.Cookie{
		Name:    s.CookieConfig.Name,
		Domain:  s.CookieConfig.Domain,
		Secure:  s.CookieConfig.Secure,
		MaxAge:  -1,
		Expires: time.Unix(1, 0),
		Value:   "LOGGED-OUT",
	}
	s.CrowdApp.InvalidateSession(currentCookie.Value)

	log.Printf("Got cookie to remove: %+v\n", currentCookie)
	log.Printf("Removal cookie: %+v\n", newCookie)
	http.SetCookie(w, newCookie)
}
901543
func (c *cmd) destroySession() error {
	// Stop the session renew if any
	if c.stopCh != nil {
		close(c.stopCh)
		c.stopCh = nil
	}

	// Destroy the session explicitly
	session := c.apiclient.Session()
	_, err := session.Destroy(c.sessionID, nil)
	return err
}
86245
func (c *Client) DeleteSession(namespace, id string) error {
	if namespace == "" {
		return trace.BadParameter(MissingNamespaceError)
	}
	_, err := c.Delete(c.Endpoint("namespaces", namespace, "sessions", id))
	return trace.Wrap(err)
}
962763
func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) (*Session, error) {
	if err := authorizeClient(client, authConfig, endpoint); err != nil {
		return nil, err
	}

	return newSession(client, authConfig, endpoint), nil
}
1149257
func (t *tracker) end(ctx context.Context, err error) {
	status := getResponseStatus(err)

	ctx, _ = tag.New(ctx, tag.Upsert(StatusCode, strconv.Itoa(int(status.Code))))
	stats.Record(ctx, t.profile.LatencyMeasure.M(float64(time.Since(t.startedAt))/float64(time.Millisecond)))

	if t.span != nil {
		t.span.SetStatus(status)
		t.span.End()
	}
}
1202006
func (s *Session) Destroy(ctx context.Context) error {
	sd := s.getSessionDataFromContext(ctx)

	sd.mu.Lock()
	defer sd.mu.Unlock()

	err := s.Store.Delete(sd.token)
	if err != nil {
		return err
	}

	sd.status = Destroyed

	// Reset everything else to defaults.
	sd.token = ""
	sd.Deadline = time.Now().Add(s.Lifetime).UTC()
	for key := range sd.Values {
		delete(sd.Values, key)
	}

	return nil
}
1069691
func (s *SuperAgent) EndBytes(callback ...func(response Response, body []byte, errs []error)) (Response, []byte, []error) {
	var (
		errs []error
		resp Response
		body []byte
	)

	for {
		resp, body, errs = s.getResponseBytes()
		if errs != nil {
			return nil, nil, errs
		}
		if s.isRetryableRequest(resp) {
			resp.Header.Set("Retry-Count", strconv.Itoa(s.Retryable.Attempt))
			break
		}
	}

	respCallback := *resp
	if len(callback) != 0 {
		callback[0](&respCallback, body, s.Errors)
	}
	return resp, body, nil
}
484876
func (r Realm) Close() {
	iter := r.clients.Iter()
	for {
		select {
		case client, ok := <-iter:
			if !ok {
				return
			}

			sess, isSession := client.Val.(Session)
			if !isSession {
				continue
			}

			sess.kill <- ErrSystemShutdown
		}
	}
}
999435
func (c *SessionContext) Close() error {
	closers := c.TransferClosers()
	for _, closer := range closers {
		c.Debugf("Closing %v.", closer)
		closer.Close()
	}
	if c.clt != nil {
		return trace.Wrap(c.clt.Close())
	}
	return nil
}
447848
func (c *Client) DeleteWebSession(user string, sid string) error {
	_, err := c.Delete(c.Endpoint("users", user, "web", "sessions", sid))
	return trace.Wrap(err)
}
676876
func (sb *SessionBuilder) BuildSenderSession(pkb *PreKeyBundle) error {
	theirIdentityKey := pkb.IdentityKey
	if !sb.identityStore.IsTrustedIdentity(sb.recipientID, theirIdentityKey) {
		return NotTrustedError{sb.recipientID}
	}
	if pkb.SignedPreKeyPublic != nil &&
		!curve25519sign.Verify(*theirIdentityKey.Key(), pkb.SignedPreKeyPublic.Serialize(), &pkb.SignedPreKeySignature) {
		return InvalidSignatureError{pkb}
	}

	sr, err := sb.sessionStore.LoadSession(sb.recipientID, sb.deviceID)
	if err != nil {
		return err
	}
	ourBaseKey := NewECKeyPair()
	theirSignedPreKey := pkb.SignedPreKeyPublic
	theirOneTimePreKey := pkb.PreKeyPublic
	theirOneTimePreKeyID := pkb.PreKeyID

	ourIdentityKey, err := sb.identityStore.GetIdentityKeyPair()
	if err != nil {
		return err
	}
	alice := aliceAxolotlParameters{
		OurBaseKey:         ourBaseKey,
		OurIdentityKey:     ourIdentityKey,
		TheirIdentity:      pkb.IdentityKey,
		TheirSignedPreKey:  theirSignedPreKey,
		TheirRatchetKey:    theirSignedPreKey,
		TheirOneTimePreKey: theirOneTimePreKey,
	}

	if !sr.Fresh {
		sr.archiveCurrentState()
	}

	err = initializeSenderSession(sr.sessionState, 3, alice)
	if err != nil {
		return err
	}

	sr.sessionState.setUnacknowledgedPreKeyMessage(theirOneTimePreKeyID, pkb.SignedPreKeyID, &ourBaseKey.PublicKey)
	regID, err := sb.identityStore.GetLocalRegistrationID()
	if err != nil {
		return err
	}
	sr.sessionState.setLocalRegistrationID(regID)
	sr.sessionState.setRemoteRegistrationID(pkb.RegistrationID)
	sr.sessionState.setAliceBaseKey(ourBaseKey.PublicKey.Serialize())

	err = sb.sessionStore.StoreSession(sb.recipientID, sb.deviceID, sr)
	if err != nil {
		return err
	}
	err = sb.identityStore.SaveIdentity(sb.recipientID, theirIdentityKey)
	return err
}
422082
func (c *Ctx) CloseAllSessions(slotID uint) error {
	if c.ctx == nil {
		return toError(CKR_CRYPTOKI_NOT_INITIALIZED)
	}
	e := C.CloseAllSessions(c.ctx, C.CK_ULONG(slotID))
	return toError(e)
}
600507
func (c *Crowd) GetSession(token string) (s Session, err error) {
	c.Client.Jar = c.cookies
	url := c.url + "rest/usermanagement/1/session/" + token
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return s, err
	}
	req.SetBasicAuth(c.user, c.passwd)
	req.Header.Set("Accept", "application/xml")
	req.Header.Set("Content-Type", "application/xml")
	resp, err := c.Client.Do(req)
	if err != nil {
		return s, err
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case 404:
		return s, fmt.Errorf("session not found")
	case 200:
		// fall through switch without returning
	default:
		return s, fmt.Errorf("request failed: %s", resp.Status)
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return s, err
	}

	err = xml.Unmarshal(body, &s)
	if err != nil {
		return s, err
	}

	return s, nil
}
248687
func MakeFindSessionByTokenEndpoint(s Service) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		req := request.(findSessionByTokenRequest)
		session, err := s.FindSessionByToken(ctx, req.Token)
		return findSessionByTokenResponse{
			Session: session,
			Err:     err,
		}, nil
	}
}
1087713
func (s *Session) Close() error {
	if s.closed() {
		return errors.New("session is already closed")
	}

	s.writeMessage(&envelope{t: websocket.CloseMessage, msg: []byte{}})

	return nil
}
692589
func finalizer() lazyref.Finalizer {
	return func(v interface{}) {
		if handle, ok := v.(*ContextHandle); ok {
			err := handle.ctx.CloseAllSessions(handle.slot)
			if err != nil {
				logger.Warnf("unable to close all sessions in finalizer for [%s, %s] : %s", handle.lib, handle.label, err)
			}
			err = handle.ctx.Finalize()
			if err != nil {
				logger.Warnf("unable to finalize pkcs11 ctx in finalizer for [%s, %s] : %s", handle.lib, handle.label, err)
			}
			handle.ctx.Destroy()
			cachebridge.ClearAllSession()
		}
	}
}
936924
func StartSession(ctx context.Context) context.Context {
	sessionTrackerOnce.Do(startSessionTracking)
	return sessionTracker.StartSession(ctx)
}