refactor authentication (#1950)
This commit is contained in:
24
pkg/apiserver/authentication/request/anonymous.go
Normal file
24
pkg/apiserver/authentication/request/anonymous.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"k8s.io/apiserver/pkg/authentication/authenticator"
|
||||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AnonymousAuthenticator struct{}
|
||||
|
||||
func (a *AnonymousAuthenticator) AuthenticateRequest(req *http.Request) (*authenticator.Response, bool, error) {
|
||||
auth := strings.TrimSpace(req.Header.Get("Authorization"))
|
||||
if auth == "" {
|
||||
return &authenticator.Response{
|
||||
User: &user.DefaultInfo{
|
||||
Name: user.Anonymous,
|
||||
UID: "",
|
||||
Groups: []string{user.AllUnauthenticated},
|
||||
},
|
||||
}, true, nil
|
||||
}
|
||||
return nil, false, nil
|
||||
}
|
||||
Reference in New Issue
Block a user