mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-21 03:50:44 -06:00
@@ -133,6 +133,10 @@ func CreateUserModelFromCS3(u *cs3user.User) *libregraph.User {
|
|||||||
OnPremisesSamAccountName: u.GetUsername(),
|
OnPremisesSamAccountName: u.GetUsername(),
|
||||||
Id: &u.GetId().OpaqueId,
|
Id: &u.GetId().OpaqueId,
|
||||||
}
|
}
|
||||||
|
if u.GetId().GetType() == cs3user.UserType_USER_TYPE_FEDERATED {
|
||||||
|
ocmUserId := u.GetId().GetOpaqueId() + "@" + u.GetId().GetIdp()
|
||||||
|
user.Id = &ocmUserId
|
||||||
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
services/graph/pkg/identity/cache/cache.go
vendored
24
services/graph/pkg/identity/cache/cache.go
vendored
@@ -2,6 +2,8 @@ package cache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||||
@@ -133,6 +135,20 @@ func (cache IdentityCache) GetAcceptedUser(ctx context.Context, userid string) (
|
|||||||
return *identity.CreateUserModelFromCS3(u), nil
|
return *identity.CreateUserModelFromCS3(u), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getIDAndMeshProvider(user string) (id, provider string, err error) {
|
||||||
|
last := strings.LastIndex(user, "@")
|
||||||
|
if last == -1 {
|
||||||
|
return "", "", errors.New("not in the form <id>@<provider>")
|
||||||
|
}
|
||||||
|
if len(user[:last]) == 0 {
|
||||||
|
return "", "", errors.New("empty id")
|
||||||
|
}
|
||||||
|
if len(user[last+1:]) == 0 {
|
||||||
|
return "", "", errors.New("empty provider")
|
||||||
|
}
|
||||||
|
return user[:last], user[last+1:], nil
|
||||||
|
}
|
||||||
|
|
||||||
func (cache IdentityCache) GetAcceptedCS3User(ctx context.Context, userid string) (*cs3User.User, error) {
|
func (cache IdentityCache) GetAcceptedCS3User(ctx context.Context, userid string) (*cs3User.User, error) {
|
||||||
var user *cs3user.User
|
var user *cs3user.User
|
||||||
if item := cache.users.Get(userid); item == nil {
|
if item := cache.users.Get(userid); item == nil {
|
||||||
@@ -140,8 +156,14 @@ func (cache IdentityCache) GetAcceptedCS3User(ctx context.Context, userid string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorcode.New(errorcode.GeneralException, err.Error())
|
return nil, errorcode.New(errorcode.GeneralException, err.Error())
|
||||||
}
|
}
|
||||||
|
id, provider, err := getIDAndMeshProvider(userid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errorcode.New(errorcode.InvalidRequest, err.Error())
|
||||||
|
}
|
||||||
cs3UserID := &cs3User.UserId{
|
cs3UserID := &cs3User.UserId{
|
||||||
OpaqueId: userid,
|
Idp: provider,
|
||||||
|
OpaqueId: id,
|
||||||
|
Type: cs3User.UserType_USER_TYPE_FEDERATED,
|
||||||
}
|
}
|
||||||
user, err = revautils.GetAcceptedUserWithContext(ctx, cs3UserID, gatewayClient)
|
user, err = revautils.GetAcceptedUserWithContext(ctx, cs3UserID, gatewayClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -106,7 +107,8 @@ func userIdToIdentity(ctx context.Context, cache cache.IdentityCache, tennantId,
|
|||||||
|
|
||||||
// federatedIdToIdentity looks the user for the supplied id using the cache and returns it
|
// federatedIdToIdentity looks the user for the supplied id using the cache and returns it
|
||||||
// as a libregraph.Identity
|
// as a libregraph.Identity
|
||||||
func federatedIdToIdentity(ctx context.Context, cache cache.IdentityCache, userID string) (libregraph.Identity, error) {
|
func federatedIdToIdentity(ctx context.Context, cache cache.IdentityCache, cs3UserID *cs3User.UserId) (libregraph.Identity, error) {
|
||||||
|
userID := fmt.Sprintf("%s@%s", cs3UserID.GetOpaqueId(), cs3UserID.GetIdp())
|
||||||
identity := libregraph.Identity{
|
identity := libregraph.Identity{
|
||||||
Id: libregraph.PtrString(userID),
|
Id: libregraph.PtrString(userID),
|
||||||
LibreGraphUserType: libregraph.PtrString("Federated"),
|
LibreGraphUserType: libregraph.PtrString("Federated"),
|
||||||
@@ -123,7 +125,7 @@ func federatedIdToIdentity(ctx context.Context, cache cache.IdentityCache, userI
|
|||||||
// as a libregraph.Identity. Skips the user lookup if the id type is USER_TYPE_SPACE_OWNER
|
// as a libregraph.Identity. Skips the user lookup if the id type is USER_TYPE_SPACE_OWNER
|
||||||
func cs3UserIdToIdentity(ctx context.Context, cache cache.IdentityCache, cs3UserID *cs3User.UserId) (libregraph.Identity, error) {
|
func cs3UserIdToIdentity(ctx context.Context, cache cache.IdentityCache, cs3UserID *cs3User.UserId) (libregraph.Identity, error) {
|
||||||
if cs3UserID.GetType() == cs3User.UserType_USER_TYPE_FEDERATED {
|
if cs3UserID.GetType() == cs3User.UserType_USER_TYPE_FEDERATED {
|
||||||
return federatedIdToIdentity(ctx, cache, cs3UserID.GetOpaqueId())
|
return federatedIdToIdentity(ctx, cache, cs3UserID)
|
||||||
}
|
}
|
||||||
if cs3UserID.GetType() != cs3User.UserType_USER_TYPE_SPACE_OWNER {
|
if cs3UserID.GetType() != cs3User.UserType_USER_TYPE_SPACE_OWNER {
|
||||||
return userIdToIdentity(ctx, cache, cs3UserID.GetTenantId(), cs3UserID.GetOpaqueId())
|
return userIdToIdentity(ctx, cache, cs3UserID.GetTenantId(), cs3UserID.GetOpaqueId())
|
||||||
|
|||||||
Reference in New Issue
Block a user