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

61 lines
1.1 KiB
Go

package cas
import (
"sync"
)
// MemoryStore implements the TicketStore interface storing ticket data in memory.
type MemoryStore struct {
mu sync.RWMutex
store map[string]*AuthenticationResponse
}
// Read returns the AuthenticationResponse for a ticket
func (s *MemoryStore) Read(id string) (*AuthenticationResponse, error) {
s.mu.RLock()
if s.store == nil {
s.mu.RUnlock()
return nil, ErrInvalidTicket
}
t, ok := s.store[id]
s.mu.RUnlock()
if !ok {
return nil, ErrInvalidTicket
}
return t, nil
}
// Write stores the AuthenticationResponse for a ticket
func (s *MemoryStore) Write(id string, ticket *AuthenticationResponse) error {
s.mu.Lock()
if s.store == nil {
s.store = make(map[string]*AuthenticationResponse)
}
s.store[id] = ticket
s.mu.Unlock()
return nil
}
// Delete removes the AuthenticationResponse for a ticket
func (s *MemoryStore) Delete(id string) error {
s.mu.Lock()
delete(s.store, id)
s.mu.Unlock()
return nil
}
// Clear removes all ticket data
func (s *MemoryStore) Clear() error {
s.mu.Lock()
s.store = nil
s.mu.Unlock()
return nil
}