Skip to content

Commit 85cb683

Browse files
committed
Revert "Fix windows build error (#14263)"
This reverts commit a1c9e8f
1 parent 4614060 commit 85cb683

File tree

9 files changed

+41
-44
lines changed

9 files changed

+41
-44
lines changed

modules/auth/sso/basic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (b *Basic) IsEnabled() bool {
4747
// "Authorization" header of the request and returns the corresponding user object for that
4848
// name/token on successful validation.
4949
// Returns nil if header is empty or validation fails.
50-
func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
50+
func (b *Basic) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
5151
baHead := req.Header.Get("Authorization")
5252
if len(baHead) == 0 {
5353
return nil

modules/auth/sso/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ type SingleSignOn interface {
4040
// or a new user object (with id = 0) populated with the information that was found
4141
// in the authentication data (username or email).
4242
// Returns nil if verification fails.
43-
VerifyAuthData(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User
43+
VerifyAuthData(http *http.Request, store DataStore, sess SessionStore) *models.User
4444
}

modules/auth/sso/oauth2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (o *OAuth2) IsEnabled() bool {
114114
// or the "Authorization" header and returns the corresponding user object for that ID.
115115
// If verification is successful returns an existing user object.
116116
// Returns nil if verification fails.
117-
func (o *OAuth2) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
117+
func (o *OAuth2) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
118118
if !models.HasEngine {
119119
return nil
120120
}

modules/auth/sso/reverseproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (r *ReverseProxy) IsEnabled() bool {
6060
// If a username is available in the "setting.ReverseProxyAuthUser" header an existing
6161
// user object is returned (populated with username or email found in header).
6262
// Returns nil if header is empty.
63-
func (r *ReverseProxy) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
63+
func (r *ReverseProxy) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
6464
username := r.getUserName(req)
6565
if len(username) == 0 {
6666
return nil

modules/auth/sso/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *Session) IsEnabled() bool {
3939
// VerifyAuthData checks if there is a user uid stored in the session and returns the user
4040
// object for that uid.
4141
// Returns nil if there is no user uid stored in the session.
42-
func (s *Session) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
42+
func (s *Session) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
4343
user := SessionUser(sess)
4444
if user != nil {
4545
return user

modules/auth/sso/sspi_windows.go

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ package sso
77
import (
88
"errors"
99
"net/http"
10+
"reflect"
1011
"strings"
1112

1213
"code.gitea.io/gitea/models"
1314
"code.gitea.io/gitea/modules/base"
1415
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/setting"
16-
"code.gitea.io/gitea/modules/templates"
17+
18+
"gitea.com/macaron/macaron"
19+
"gitea.com/macaron/session"
1720

1821
gouuid "github.com/google/uuid"
1922
"github.com/quasoft/websspi"
20-
"github.com/unrolled/render"
2123
)
2224

2325
const (
@@ -39,26 +41,14 @@ var (
3941
// On successful authentication returns a valid user object.
4042
// Returns nil if authentication fails.
4143
type SSPI struct {
42-
rnd *render.Render
4344
}
4445

4546
// Init creates a new global websspi.Authenticator object
4647
func (s *SSPI) Init() error {
4748
config := websspi.NewConfig()
4849
var err error
4950
sspiAuth, err = websspi.New(config)
50-
if err != nil {
51-
return err
52-
}
53-
s.rnd = render.New(render.Options{
54-
Extensions: []string{".tmpl"},
55-
Directory: "templates",
56-
Funcs: templates.NewFuncMap(),
57-
Asset: templates.GetAsset,
58-
AssetNames: templates.GetAssetNames,
59-
IsDevelopment: setting.RunMode != "prod",
60-
})
61-
return nil
51+
return err
6252
}
6353

6454
// Free releases resources used by the global websspi.Authenticator object
@@ -75,8 +65,8 @@ func (s *SSPI) IsEnabled() bool {
7565
// If authentication is successful, returs the corresponding user object.
7666
// If negotiation should continue or authentication fails, immediately returns a 401 HTTP
7767
// response code, as required by the SPNEGO protocol.
78-
func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
79-
if !s.shouldAuthenticate(req) {
68+
func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
69+
if !s.shouldAuthenticate(ctx) {
8070
return nil
8171
}
8272

@@ -86,29 +76,22 @@ func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store Da
8676
return nil
8777
}
8878

89-
userInfo, outToken, err := sspiAuth.Authenticate(req, w)
79+
userInfo, outToken, err := sspiAuth.Authenticate(req, ctx.Resp)
9080
if err != nil {
9181
log.Warn("Authentication failed with error: %v\n", err)
92-
sspiAuth.AppendAuthenticateHeader(w, outToken)
82+
sspiAuth.AppendAuthenticateHeader(ctx.Resp, outToken)
9383

9484
// Include the user login page in the 401 response to allow the user
9585
// to login with another authentication method if SSPI authentication
9686
// fails
97-
store.GetData()["Flash"] = map[string]string{
98-
"ErrMsg": err.Error(),
99-
}
100-
store.GetData()["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
101-
store.GetData()["EnableSSPI"] = true
102-
103-
err := s.rnd.HTML(w, 401, string(tplSignIn), templates.BaseVars().Merge(store.GetData()))
104-
if err != nil {
105-
log.Error("%v", err)
106-
}
107-
87+
addFlashErr(ctx, ctx.Tr("auth.sspi_auth_failed"))
88+
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
89+
ctx.Data["EnableSSPI"] = true
90+
ctx.HTML(401, string(tplSignIn))
10891
return nil
10992
}
11093
if outToken != "" {
111-
sspiAuth.AppendAuthenticateHeader(w, outToken)
94+
sspiAuth.AppendAuthenticateHeader(ctx.Resp, outToken)
11295
}
11396

11497
username := sanitizeUsername(userInfo.Username, cfg)
@@ -127,16 +110,16 @@ func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store Da
127110
log.Error("User '%s' not found", username)
128111
return nil
129112
}
130-
user, err = s.newUser(username, cfg)
113+
user, err = s.newUser(ctx, username, cfg)
131114
if err != nil {
132115
log.Error("CreateUser: %v", err)
133116
return nil
134117
}
135118
}
136119

137120
// Make sure requests to API paths and PWA resources do not create a new session
138-
if !isAPIPath(req) && !isAttachmentDownload(req) {
139-
handleSignIn(w, req, sess, user)
121+
if !isAPIPath(ctx) && !isAttachmentDownload(ctx) {
122+
handleSignIn(ctx, sess, user)
140123
}
141124

142125
return user
@@ -163,7 +146,7 @@ func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) {
163146
if path == "/user/login" {
164147
if req.FormValue("user_name") != "" && req.FormValue("password") != "" {
165148
shouldAuth = false
166-
} else if req.FormValue("auth_with_sspi") == "1" {
149+
} else if ctx.Req.FormValue("auth_with_sspi") == "1" {
167150
shouldAuth = true
168151
}
169152
} else if isInternalPath(req) {
@@ -234,6 +217,20 @@ func sanitizeUsername(username string, cfg *models.SSPIConfig) string {
234217
return username
235218
}
236219

220+
// addFlashErr adds an error message to the Flash object mapped to a macaron.Context
221+
func addFlashErr(ctx *macaron.Context, err string) {
222+
fv := ctx.GetVal(reflect.TypeOf(&session.Flash{}))
223+
if !fv.IsValid() {
224+
return
225+
}
226+
flash, ok := fv.Interface().(*session.Flash)
227+
if !ok {
228+
return
229+
}
230+
flash.Error(err)
231+
ctx.Data["Flash"] = flash
232+
}
233+
237234
// init registers the SSPI auth method as the last method in the list.
238235
// The SSPI plugin is expected to be executed last, as it returns 401 status code if negotiation
239236
// fails (or if negotiation should continue), which would prevent other authentication methods

modules/auth/sso/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// SignedInUser returns the user object of signed user.
1414
// It returns a bool value to indicate whether user uses basic auth or not.
15-
func SignedInUser(req *http.Request, w http.ResponseWriter, ds DataStore, sess SessionStore) (*models.User, bool) {
15+
func SignedInUser(req *http.Request, ds DataStore, sess SessionStore) (*models.User, bool) {
1616
if !models.HasEngine {
1717
return nil, false
1818
}
@@ -22,7 +22,7 @@ func SignedInUser(req *http.Request, w http.ResponseWriter, ds DataStore, sess S
2222
if !ssoMethod.IsEnabled() {
2323
continue
2424
}
25-
user := ssoMethod.VerifyAuthData(req, w, ds, sess)
25+
user := ssoMethod.VerifyAuthData(req, ds, sess)
2626
if user != nil {
2727
_, isBasic := ssoMethod.(*Basic)
2828
return user, isBasic

modules/context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func Contexter() macaron.Handler {
309309
}
310310

311311
// Get user from session if logged in.
312-
ctx.User, ctx.IsBasicAuth = sso.SignedInUser(ctx.Req.Request, c.Resp, ctx, ctx.Session)
312+
ctx.User, ctx.IsBasicAuth = sso.SignedInUser(ctx.Req.Request, ctx, ctx.Session)
313313

314314
if ctx.User != nil {
315315
ctx.IsSigned = true

routers/routes/recovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func Recovery() func(next http.Handler) http.Handler {
7575
}
7676

7777
// Get user from session if logged in.
78-
user, _ := sso.SignedInUser(req, w, &store, sess)
78+
user, _ := sso.SignedInUser(req, &store, sess)
7979
if user != nil {
8080
store.Data["IsSigned"] = true
8181
store.Data["SignedUser"] = user

0 commit comments

Comments
 (0)