diff --git a/lib/core/conf/conf.go b/lib/core/conf/conf.go index c5e25863..7e22479a 100644 --- a/lib/core/conf/conf.go +++ b/lib/core/conf/conf.go @@ -25,7 +25,7 @@ func InitConfig(configFile string) { // Get 获取配置信息 // -// Get("framework.name") +// Get("server.port") func Get(key string) any { return v.Get(key) } diff --git a/src/framework/config/config.go b/src/framework/config/config.go index 8974d4c6..875acec5 100644 --- a/src/framework/config/config.go +++ b/src/framework/config/config.go @@ -142,7 +142,7 @@ func RunTime() time.Time { // Get 获取配置信息 // -// Get("framework.name") +// Get("server.port") func Get(key string) any { return viper.Get(key) } diff --git a/src/framework/config/config/config.default.yaml b/src/framework/config/config/config.default.yaml index d2238938..13b1fffc 100644 --- a/src/framework/config/config/config.default.yaml +++ b/src/framework/config/config/config.default.yaml @@ -1,8 +1,3 @@ -# 项目信息 -framework: - name: "OMC" - version: "2.2411.3" - # 应用服务配置 server: # 服务端口 @@ -181,6 +176,10 @@ aes: # 用户配置 user: + # 登录认证,默认打开 + loginAuth: true + # 接口加密,默认打开 + cryptoApi: true # 密码 password: # 密码最大错误次数 diff --git a/src/framework/middleware/crypto_api.go b/src/framework/middleware/crypto_api.go index bfb8f7a0..f802e8db 100644 --- a/src/framework/middleware/crypto_api.go +++ b/src/framework/middleware/crypto_api.go @@ -24,6 +24,19 @@ import ( // 请将中间件放在最前置,对请求优先处理 func CryptoApi(requestDecrypt, responseEncrypt bool) gin.HandlerFunc { return func(c *gin.Context) { + // 登录认证,默认打开 + enable := true + if v := config.Get("user.loginAuth"); v != nil { + enable = v.(bool) + } + if v := config.Get("user.cryptoApi"); v != nil && enable { + enable = v.(bool) + } + if !enable { + c.Next() + return + } + // 请求解密时对请求data注入 if requestDecrypt { method := c.Request.Method diff --git a/src/framework/middleware/pre_authorize.go b/src/framework/middleware/pre_authorize.go index 588ad292..f2f93d42 100644 --- a/src/framework/middleware/pre_authorize.go +++ b/src/framework/middleware/pre_authorize.go @@ -3,6 +3,7 @@ package middleware import ( "strings" + "be.ems/src/framework/config" AdminConstants "be.ems/src/framework/constants/admin" commonConstants "be.ems/src/framework/constants/common" "be.ems/src/framework/i18n" @@ -36,6 +37,21 @@ var URL_WHITE_LIST = []string{ // 同时匹配其中权限 "matchPerms": {"xxx"}, func PreAuthorize(options map[string][]string) gin.HandlerFunc { return func(c *gin.Context) { + // 登录认证,默认打开 + enable := true + if v := config.Get("user.loginAuth"); v != nil { + enable = v.(bool) + } + if !enable { + loginUser, _ := ctxUtils.LoginUser(c) + loginUser.UserID = "2" + loginUser.User.UserID = "2" + loginUser.User.UserName = "admin" + c.Set(commonConstants.CTX_LOGIN_USER, loginUser) + c.Next() + return + } + language := ctxUtils.AcceptLanguage(c) requestURI := c.Request.RequestURI diff --git a/src/modules/common/controller/index.go b/src/modules/common/controller/index.go index 020b5be6..b61ce81a 100644 --- a/src/modules/common/controller/index.go +++ b/src/modules/common/controller/index.go @@ -3,7 +3,7 @@ package controller import ( "fmt" - "be.ems/src/framework/config" + libGlobal "be.ems/lib/global" "be.ems/src/framework/vo/result" "github.com/gin-gonic/gin" @@ -21,8 +21,8 @@ type IndexController struct{} // // GET / func (s *IndexController) Handler(c *gin.Context) { - name := config.Get("framework.name").(string) - version := config.Get("framework.version").(string) + name := "OMC" + version := libGlobal.Version // str := "欢迎使用%s核心网管理平台,当前版本:%s,请通过前台地址访问。" str := "Welcome to the %s Core Network Management Platform, current version: %s, please access via the frontend address." c.JSON(200, result.OkMsg(fmt.Sprintf(str, name, version))) diff --git a/src/modules/common/service/commont.impl.go b/src/modules/common/service/commont.impl.go index 10ad3f8c..b84b4d49 100644 --- a/src/modules/common/service/commont.impl.go +++ b/src/modules/common/service/commont.impl.go @@ -30,7 +30,6 @@ func (s *CommontImpl) SystemConfigInfo() map[string]string { // 获取打包注入的全局变量信息 infoMap["version"] = global.Version infoMap["buildTime"] = global.BuildTime - infoMap["goVer"] = global.GoVer // 系统首次使用标记 launchInfo := machine.LaunchInfo if launchInfo != nil { @@ -42,6 +41,8 @@ func (s *CommontImpl) SystemConfigInfo() map[string]string { } else { infoMap[common.LAUNCH_BOOTLOADER] = "true" } + // 用户登录认证 + infoMap["loginAuth"] = fmt.Sprint(config.Get("user.loginAuth")) // 序列号 infoMap["serialNum"] = fmt.Sprint(config.Get("omc.sn")) // 获取LOGO类型