del: 移除旧登录会话生成 token和中间件方式设置请求头
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"be.ems/restagent/config"
|
||||
"be.ems/src"
|
||||
"be.ems/src/framework/middleware"
|
||||
libSession "be.ems/src/lib_features/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/net/http2"
|
||||
"golang.org/x/net/http2/h2c"
|
||||
@@ -235,11 +234,9 @@ func main() {
|
||||
// 默认路由组
|
||||
defaultUriGroup := app.Group(config.DefaultUriPrefix)
|
||||
defaultUriGroup.Use(middleware.PreAuthorize(nil))
|
||||
defaultUriGroup.Use(libSession.SessionHeader())
|
||||
defaultUriGroup.Any("/*any", gin.WrapH(routes.NewRouter()))
|
||||
// 可配置前缀路由组
|
||||
uriGroup := app.Group(config.UriPrefix)
|
||||
uriGroup.Use(libSession.SessionHeader())
|
||||
uriGroup.Any("/*any", gin.WrapH(routes.NewRouter()))
|
||||
// AMF上报的UE事件, 无前缀,暂时特殊处理
|
||||
app.POST(event.UriUEEvent, event.PostUEEventFromAMF)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package libfeatures
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"be.ems/lib/dborm"
|
||||
"be.ems/lib/oauth"
|
||||
libConfig "be.ems/restagent/config"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/redis"
|
||||
)
|
||||
|
||||
// SessionToken 设置登录会话-兼容旧登录方式
|
||||
func SessionToken(username, sourceAddr string) bool {
|
||||
// token, _ := redis.Get("", "session_token")
|
||||
// if token != "" {
|
||||
// se, err := dborm.XormUpdateSessionShakeTime(token)
|
||||
// if se.AccountId != username || err != nil {
|
||||
// // 过期时间单位秒 配置1800是半小时
|
||||
// expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
|
||||
// redis.SetByExpire("", "session_token", token, expireTime)
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// 不管原先的登录情况,直接插入写入覆盖redis中session
|
||||
//
|
||||
token := oauth.GenRandToken("omc") // Generate new token to session ID
|
||||
affected, err := dborm.XormInsertSession(username, sourceAddr, token, libConfig.GetExpiresFromConfig(), libConfig.GetYamlConfig().Auth.Session)
|
||||
if err != nil {
|
||||
logger.Errorf("SessionToken XormInsertSession err %v", err)
|
||||
}
|
||||
if affected >= 1 {
|
||||
// 过期时间单位秒 配置1800是半小时
|
||||
expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
|
||||
redis.SetByExpire("", "session_token", token, expireTime)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
# 外层 lib 和 features 粘合层
|
||||
|
||||
- config.go 配置合并: restagent.yaml 文件内容,主要是数据库配置
|
||||
- account.go 登录会话生成 token
|
||||
- session.go 中间件方式设置请求头 token 值
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
libConfig "be.ems/restagent/config"
|
||||
"be.ems/src/framework/redis"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// SessionHeader 旧登录方式token头
|
||||
func SessionHeader() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 读取登录生成的会话token
|
||||
token, _ := redis.Get("", "session_token")
|
||||
if token != "" {
|
||||
// 过期时间单位秒 配置1800是半小时
|
||||
expireTime := time.Duration(int64(libConfig.GetExpiresFromConfig())) * time.Second
|
||||
redis.SetByExpire("", "session_token", token, expireTime)
|
||||
c.Request.Header.Set("Accesstoken", token)
|
||||
}
|
||||
|
||||
// Accesstoken: omc-ce4d0a86-8515-ad51-3249-4913c95f8e34
|
||||
// 调用下一个处理程序
|
||||
c.Next()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
tokenUtils "be.ems/src/framework/utils/token"
|
||||
"be.ems/src/framework/vo"
|
||||
"be.ems/src/framework/vo/result"
|
||||
libAccount "be.ems/src/lib_features/account"
|
||||
commonModel "be.ems/src/modules/common/model"
|
||||
commonService "be.ems/src/modules/common/service"
|
||||
systemService "be.ems/src/modules/system/service"
|
||||
@@ -83,9 +82,6 @@ func (s *AccountController) Login(c *gin.Context) {
|
||||
)
|
||||
}
|
||||
|
||||
// 设置登录会话-兼容旧登录方式
|
||||
libAccount.SessionToken(loginBody.Username, ipaddr)
|
||||
|
||||
c.JSON(200, result.OkData(map[string]any{
|
||||
tokenConstants.RESPONSE_FIELD: tokenStr,
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user