Commit 0fd78686 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Enable authentication middleware for API routes

- Uncomment and activate AuthMiddleware in router configuration
- Add conditional skip for ping endpoint in authentication middleware
- Restore authentication checks for both release and debug modes
parent ab374dd5
...@@ -7,8 +7,7 @@ import ( ...@@ -7,8 +7,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"gitlab.com/tensorsecurity-rd/waf-console/internal/config" "gitlab.com/tensorsecurity-rd/waf-console/internal/config"
"gitlab.com/tensorsecurity-rd/waf-console/internal/middleware"
//"gitlab.com/tensorsecurity-rd/waf-console/internal/middleware"
"gitlab.com/tensorsecurity-rd/waf-console/internal/utils" "gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
"gorm.io/gorm" "gorm.io/gorm"
) )
...@@ -21,7 +20,7 @@ func SetRouters(db *gorm.DB, clusterClientManager *utils.ClusterClientManager, g ...@@ -21,7 +20,7 @@ func SetRouters(db *gorm.DB, clusterClientManager *utils.ClusterClientManager, g
log.Info().Msg("release mode") log.Info().Msg("release mode")
engine = ReleaseRouter() engine = ReleaseRouter()
engine.Use( engine.Use(
// middleware.AuthMiddleware(ssoUrl), middleware.AuthMiddleware(ssoUrl),
// middleware.RequestCostHandler(), // middleware.RequestCostHandler(),
// middleware.CustomLogger(), // middleware.CustomLogger(),
// middleware.CustomRecovery(), // middleware.CustomRecovery(),
...@@ -33,7 +32,7 @@ func SetRouters(db *gorm.DB, clusterClientManager *utils.ClusterClientManager, g ...@@ -33,7 +32,7 @@ func SetRouters(db *gorm.DB, clusterClientManager *utils.ClusterClientManager, g
log.Info().Msg("debug mode") log.Info().Msg("debug mode")
engine = gin.New() engine = gin.New()
engine.Use( engine.Use(
// middleware.AuthMiddleware(ssoUrl), middleware.AuthMiddleware(ssoUrl),
gin.Logger(), gin.Logger(),
// middleware.CustomRecovery(), // middleware.CustomRecovery(),
// middleware.CorsHandler(), // middleware.CorsHandler(),
......
...@@ -17,6 +17,11 @@ const ( ...@@ -17,6 +17,11 @@ const (
// AuthMiddleware validates the auth cookie with SSO service // AuthMiddleware validates the auth cookie with SSO service
func AuthMiddleware(ssoUrl string) gin.HandlerFunc { func AuthMiddleware(ssoUrl string) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
// skip ping
if c.Request.URL.Path != "/ping" {
c.Next()
return
}
// Get auth cookie // Get auth cookie
cookies := c.Request.Cookies() cookies := c.Request.Cookies()
if len(cookies) == 0 { if len(cookies) == 0 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment