init commit
This commit is contained in:
41
server/web/auth/context.go
Normal file
41
server/web/auth/context.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package auth
|
||||
|
||||
type Context interface {
|
||||
Permissions() map[string]struct{}
|
||||
PermitAll(permissions ...string) bool
|
||||
PermitAny(permissions ...string) bool
|
||||
}
|
||||
|
||||
// region DeviceContext
|
||||
|
||||
type DeviceContext struct {
|
||||
ID uint
|
||||
IpAddress string
|
||||
Permissions map[string]struct{}
|
||||
}
|
||||
|
||||
func (c DeviceContext) PermitAny(permissions ...string) bool {
|
||||
if _, exist := c.Permissions["*"]; exist {
|
||||
return true
|
||||
}
|
||||
for _, permission := range permissions {
|
||||
if _, ok := c.Permissions[permission]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c DeviceContext) PermitAll(permissions ...string) bool {
|
||||
if _, exist := c.Permissions["*"]; exist {
|
||||
return true
|
||||
}
|
||||
for _, permission := range permissions {
|
||||
if _, ok := c.Permissions[permission]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// endregion
|
||||
Reference in New Issue
Block a user