Skip to content

Commit a2df265

Browse files
authored
Add trace logging to SSO methods (#15803)
It is currenly impossible to detect which "SSO" method is responsible for login. This PR adds some basic trace logging to these methods. Signed-off-by: Andrew Thornton <[email protected]>
1 parent 4ea0b46 commit a2df265

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

modules/auth/sso/basic.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@ func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store D
6666
// Assume username is token
6767
authToken := uname
6868
if !isUsernameToken {
69+
log.Trace("Basic Authorization: Attempting login for: %s", uname)
6970
// Assume password is token
7071
authToken = passwd
72+
} else {
73+
log.Trace("Basic Authorization: Attempting login with username as token")
7174
}
7275

7376
uid := CheckOAuthAccessToken(authToken)
7477
if uid != 0 {
78+
log.Trace("Basic Authorization: Valid OAuthAccessToken for user[%d]", uid)
7579
var err error
7680
store.GetData()["IsApiToken"] = true
7781

@@ -83,6 +87,8 @@ func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store D
8387
}
8488
token, err := models.GetAccessTokenBySHA(authToken)
8589
if err == nil {
90+
log.Trace("Basic Authorization: Valid AccessToken for user[%d]", uid)
91+
8692
u, err = models.GetUserByID(token.UID)
8793
if err != nil {
8894
log.Error("GetUserByID: %v", err)
@@ -98,6 +104,8 @@ func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store D
98104
}
99105

100106
if u == nil {
107+
log.Trace("Basic Authorization: Attempting SignIn for %s", uname)
108+
101109
u, err = models.UserSignIn(uname, passwd)
102110
if err != nil {
103111
if !models.IsErrUserNotExist(err) {
@@ -109,5 +117,7 @@ func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store D
109117
store.GetData()["IsApiToken"] = true
110118
}
111119

120+
log.Trace("Basic Authorization: Logged in user %-v", u)
121+
112122
return u
113123
}

modules/auth/sso/oauth2.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (o *OAuth2) VerifyAuthData(req *http.Request, w http.ResponseWriter, store
130130
if id <= 0 {
131131
return nil
132132
}
133+
log.Trace("OAuth2 Authorization: Found token for user[%d]", id)
133134

134135
user, err := models.GetUserByID(id)
135136
if err != nil {
@@ -139,5 +140,6 @@ func (o *OAuth2) VerifyAuthData(req *http.Request, w http.ResponseWriter, store
139140
return nil
140141
}
141142

143+
log.Trace("OAuth2 Authorization: Logged in user %-v", user)
142144
return user
143145
}

modules/auth/sso/reverseproxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (r *ReverseProxy) VerifyAuthData(req *http.Request, w http.ResponseWriter,
6565
if len(username) == 0 {
6666
return nil
6767
}
68+
log.Trace("ReverseProxy Authorization: Found username: %s", username)
6869

6970
user, err := models.GetUserByName(username)
7071
if err != nil {
@@ -75,6 +76,7 @@ func (r *ReverseProxy) VerifyAuthData(req *http.Request, w http.ResponseWriter,
7576
return nil
7677
}
7778

79+
log.Trace("ReverseProxy Authorization: Logged in user %-v", user)
7880
return user
7981
}
8082

modules/auth/sso/sso.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func SessionUser(sess SessionStore) *models.User {
7777
if uid == nil {
7878
return nil
7979
}
80+
log.Trace("Session Authorization: Found user[%d]", uid)
81+
8082
id, ok := uid.(int64)
8183
if !ok {
8284
return nil
@@ -90,6 +92,8 @@ func SessionUser(sess SessionStore) *models.User {
9092
}
9193
return nil
9294
}
95+
96+
log.Trace("Session Authorization: Logged in user %-v", user)
9397
return user
9498
}
9599

modules/auth/sso/sspi_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store Da
8787
return nil
8888
}
8989

90+
log.Trace("SSPI Authorization: Attempting to authenticate")
9091
userInfo, outToken, err := sspiAuth.Authenticate(req, w)
9192
if err != nil {
9293
log.Warn("Authentication failed with error: %v\n", err)
@@ -140,6 +141,7 @@ func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store Da
140141
handleSignIn(w, req, sess, user)
141142
}
142143

144+
log.Trace("SSPI Authorization: Logged in user %-v", user)
143145
return user
144146
}
145147

0 commit comments

Comments
 (0)