-
Notifications
You must be signed in to change notification settings - Fork 96
/
memory_store.go
60 lines (47 loc) · 1.08 KB
/
memory_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
}