mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 10:18:38 +00:00
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>
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user