auth

Paddy 2014-10-22 Parent:3a6a65ed380c Child:e45bfa2abc00

55:cfab12566289 Go to Latest

auth/memstore.go

Update Context with new CheckEndpoint and CountEndpoints. Update the Context.CheckEndpoint method to pass through the new "strict" parameter that controls how URLs are checked for validation. Add a Context.CountEndpoints method to safely access the number of endpoints in stored for the client in the associent ClientStore. Finally, remove the error return from Context.Render, as we'd only ever want to log that, anyways. So we may as well just log it from the central function.

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 }