Skip to content

Commit

Permalink
When a token is picked by refresh operation, increase its expire time…
Browse files Browse the repository at this point in the history
…. Add more error log.
  • Loading branch information
craftleon committed Nov 1, 2024
1 parent f5879ff commit ea7874e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ac/httpac.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,28 @@ func (ha *HttpAC) initRouter() {

func (ha *HttpAC) HandleHttpRefreshOperations(c *gin.Context, req *common.HttpRefreshRequest) {
if len(req.SrcIp) == 0 {
log.Error("empty source ip")
c.String(http.StatusOK, "{\"errMsg\": \"empty source ip\"}")
return
}

netIp := net.ParseIP(req.SrcIp)
if netIp == nil {
log.Error("invalid source ip")
c.String(http.StatusOK, "{\"errMsg\": \"invalid source ip\"}")
return
}

buf, err := base64.StdEncoding.DecodeString(req.Token)
if err != nil || len(buf) != 32 {
c.String(http.StatusOK, "{\"errMsg\": \"invalid token\"}")
log.Error("invalid token format")
c.String(http.StatusOK, "{\"errMsg\": \"invalid token format\"}")
return
}

entry := ha.ua.VerifyAccessToken(req.Token)
if entry == nil {
log.Error("token verification failed")
c.String(http.StatusOK, "{\"errMsg\": \"token verification failed\"}")
return
}
Expand All @@ -207,6 +211,7 @@ func (ha *HttpAC) HandleHttpRefreshOperations(c *gin.Context, req *common.HttpRe

_, err = ha.ua.HandleAccessControl(entry.User, entry.SrcAddrs, entry.DstAddrs, entry.OpenTime, nil)
if err != nil {
log.Error("HandleAccessControl failed: %v", err)
c.String(http.StatusOK, "{\"errMsg\": \"%s\"}", err)
return
}
Expand Down
1 change: 1 addition & 0 deletions ac/tokenstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (a *UdpAC) VerifyAccessToken(token string) *AccessEntry {
if found {
entry, found := tokenMap[token]
if found {
entry.ExpireTime = entry.ExpireTime.Add(time.Duration(entry.OpenTime) * time.Second)
return entry
}
}
Expand Down

0 comments on commit ea7874e

Please sign in to comment.