blob: fd3d0383e52b364fb933257eb2129461b9700885 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package authenticator
18
19import (
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.
28type 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.
35type 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
42type Password interface {
43 AuthenticatePassword(user, password string) (user.Info, bool, error)
44}
45
46// TokenFunc is a function that implements the Token interface.
47type TokenFunc func(token string) (user.Info, bool, error)
48
49// AuthenticateToken implements authenticator.Token.
50func (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.
55type RequestFunc func(req *http.Request) (user.Info, bool, error)
56
57// AuthenticateRequest implements authenticator.Request.
58func (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.
63type PasswordFunc func(user, password string) (user.Info, bool, error)
64
65// AuthenticatePassword implements authenticator.Password.
66func (f PasswordFunc) AuthenticatePassword(user, password string) (user.Info, bool, error) {
67 return f(user, password)
68}