From 09ecfd08ee1958df252169edb90c44dd8877e271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 17 Jun 2020 15:33:42 +0200 Subject: [PATCH] cache account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- pkg/middleware/account_uuid.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/middleware/account_uuid.go b/pkg/middleware/account_uuid.go index 67cf29119..c3d68fcfb 100644 --- a/pkg/middleware/account_uuid.go +++ b/pkg/middleware/account_uuid.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "net/http" - "strings" revauser "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" "github.com/cs3org/reva/pkg/token/manager/jwt" @@ -78,7 +77,7 @@ func AccountUUID(opts ...AccountMiddlewareOption) func(next http.Handler) http.H // TODO allow lookup by username? // TODO allow lookup by custom claim, eg an id - var uuid string + var account *acc.Account entry, err := svcCache.Get(AccountsKey, claims.Email) if err != nil { l.Debug().Msgf("No cache entry for %v", claims.Email) @@ -105,31 +104,32 @@ func AccountUUID(opts ...AccountMiddlewareOption) func(next http.Handler) http.H return } - err = svcCache.Set(AccountsKey, claims.Email, resp.Accounts[0].Id) + err = svcCache.Set(AccountsKey, claims.Email, *resp.Accounts[0]) if err != nil { l.Err(err).Str("email", claims.Email).Msgf("Could not cache user") w.WriteHeader(http.StatusInternalServerError) return } - uuid = resp.Accounts[0].Id + account = resp.Accounts[0] } else { - uuid, ok = entry.V.(string) + a, ok := entry.V.(acc.Account) // TODO how can we directly point to the cached account? if !ok { w.WriteHeader(http.StatusInternalServerError) return } + account = &a } - l.Debug().Interface("claims", claims).Interface("uuid", uuid).Msgf("Associated claims with uuid") + l.Debug().Interface("claims", claims).Interface("account", account).Msgf("Associated claims with uuid") token, err := tokenManager.MintToken(r.Context(), &revauser.User{ Id: &revauser.UserId{ - OpaqueId: uuid, + OpaqueId: account.Id, }, - Username: strings.ToLower(claims.Name), - DisplayName: claims.Name, - Mail: claims.Email, - MailVerified: claims.EmailVerified, + Username: account.PreferredName, + DisplayName: account.DisplayName, + Mail: account.Mail, + MailVerified: account.ExternalUserState == "" || account.ExternalUserState == "Accepted", // TODO groups })