@@ -19,8 +19,14 @@ type Authenticator interface {
1919 // else returns an empty string.
2020 Validate (r * http.Request ) (string , error )
2121 // ValidateAndReject is called on an HTTP API request and returns the username if request
22- // is authenticated, else the request is rejected .
22+ // is authenticated, else returns an empty string and rejects the request .
2323 ValidateAndReject (w http.ResponseWriter , r * http.Request ) string
24+ // HasPerm returns a boolean indicating whether or not the user has the requested permission.
25+ HasPerm (username string , permission string ) (bool , error )
26+ // ValidatePermAndReject is called on an HTTP API request and returns the username if request is
27+ // authenticated, and a boolean indicating whether or not the user has the requested permission.
28+ // If unauthenticated or forbidden, the request is rejected with a 401 or 403 error respectively.
29+ ValidatePermAndReject (w http.ResponseWriter , r * http.Request , permission string ) (string , bool )
2430 // CanManageAuth returns whether or not this authenticator can manage auth, i.e. users and tokens.
2531 CanManageAuth () bool
2632 // Login allows logging in a user and returning the token.
@@ -68,6 +74,22 @@ func (a *ReplaceableAuthenticator) ValidateAndReject(w http.ResponseWriter, r *h
6874 return a .Engine .ValidateAndReject (w , r )
6975}
7076
77+ // HasPerm returns a boolean indicating whether or not the user has the requested permission.
78+ func (a * ReplaceableAuthenticator ) HasPerm (username string , permission string ) (bool , error ) {
79+ a .EngineMutex .RLock ()
80+ defer a .EngineMutex .RUnlock ()
81+ return a .Engine .HasPerm (username , permission )
82+ }
83+
84+ // ValidatePermAndReject is called on an HTTP API request and returns the username if request is
85+ // authenticated, and a boolean indicating whether or not the user has the requested permission.
86+ // If unauthenticated or forbidden, the request is rejected with a 401 or 403 error respectively.
87+ func (a * ReplaceableAuthenticator ) ValidatePermAndReject (w http.ResponseWriter , r * http.Request , permission string ) (string , bool ) {
88+ a .EngineMutex .RLock ()
89+ defer a .EngineMutex .RUnlock ()
90+ return a .Engine .ValidatePermAndReject (w , r , permission )
91+ }
92+
7193// CanManageAuth returns whether or not this authenticator can manage auth, i.e. users and tokens.
7294func (a * ReplaceableAuthenticator ) CanManageAuth () bool {
7395 a .EngineMutex .RLock ()
0 commit comments