auth

Paddy 2014-09-27 Parent:fb827644bfd8 Child:e45bfa2abc00

45:3a6a65ed380c Go to Latest

auth/memstore.go

Update uuid import path, test for multiple profile updates. Test updating multiple profiles in one request (e.g., when profiles become compromised.) Update the uuid import path to use the new code.secondbit.org/uuid import path.

History
1 package auth
3 import (
4 "sync"
6 "code.secondbit.org/uuid"
7 )
9 type Memstore struct {
10 tokens map[string]Token
11 refreshTokenLookup map[string]string
12 profileTokenLookup map[string][]string
13 tokenLock sync.RWMutex
15 grants map[string]Grant
16 grantLock sync.RWMutex
18 clients map[string]Client
19 profileClientLookup map[string][]uuid.ID
20 clientLock sync.RWMutex
22 endpoints map[string][]Endpoint
23 endpointLock sync.RWMutex
25 profiles map[string]Profile
26 profileLock sync.RWMutex
28 logins map[string]Login
29 profileLoginLookup map[string][]string
30 loginLock sync.RWMutex
31 }
33 func NewMemstore() *Memstore {
34 return &Memstore{
35 tokens: map[string]Token{},
36 refreshTokenLookup: map[string]string{},
37 profileTokenLookup: map[string][]string{},
38 grants: map[string]Grant{},
39 clients: map[string]Client{},
40 profileClientLookup: map[string][]uuid.ID{},
41 endpoints: map[string][]Endpoint{},
42 profiles: map[string]Profile{},
43 logins: map[string]Login{},
44 profileLoginLookup: map[string][]string{},
45 }
46 }
48 func (m *Memstore) lookupTokenByRefresh(token string) (string, error) {
49 m.tokenLock.RLock()
50 defer m.tokenLock.RUnlock()
51 t, ok := m.refreshTokenLookup[token]
52 if !ok {
53 return "", ErrTokenNotFound
54 }
55 return t, nil
56 }
58 func (m *Memstore) lookupTokensByProfileID(id string) ([]string, error) {
59 m.tokenLock.RLock()
60 defer m.tokenLock.RUnlock()
61 return m.profileTokenLookup[id], nil
62 }
64 func (m *Memstore) lookupClientsByProfileID(id string) []uuid.ID {
65 m.clientLock.RLock()
66 defer m.clientLock.RUnlock()
67 c, ok := m.profileClientLookup[id]
68 if !ok {
69 return []uuid.ID{}
70 }
71 return c
72 }