This repository has been archived on 2020-04-20. You can view files and clone it, but cannot push or open issues or pull requests.
2018-01-15 18:07:54 +00:00
|
|
|
package connection
|
|
|
|
|
|
|
|
import (
|
2018-06-08 21:54:31 +00:00
|
|
|
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
2018-01-15 18:07:54 +00:00
|
|
|
)
|
|
|
|
|
2018-01-17 18:18:46 +00:00
|
|
|
// AuthorizationManager helps keep track of permissions for a connection
|
2018-01-15 18:07:54 +00:00
|
|
|
type AuthorizationManager struct {
|
|
|
|
Authorizations map[string]bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init sets up an AuthorizationManager to be used.
|
|
|
|
func (am *AuthorizationManager) Init() {
|
|
|
|
am.Authorizations = make(map[string]bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAuthorization adds the string authz to the map of allowed authorizations
|
|
|
|
func (am *AuthorizationManager) AddAuthorization(authz string) {
|
|
|
|
am.Authorizations[authz] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Authorized returns no error in the case an authz type is authorized, error otherwise.
|
|
|
|
func (am *AuthorizationManager) Authorized(authz string) error {
|
|
|
|
_, authed := am.Authorizations[authz]
|
|
|
|
if !authed {
|
|
|
|
return utils.UnauthorizedActionError
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|