Files
kubesphere/vendor/gopkg.in/cas.v2/session_store.go
hongming 5f0727cf34 support CAS identity provider
Signed-off-by: hongming <talonwan@yunify.com>
2021-02-20 10:45:55 +08:00

53 lines
1.0 KiB
Go

package cas
import "sync"
// SessionStore store the session's ticket
// SessionID is retrived from cookies
type SessionStore interface {
// Get the ticket with the session id
Get(sessionID string) (string, bool)
// Set the session with a ticket
Set(sessionID, ticket string) error
// Delete the session
Delete(sessionID string) error
}
// NewMemorySessionStore create a default SessionStore that uses memory
func NewMemorySessionStore() SessionStore {
return &memorySessionStore{
sessions: make(map[string]string),
}
}
type memorySessionStore struct {
mu sync.RWMutex
sessions map[string]string
}
func (m *memorySessionStore) Get(sessionID string) (string, bool) {
m.mu.RLock()
ticket, ok := m.sessions[sessionID]
m.mu.RUnlock()
return ticket, ok
}
func (m *memorySessionStore) Set(sessionID, ticket string) error {
m.mu.Lock()
m.sessions[sessionID] = ticket
m.mu.Unlock()
return nil
}
func (m *memorySessionStore) Delete(sessionID string) error {
m.mu.Lock()
delete(m.sessions, sessionID)
m.mu.Unlock()
return nil
}