update at 2023/08/14
This commit is contained in:
@@ -9,13 +9,17 @@ import (
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
|
||||
"ems.agt/lib/dborm"
|
||||
"ems.agt/lib/log"
|
||||
"ems.agt/lib/oauth"
|
||||
"ems.agt/lib/services"
|
||||
"ems.agt/restagent/config"
|
||||
)
|
||||
|
||||
var (
|
||||
UriAAAASSO = config.UriPrefix + "/aaaa/{apiVersion}/security/sso" // for external
|
||||
UriAAAASSO = config.DefaultUriPrefix + "/aaaa/{apiVersion}/security/sso" // for 4A external
|
||||
|
||||
CustomUriAAAASSO = config.UriPrefix + "/aaaa/{apiVersion}/security/sso" // for 4A external
|
||||
)
|
||||
|
||||
var client = resty.New()
|
||||
@@ -64,17 +68,9 @@ func GetSSOFromAAAA(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
log.Debugf("r.RemoteAddr:%s r.Host: %s", r.RemoteAddr, r.Host)
|
||||
|
||||
var aaaaIp, omcIp string
|
||||
addr := strings.Split(r.RemoteAddr, ":")
|
||||
if len(addr) > 0 {
|
||||
//aaaaIp := r.RemoteAddr[:strings.Index(r.Host, ":")]
|
||||
aaaaIp = addr[0]
|
||||
}
|
||||
addr = strings.Split(r.Host, ":")
|
||||
if len(addr) > 0 {
|
||||
//omcIp := r.Host[:strings.Index(r.Host, ":")]
|
||||
omcIp = addr[0]
|
||||
}
|
||||
aaaaIp := r.RemoteAddr[:strings.Index(r.RemoteAddr, ":")]
|
||||
omcIp := r.Host[:strings.Index(r.Host, ":")]
|
||||
|
||||
log.Debugf("aaaaIp=%s omcIp=%s", aaaaIp, omcIp)
|
||||
requestURI2NF := fmt.Sprintf("http://%s:8080/qryUserByTicket", aaaaIp)
|
||||
|
||||
@@ -107,11 +103,35 @@ func GetSSOFromAAAA(w http.ResponseWriter, r *http.Request) {
|
||||
if len(ssoResult.SSO.Account) != 0 {
|
||||
accid = ssoResult.SSO.Account[0].Accid
|
||||
}
|
||||
redirectUrl := fmt.Sprintf("http://%s:8888/home.html?user=%s", omcIp, accid)
|
||||
services.ResponseRedirect(w, redirectUrl)
|
||||
return
|
||||
|
||||
log.Debug("accid:", accid)
|
||||
exist, err := dborm.XormIsExistUser(accid)
|
||||
if err != nil {
|
||||
services.ResponseInternalServerError500ProcessError(w, err)
|
||||
return
|
||||
}
|
||||
token := oauth.GenRandToken() // Generate new token to session ID
|
||||
affected, err := dborm.XormInsertSession(accid, r.RemoteAddr, token,
|
||||
config.GetExpiresFromConfig(), config.GetYamlConfig().Auth.Session)
|
||||
if err != nil {
|
||||
log.Error("Failed to XormInsertSession:", err)
|
||||
if affected == -1 {
|
||||
services.ResponseForbidden403MultiLoginNotAllowed(w)
|
||||
} else {
|
||||
services.ResponseBadRequest400IncorrectLogin(w)
|
||||
}
|
||||
return
|
||||
}
|
||||
if exist == true {
|
||||
redirectUrl := fmt.Sprintf("http://%s:8888/home.html?user=%s&token=%s", omcIp, accid, token)
|
||||
services.ResponseRedirect(w, redirectUrl, accid, token)
|
||||
return
|
||||
} else {
|
||||
services.ResponseBadRequest400IncorrectLogin(w)
|
||||
return
|
||||
}
|
||||
default:
|
||||
services.ResponseNotFound404UriNotExist(w, r)
|
||||
services.ResponseForbidden403NotPermission(w)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user