From d518180f3eff42b2fc7b8ab66a5bfa9d6e29f3f9 Mon Sep 17 00:00:00 2001 From: tbuchaillot Date: Fri, 11 Sep 2020 19:51:59 -0300 Subject: [PATCH 1/3] initializing session with mutexes --- gateway/api.go | 2 +- gateway/auth_manager.go | 5 ++--- gateway/mw_http_signature_validation.go | 3 ++- gateway/oauth_manager.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gateway/api.go b/gateway/api.go index 53da779b4f9..4543b675170 100644 --- a/gateway/api.go +++ b/gateway/api.go @@ -472,7 +472,7 @@ func handleGetDetail(sessionKey, apiID string, byHash bool) (interface{}, int) { sessionManager = spec.SessionManager } - var session user.SessionState + session := user.SessionState{Mutex:&sync.RWMutex{}} var ok bool session, ok = sessionManager.SessionDetail(sessionKey, byHash) diff --git a/gateway/auth_manager.go b/gateway/auth_manager.go index f28aff97d51..5af865e5e76 100644 --- a/gateway/auth_manager.go +++ b/gateway/auth_manager.go @@ -136,7 +136,7 @@ func (b *DefaultAuthorisationManager) Init(store storage.Handler) { // KeyAuthorised checks if key exists and can be read into a user.SessionState object func (b *DefaultAuthorisationManager) KeyAuthorised(keyName string) (user.SessionState, bool) { jsonKeyVal, err := b.store.GetKey(keyName) - var newSession user.SessionState + newSession := user.SessionState{Mutex:&sync.RWMutex{}} if err != nil { log.WithFields(logrus.Fields{ "prefix": "auth-mgr", @@ -280,8 +280,7 @@ func (b *DefaultSessionManager) RemoveSession(keyName string, hashed bool) bool func (b *DefaultSessionManager) SessionDetail(keyName string, hashed bool) (user.SessionState, bool) { var jsonKeyVal string var err error - var session user.SessionState - + session := user.SessionState{Mutex:&sync.RWMutex{}} // get session by key if hashed { jsonKeyVal, err = b.store.GetRawKey(b.store.GetKeyPrefix() + keyName) diff --git a/gateway/mw_http_signature_validation.go b/gateway/mw_http_signature_validation.go index f2da8b774d4..3ac3b69d07f 100644 --- a/gateway/mw_http_signature_validation.go +++ b/gateway/mw_http_signature_validation.go @@ -15,6 +15,7 @@ import ( "net/url" "strconv" "strings" + "sync" "text/scanner" "time" @@ -96,7 +97,7 @@ func (hm *HTTPSignatureValidationMiddleware) ProcessRequest(w http.ResponseWrite var secret string var rsaKey *rsa.PublicKey - var session user.SessionState + session := user.SessionState{Mutex:&sync.RWMutex{}} if strings.HasPrefix(fieldValues.Algorthm, "rsa") { var certificateId string diff --git a/gateway/oauth_manager.go b/gateway/oauth_manager.go index c20a9839492..f7a18a4be78 100644 --- a/gateway/oauth_manager.go +++ b/gateway/oauth_manager.go @@ -392,7 +392,7 @@ func (o *OAuthManager) HandleAccess(r *http.Request) *osin.Response { if ar := o.OsinServer.HandleAccessRequest(resp, r); ar != nil { - var session *user.SessionState + session := user.SessionState{Mutex:&sync.RWMutex{}} if ar.Type == osin.PASSWORD { username = r.Form.Get("username") password := r.Form.Get("password") From 67d43e928fce92dfe9ec78358d493d1b7457601c Mon Sep 17 00:00:00 2001 From: tbuchaillot Date: Fri, 11 Sep 2020 20:05:05 -0300 Subject: [PATCH 2/3] fix oauth session pointer --- gateway/oauth_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/oauth_manager.go b/gateway/oauth_manager.go index f7a18a4be78..4a67bef4db7 100644 --- a/gateway/oauth_manager.go +++ b/gateway/oauth_manager.go @@ -392,7 +392,7 @@ func (o *OAuthManager) HandleAccess(r *http.Request) *osin.Response { if ar := o.OsinServer.HandleAccessRequest(resp, r); ar != nil { - session := user.SessionState{Mutex:&sync.RWMutex{}} + session := &user.SessionState{Mutex:&sync.RWMutex{}} if ar.Type == osin.PASSWORD { username = r.Form.Get("username") password := r.Form.Get("password") From 41fe64c201dfe3f629d699d7465d022e259a4968 Mon Sep 17 00:00:00 2001 From: tbuchaillot Date: Fri, 11 Sep 2020 20:11:37 -0300 Subject: [PATCH 3/3] fmting --- gateway/api.go | 2 +- gateway/auth_manager.go | 4 ++-- gateway/mw_http_signature_validation.go | 2 +- gateway/oauth_manager.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gateway/api.go b/gateway/api.go index 4543b675170..01174581f74 100644 --- a/gateway/api.go +++ b/gateway/api.go @@ -472,7 +472,7 @@ func handleGetDetail(sessionKey, apiID string, byHash bool) (interface{}, int) { sessionManager = spec.SessionManager } - session := user.SessionState{Mutex:&sync.RWMutex{}} + session := user.SessionState{Mutex: &sync.RWMutex{}} var ok bool session, ok = sessionManager.SessionDetail(sessionKey, byHash) diff --git a/gateway/auth_manager.go b/gateway/auth_manager.go index 5af865e5e76..73f55c6c386 100644 --- a/gateway/auth_manager.go +++ b/gateway/auth_manager.go @@ -136,7 +136,7 @@ func (b *DefaultAuthorisationManager) Init(store storage.Handler) { // KeyAuthorised checks if key exists and can be read into a user.SessionState object func (b *DefaultAuthorisationManager) KeyAuthorised(keyName string) (user.SessionState, bool) { jsonKeyVal, err := b.store.GetKey(keyName) - newSession := user.SessionState{Mutex:&sync.RWMutex{}} + newSession := user.SessionState{Mutex: &sync.RWMutex{}} if err != nil { log.WithFields(logrus.Fields{ "prefix": "auth-mgr", @@ -280,7 +280,7 @@ func (b *DefaultSessionManager) RemoveSession(keyName string, hashed bool) bool func (b *DefaultSessionManager) SessionDetail(keyName string, hashed bool) (user.SessionState, bool) { var jsonKeyVal string var err error - session := user.SessionState{Mutex:&sync.RWMutex{}} + session := user.SessionState{Mutex: &sync.RWMutex{}} // get session by key if hashed { jsonKeyVal, err = b.store.GetRawKey(b.store.GetKeyPrefix() + keyName) diff --git a/gateway/mw_http_signature_validation.go b/gateway/mw_http_signature_validation.go index 3ac3b69d07f..0c893719aba 100644 --- a/gateway/mw_http_signature_validation.go +++ b/gateway/mw_http_signature_validation.go @@ -97,7 +97,7 @@ func (hm *HTTPSignatureValidationMiddleware) ProcessRequest(w http.ResponseWrite var secret string var rsaKey *rsa.PublicKey - session := user.SessionState{Mutex:&sync.RWMutex{}} + session := user.SessionState{Mutex: &sync.RWMutex{}} if strings.HasPrefix(fieldValues.Algorthm, "rsa") { var certificateId string diff --git a/gateway/oauth_manager.go b/gateway/oauth_manager.go index 4a67bef4db7..424dc5cc2ad 100644 --- a/gateway/oauth_manager.go +++ b/gateway/oauth_manager.go @@ -392,7 +392,7 @@ func (o *OAuthManager) HandleAccess(r *http.Request) *osin.Response { if ar := o.OsinServer.HandleAccessRequest(resp, r); ar != nil { - session := &user.SessionState{Mutex:&sync.RWMutex{}} + session := &user.SessionState{Mutex: &sync.RWMutex{}} if ar.Type == osin.PASSWORD { username = r.Form.Get("username") password := r.Form.Get("password")