You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package SsoUtil
import (
"dsSso/Const/DefaultConst"
"dsSso/Const/ErrorConst"
"dsSso/Utils/AesUtil"
"dsSso/Utils/ConfigUtil"
"dsSso/Utils/LogUtil"
"encoding/base64"
"github.com/gin-gonic/gin"
"strings"
)
/**
功能解析SessionId的内容换算出设备身份和人员ID
作者:黄海
时间2020-02-25
*/
func AnalyzeSessionId(encodeString string) (string, string, string) {
var identityId = DefaultConst.IdentityId
var personId = DefaultConst.PersonId
var deviceId = DefaultConst.DeviceId
//解base64
sessionId, err := base64.RawURLEncoding.DecodeString(encodeString)
if err != nil {
return identityId, personId, deviceId
}
//解密
r, err := AesUtil.Decrypt(string(sessionId))
if err != nil {
LogUtil.Error(ErrorConst.AnalyzeCookieError, "解析cookie失败怀疑有人恶意攻击!")
return identityId, personId, deviceId
} else {
s := r
array := strings.Split(s, "_")
if len(array) > 1 {
identityId = array[0]
personId = array[1]
deviceId = array[2]
}
return identityId, personId, deviceId
}
}
/**
功能读取统一认证的cookie值
作者:黄海
时间2020-02-22
*/
func ReadSsoCookie(c *gin.Context) string {
cookie, e := c.Request.Cookie(ConfigUtil.AccessToken)
if e == nil {
return cookie.Value
} else {
return ""
}
}
/**
功能删除统一认证的cookie信息
作者:黄海
时间2020-02-22
*/
func DeleteSsoCookie(c *gin.Context) {
c.SetCookie(ConfigUtil.AccessToken, "", -1, "/", "", false, true)
}