Skip to content

Commit ea7874e

Browse files
committed
When a token is picked by refresh operation, increase its expire time. Add more error log.
1 parent f5879ff commit ea7874e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

ac/httpac.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,28 @@ func (ha *HttpAC) initRouter() {
166166

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

173174
netIp := net.ParseIP(req.SrcIp)
174175
if netIp == nil {
176+
log.Error("invalid source ip")
175177
c.String(http.StatusOK, "{\"errMsg\": \"invalid source ip\"}")
176178
return
177179
}
178180

179181
buf, err := base64.StdEncoding.DecodeString(req.Token)
180182
if err != nil || len(buf) != 32 {
181-
c.String(http.StatusOK, "{\"errMsg\": \"invalid token\"}")
183+
log.Error("invalid token format")
184+
c.String(http.StatusOK, "{\"errMsg\": \"invalid token format\"}")
182185
return
183186
}
184187

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

208212
_, err = ha.ua.HandleAccessControl(entry.User, entry.SrcAddrs, entry.DstAddrs, entry.OpenTime, nil)
209213
if err != nil {
214+
log.Error("HandleAccessControl failed: %v", err)
210215
c.String(http.StatusOK, "{\"errMsg\": \"%s\"}", err)
211216
return
212217
}

ac/tokenstore.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (a *UdpAC) VerifyAccessToken(token string) *AccessEntry {
5858
if found {
5959
entry, found := tokenMap[token]
6060
if found {
61+
entry.ExpireTime = entry.ExpireTime.Add(time.Duration(entry.OpenTime) * time.Second)
6162
return entry
6263
}
6364
}

0 commit comments

Comments
 (0)