-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
177 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package backend | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" | ||
cs3 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" | ||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" | ||
settings "github.com/owncloud/ocis/settings/pkg/proto/v0" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// UserBackend allows the proxy to retrieve users from different user-backends (accounts-service, CS3) | ||
type UserBackend interface { | ||
GetUserByClaims(ctx context.Context, claim, value string, withRoles bool) (*cs3.User, error) | ||
Authenticate(ctx context.Context, username string, password string) (*cs3.User, error) | ||
GetUserGroups(ctx context.Context, userID string) | ||
} | ||
|
||
// RevaAuthenticator helper interface to mock auth-method from reva gateway-client. | ||
type RevaAuthenticator interface { | ||
Authenticate(ctx context.Context, in *gateway.AuthenticateRequest, opts ...grpc.CallOption) (*gateway.AuthenticateResponse, error) | ||
} | ||
|
||
func loadRolesIDs(ctx context.Context, opaqueUserID string, rs settings.RoleService) ([]string, error) { | ||
req := &settings.ListRoleAssignmentsRequest{AccountUuid: opaqueUserID} | ||
assignmentResponse, err := rs.ListRoleAssignments(ctx, req) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
roleIDs := make([]string, 0) | ||
|
||
for _, assignment := range assignmentResponse.Assignments { | ||
roleIDs = append(roleIDs, assignment.RoleId) | ||
} | ||
|
||
return roleIDs, nil | ||
} | ||
|
||
func encodeRoleIDs(roleIDs []string) (*types.OpaqueEntry, error) { | ||
roleIDsJSON, err := json.Marshal(roleIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.OpaqueEntry{ | ||
Decoder: "json", | ||
Value: roleIDsJSON, | ||
}, nil | ||
|
||
} |
Oops, something went wrong.