Skip to content

Commit 4f4468f

Browse files
committed
fix build
1 parent 4ef5f17 commit 4f4468f

File tree

9 files changed

+42
-26
lines changed

9 files changed

+42
-26
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, store DataStore, sess SessionStore) *models.User {
50+
func (b *Basic) VerifyAuthData(req *http.Request, w http.ResponseWriter, 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, store DataStore, sess SessionStore) *models.User
43+
VerifyAuthData(http *http.Request, w http.ResponseWriter, 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, store DataStore, sess SessionStore) *models.User {
117+
func (o *OAuth2) VerifyAuthData(req *http.Request, w http.ResponseWriter, 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, store DataStore, sess SessionStore) *models.User {
63+
func (r *ReverseProxy) VerifyAuthData(req *http.Request, w http.ResponseWriter, 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, store DataStore, sess SessionStore) *models.User {
42+
func (s *Session) VerifyAuthData(req *http.Request, w http.ResponseWriter, 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: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@
55
package sso
66

77
import (
8+
"code.gitea.io/gitea/modules/templates"
89
"errors"
910
"net/http"
10-
"reflect"
1111
"strings"
1212

1313
"code.gitea.io/gitea/models"
1414
"code.gitea.io/gitea/modules/base"
1515
"code.gitea.io/gitea/modules/log"
1616
"code.gitea.io/gitea/modules/setting"
1717

18-
"gitea.com/macaron/macaron"
19-
"gitea.com/macaron/session"
20-
2118
gouuid "github.com/google/uuid"
2219
"github.com/quasoft/websspi"
20+
"github.com/unrolled/render"
2321
)
2422

2523
const (
@@ -65,8 +63,8 @@ func (s *SSPI) IsEnabled() bool {
6563
// If authentication is successful, returs the corresponding user object.
6664
// If negotiation should continue or authentication fails, immediately returns a 401 HTTP
6765
// response code, as required by the SPNEGO protocol.
68-
func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionStore) *models.User {
69-
if !s.shouldAuthenticate(ctx) {
66+
func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
67+
if !s.shouldAuthenticate(req) {
7068
return nil
7169
}
7270

@@ -76,22 +74,36 @@ func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionSt
7674
return nil
7775
}
7876

79-
userInfo, outToken, err := sspiAuth.Authenticate(req, ctx.Resp)
77+
userInfo, outToken, err := sspiAuth.Authenticate(req, w)
8078
if err != nil {
8179
log.Warn("Authentication failed with error: %v\n", err)
82-
sspiAuth.AppendAuthenticateHeader(ctx.Resp, outToken)
80+
sspiAuth.AppendAuthenticateHeader(w, outToken)
8381

8482
// Include the user login page in the 401 response to allow the user
8583
// to login with another authentication method if SSPI authentication
8684
// fails
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))
85+
//addFlashErr(ctx, ctx.Tr("auth.sspi_auth_failed"))
86+
87+
store.GetData()["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
88+
store.GetData()["EnableSSPI"] = true
89+
90+
rnd := render.New(render.Options{
91+
Extensions: []string{".tmpl"},
92+
Directory: "templates",
93+
Funcs: templates.NewFuncMap(),
94+
Asset: templates.GetAsset,
95+
AssetNames: templates.GetAssetNames,
96+
IsDevelopment: setting.RunMode != "prod",
97+
})
98+
err := rnd.HTML(w, 401, string(tplSignIn), templates.BaseVars().Merge(store.GetData()))
99+
if err != nil {
100+
log.Error("%v", err)
101+
}
102+
91103
return nil
92104
}
93105
if outToken != "" {
94-
sspiAuth.AppendAuthenticateHeader(ctx.Resp, outToken)
106+
sspiAuth.AppendAuthenticateHeader(w, outToken)
95107
}
96108

97109
username := sanitizeUsername(userInfo.Username, cfg)
@@ -110,16 +122,16 @@ func (s *SSPI) VerifyAuthData(req *http.Request, store DataStore, sess SessionSt
110122
log.Error("User '%s' not found", username)
111123
return nil
112124
}
113-
user, err = s.newUser(ctx, username, cfg)
125+
user, err = s.newUser(username, cfg)
114126
if err != nil {
115127
log.Error("CreateUser: %v", err)
116128
return nil
117129
}
118130
}
119131

120132
// Make sure requests to API paths and PWA resources do not create a new session
121-
if !isAPIPath(ctx) && !isAttachmentDownload(ctx) {
122-
handleSignIn(ctx, sess, user)
133+
if !isAPIPath(req) && !isAttachmentDownload(req) {
134+
handleSignIn(w, req, sess, user)
123135
}
124136

125137
return user
@@ -146,7 +158,7 @@ func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) {
146158
if path == "/user/login" {
147159
if req.FormValue("user_name") != "" && req.FormValue("password") != "" {
148160
shouldAuth = false
149-
} else if ctx.Req.FormValue("auth_with_sspi") == "1" {
161+
} else if req.FormValue("auth_with_sspi") == "1" {
150162
shouldAuth = true
151163
}
152164
} else if isInternalPath(req) {
@@ -217,6 +229,8 @@ func sanitizeUsername(username string, cfg *models.SSPIConfig) string {
217229
return username
218230
}
219231

232+
/*
233+
// TODO flash err not implemented for chi
220234
// addFlashErr adds an error message to the Flash object mapped to a macaron.Context
221235
func addFlashErr(ctx *macaron.Context, err string) {
222236
fv := ctx.GetVal(reflect.TypeOf(&session.Flash{}))
@@ -231,6 +245,8 @@ func addFlashErr(ctx *macaron.Context, err string) {
231245
ctx.Data["Flash"] = flash
232246
}
233247
248+
*/
249+
234250
// init registers the SSPI auth method as the last method in the list.
235251
// The SSPI plugin is expected to be executed last, as it returns 401 status code if negotiation
236252
// 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, ds DataStore, sess SessionStore) (*models.User, bool) {
15+
func SignedInUser(req *http.Request, w http.ResponseWriter, 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, ds DataStore, sess SessionStore) (*models.U
2222
if !ssoMethod.IsEnabled() {
2323
continue
2424
}
25-
user := ssoMethod.VerifyAuthData(req, ds, sess)
25+
user := ssoMethod.VerifyAuthData(req, w, 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, ctx, ctx.Session)
312+
ctx.User, ctx.IsBasicAuth = sso.SignedInUser(ctx.Req.Request, c.Resp, 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, &store, sess)
78+
user, _ := sso.SignedInUser(req, w, &store, sess)
7979
if user != nil {
8080
store.Data["IsSigned"] = true
8181
store.Data["SignedUser"] = user

0 commit comments

Comments
 (0)