moved sync out of JWT and added new secret reader
This commit is contained in:
parent
4c14116a41
commit
9b4adfe863
3 changed files with 82 additions and 33 deletions
49
blacklist.go
49
blacklist.go
|
|
@ -2,39 +2,60 @@
|
|||
|
||||
package jwt
|
||||
|
||||
import "sync"
|
||||
|
||||
// Blacklist is the blacklisting storage interface
|
||||
type Blacklist interface {
|
||||
Add(string, int64)
|
||||
Remove(string)
|
||||
Check(string) bool
|
||||
Map() MapBlacklist
|
||||
Map() BlacklistMap
|
||||
}
|
||||
|
||||
// MapBlacklist implements the Blacklist interface
|
||||
type MapBlacklist map[string]int64
|
||||
// BlacklistMap is the blacklist map structure
|
||||
type BlacklistMap map[string]int64
|
||||
|
||||
// NewMapBlacklist
|
||||
func NewMapBlacklist() MapBlacklist {
|
||||
return make(MapBlacklist)
|
||||
// MemBlacklist implements the Blacklist interface
|
||||
type MemBlacklist struct {
|
||||
// protects list
|
||||
sync.RWMutex
|
||||
list BlacklistMap
|
||||
}
|
||||
|
||||
// NewMemBlacklist
|
||||
func NewMemBlacklist() *MemBlacklist {
|
||||
return &MemBlacklist{list: make(BlacklistMap)}
|
||||
}
|
||||
|
||||
// Add adds a new token signature with expiration time to the blacklist
|
||||
func (mb MapBlacklist) Add(sig string, exp int64) {
|
||||
mb[sig] = exp
|
||||
func (mb MemBlacklist) Add(sig string, exp int64) {
|
||||
mb.Lock()
|
||||
mb.list[sig] = exp
|
||||
mb.Unlock()
|
||||
}
|
||||
|
||||
// Remove deletes a token signature from the blacklist
|
||||
func (mb MapBlacklist) Remove(sig string) {
|
||||
delete(mb, sig)
|
||||
func (mb MemBlacklist) Remove(sig string) {
|
||||
mb.Lock()
|
||||
delete(mb.list, sig)
|
||||
mb.Unlock()
|
||||
}
|
||||
|
||||
// Check returns true if a token signature is blacklisted and false otherwise
|
||||
func (mb MapBlacklist) Check(sig string) (ok bool) {
|
||||
_, ok = mb[sig]
|
||||
func (mb MemBlacklist) Check(sig string) (ok bool) {
|
||||
mb.RLock()
|
||||
_, ok = mb.list[sig]
|
||||
mb.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// Map returns the blacklist in the form of a iterable map structure for cleanup
|
||||
func (mb MapBlacklist) Map() MapBlacklist {
|
||||
return mb
|
||||
func (mb MemBlacklist) Map() (list BlacklistMap) {
|
||||
list = make(BlacklistMap)
|
||||
mb.RLock()
|
||||
for k, v := range mb.list {
|
||||
list[k] = v
|
||||
}
|
||||
mb.RUnlock()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue