aboutsummaryrefslogtreecommitdiffstats
path: root/modules/auth/sso/sspi_windows.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-01-05 21:05:40 +0800
committerGitHub <noreply@github.com>2021-01-05 21:05:40 +0800
commit15a475b7dbcf7923d9518dff7764b20e404eb774 (patch)
tree8789f1f82c5e41345b442df4e58120bdd5f8bade /modules/auth/sso/sspi_windows.go
parent126c9331d6d8789563fae5d5bac2196d63fee0e8 (diff)
downloadgitea-15a475b7dbcf7923d9518dff7764b20e404eb774.tar.gz
gitea-15a475b7dbcf7923d9518dff7764b20e404eb774.zip
Fix recovery middleware to render gitea style page. (#13857)
* Some changes to fix recovery * Move Recovery to middlewares * Remove trace code * Fix lint * add session middleware and remove dependent on macaron for sso * Fix panic 500 page rendering * Fix bugs * Fix fmt * Fix vendor * recover unnecessary change * Fix lint and addd some comments about the copied codes. * Use util.StatDir instead of com.StatDir Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/auth/sso/sspi_windows.go')
-rw-r--r--modules/auth/sso/sspi_windows.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/modules/auth/sso/sspi_windows.go b/modules/auth/sso/sspi_windows.go
index 62013737ca..5850dcf6e2 100644
--- a/modules/auth/sso/sspi_windows.go
+++ b/modules/auth/sso/sspi_windows.go
@@ -6,6 +6,7 @@ package sso
import (
"errors"
+ "net/http"
"reflect"
"strings"
@@ -64,7 +65,7 @@ func (s *SSPI) IsEnabled() bool {
// If authentication is successful, returs the corresponding user object.
// If negotiation should continue or authentication fails, immediately returns a 401 HTTP
// response code, as required by the SPNEGO protocol.
-func (s *SSPI) VerifyAuthData(ctx *macaron.Context, sess session.Store) *models.User {
+func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
if !s.shouldAuthenticate(ctx) {
return nil
}
@@ -75,7 +76,7 @@ func (s *SSPI) VerifyAuthData(ctx *macaron.Context, sess session.Store) *models.
return nil
}
- userInfo, outToken, err := sspiAuth.Authenticate(ctx.Req.Request, ctx.Resp)
+ userInfo, outToken, err := sspiAuth.Authenticate(req, ctx.Resp)
if err != nil {
log.Warn("Authentication failed with error: %v\n", err)
sspiAuth.AppendAuthenticateHeader(ctx.Resp, outToken)
@@ -139,18 +140,18 @@ func (s *SSPI) getConfig() (*models.SSPIConfig, error) {
return sources[0].SSPI(), nil
}
-func (s *SSPI) shouldAuthenticate(ctx *macaron.Context) (shouldAuth bool) {
+func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) {
shouldAuth = false
- path := strings.TrimSuffix(ctx.Req.URL.Path, "/")
+ path := strings.TrimSuffix(req.URL.Path, "/")
if path == "/user/login" {
- if ctx.Req.FormValue("user_name") != "" && ctx.Req.FormValue("password") != "" {
+ if req.FormValue("user_name") != "" && req.FormValue("password") != "" {
shouldAuth = false
} else if ctx.Req.FormValue("auth_with_sspi") == "1" {
shouldAuth = true
}
- } else if isInternalPath(ctx) {
+ } else if isInternalPath(req) {
shouldAuth = false
- } else if isAPIPath(ctx) || isAttachmentDownload(ctx) {
+ } else if isAPIPath(req) || isAttachmentDownload(req) {
shouldAuth = true
}
return
@@ -158,7 +159,7 @@ func (s *SSPI) shouldAuthenticate(ctx *macaron.Context) (shouldAuth bool) {
// newUser creates a new user object for the purpose of automatic registration
// and populates its name and email with the information present in request headers.
-func (s *SSPI) newUser(ctx *macaron.Context, username string, cfg *models.SSPIConfig) (*models.User, error) {
+func (s *SSPI) newUser(username string, cfg *models.SSPIConfig) (*models.User, error) {
email := gouuid.New().String() + "@localhost.localdomain"
user := &models.User{
Name: username,