Fix redirect to login page from snapshot page when not authenticated.
Fixes #28547
(cherry picked from commit a97637a133)
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
co-authored by
Marcus Efraimsson
parent
cfc0e132f5
commit
f570fb2d6f
+24
-6
@@ -76,13 +76,8 @@ func RoleAuth(roles ...models.RoleType) macaron.Handler {
|
||||
func Auth(options *AuthOptions) macaron.Handler {
|
||||
return func(c *models.ReqContext) {
|
||||
forceLogin := false
|
||||
|
||||
if c.AllowAnonymous {
|
||||
forceLoginParam, err := strconv.ParseBool(c.Req.URL.Query().Get("forceLogin"))
|
||||
if err == nil {
|
||||
forceLogin = forceLoginParam
|
||||
}
|
||||
|
||||
forceLogin = shouldForceLogin(c)
|
||||
if !forceLogin {
|
||||
orgIDValue := c.Req.URL.Query().Get("orgId")
|
||||
orgID, err := strconv.ParseInt(orgIDValue, 10, 64)
|
||||
@@ -137,3 +132,26 @@ func SnapshotPublicModeOrSignedIn(cfg *setting.Cfg) macaron.Handler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NoAuth creates a middleware that doesn't require any authentication.
|
||||
// If forceLogin param is set it will redirect the user to the login page.
|
||||
func NoAuth() macaron.Handler {
|
||||
return func(c *models.ReqContext) {
|
||||
if shouldForceLogin(c) {
|
||||
notAuthorized(c)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// shouldForceLogin checks if user should be enforced to login.
|
||||
// Returns true if forceLogin parameter is set.
|
||||
func shouldForceLogin(c *models.ReqContext) bool {
|
||||
forceLogin := false
|
||||
forceLoginParam, err := strconv.ParseBool(c.Req.URL.Query().Get("forceLogin"))
|
||||
if err == nil {
|
||||
forceLogin = forceLoginParam
|
||||
}
|
||||
|
||||
return forceLogin
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user