Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2014 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package authenticator |
| 18 | |
| 19 | import ( |
| 20 | "net/http" |
| 21 | |
| 22 | "k8s.io/apiserver/pkg/authentication/user" |
| 23 | ) |
| 24 | |
| 25 | // Token checks a string value against a backing authentication store and returns |
| 26 | // information about the current user and true if successful, false if not successful, |
| 27 | // or an error if the token could not be checked. |
| 28 | type Token interface { |
| 29 | AuthenticateToken(token string) (user.Info, bool, error) |
| 30 | } |
| 31 | |
| 32 | // Request attempts to extract authentication information from a request and returns |
| 33 | // information about the current user and true if successful, false if not successful, |
| 34 | // or an error if the request could not be checked. |
| 35 | type Request interface { |
| 36 | AuthenticateRequest(req *http.Request) (user.Info, bool, error) |
| 37 | } |
| 38 | |
| 39 | // Password checks a username and password against a backing authentication store and |
| 40 | // returns information about the user and true if successful, false if not successful, |
| 41 | // or an error if the username and password could not be checked |
| 42 | type Password interface { |
| 43 | AuthenticatePassword(user, password string) (user.Info, bool, error) |
| 44 | } |
| 45 | |
| 46 | // TokenFunc is a function that implements the Token interface. |
| 47 | type TokenFunc func(token string) (user.Info, bool, error) |
| 48 | |
| 49 | // AuthenticateToken implements authenticator.Token. |
| 50 | func (f TokenFunc) AuthenticateToken(token string) (user.Info, bool, error) { |
| 51 | return f(token) |
| 52 | } |
| 53 | |
| 54 | // RequestFunc is a function that implements the Request interface. |
| 55 | type RequestFunc func(req *http.Request) (user.Info, bool, error) |
| 56 | |
| 57 | // AuthenticateRequest implements authenticator.Request. |
| 58 | func (f RequestFunc) AuthenticateRequest(req *http.Request) (user.Info, bool, error) { |
| 59 | return f(req) |
| 60 | } |
| 61 | |
| 62 | // PasswordFunc is a function that implements the Password interface. |
| 63 | type PasswordFunc func(user, password string) (user.Info, bool, error) |
| 64 | |
| 65 | // AuthenticatePassword implements authenticator.Password. |
| 66 | func (f PasswordFunc) AuthenticatePassword(user, password string) (user.Info, bool, error) { |
| 67 | return f(user, password) |
| 68 | } |