forked from kubernetes/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidateloginstatus.go
50 lines (44 loc) · 1.86 KB
/
validateloginstatus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package validation
import (
restful "github.com/emicklei/go-restful"
"github.com/kubernetes/dashboard/src/app/backend/args"
"github.com/kubernetes/dashboard/src/app/backend/client"
)
// LoginStatus is returned as a response to login status check. Used by the frontend to determine if is logged in
// and if login page should be shown.
type LoginStatus struct {
// True when token header indicating logged in user is found in request.
TokenPresent bool `json:"tokenPresent"`
// True when authorization header indicating logged in user is found in request.
HeaderPresent bool `json:"headerPresent"`
// True if dashboard is configured to use HTTPS connection. It is required for secure
// data exchange during login operation.
HTTPSMode bool `json:"httpsMode"`
}
// ValidateLoginStatus returns information about user login status and if request was made over HTTPS.
func ValidateLoginStatus(request *restful.Request) *LoginStatus {
authHeader := request.HeaderParameter("Authorization")
tokenHeader := request.HeaderParameter(client.JWETokenHeader)
httpsMode := request.Request.TLS != nil
if args.Holder.GetEnableInsecureLogin() {
httpsMode = true
}
return &LoginStatus{
TokenPresent: len(tokenHeader) > 0,
HeaderPresent: len(authHeader) > 0,
HTTPSMode: httpsMode,
}
}