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.
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 )
}