mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:07:31 +00:00

# Which Problems Are Solved The commands for the resource based v2beta AuthorizationService API are added. Authorizations, previously knows as user grants, give a user in a specific organization and project context roles. The project can be owned or granted. The given roles can be used to restrict access within the projects applications. The commands for the resource based v2beta InteralPermissionService API are added. Administrators, previously knows as memberships, give a user in a specific organization and project context roles. The project can be owned or granted. The give roles give the user permissions to manage different resources in Zitadel. API definitions from https://github.com/zitadel/zitadel/issues/9165 are implemented. Contains endpoints for user metadata. # How the Problems Are Solved ### New Methods - CreateAuthorization - UpdateAuthorization - DeleteAuthorization - ActivateAuthorization - DeactivateAuthorization - ListAuthorizations - CreateAdministrator - UpdateAdministrator - DeleteAdministrator - ListAdministrators - SetUserMetadata to set metadata on a user - DeleteUserMetadata to delete metadata on a user - ListUserMetadata to query for metadata of a user ## Deprecated Methods ### v1.ManagementService - GetUserGrantByID - ListUserGrants - AddUserGrant - UpdateUserGrant - DeactivateUserGrant - ReactivateUserGrant - RemoveUserGrant - BulkRemoveUserGrant ### v1.AuthService - ListMyUserGrants - ListMyProjectPermissions # Additional Changes - Permission checks for metadata functionality on query and command side - correct existence checks for resources, for example you can only be an administrator on an existing project - combined all member tables to singular query for the administrators - add permission checks for command an query side functionality - combined functions on command side where necessary for easier maintainability # Additional Context Closes #9165 --------- Co-authored-by: Elio Bischof <elio@zitadel.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Livio Spring <livio.a@gmail.com>
140 lines
4.3 KiB
Go
140 lines
4.3 KiB
Go
package eventsourcing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/auth/repository/eventsourcing/eventstore"
|
|
auth_handler "github.com/zitadel/zitadel/internal/auth/repository/eventsourcing/handler"
|
|
auth_view "github.com/zitadel/zitadel/internal/auth/repository/eventsourcing/view"
|
|
"github.com/zitadel/zitadel/internal/auth_request/repository/cache"
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
sd "github.com/zitadel/zitadel/internal/config/systemdefaults"
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
eventstore2 "github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/id"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
)
|
|
|
|
type Config struct {
|
|
SearchLimit uint64
|
|
Spooler auth_handler.Config
|
|
AmountOfCachedAuthRequests uint16
|
|
}
|
|
|
|
type EsRepository struct {
|
|
eventstore.UserRepo
|
|
eventstore.AuthRequestRepo
|
|
eventstore.TokenRepo
|
|
eventstore.RefreshTokenRepo
|
|
eventstore.UserSessionRepo
|
|
eventstore.OrgRepository
|
|
}
|
|
|
|
func Start(ctx context.Context, conf Config, systemDefaults sd.SystemDefaults, command *command.Commands, queries *query.Queries, dbClient *database.DB, esV2 *eventstore2.Eventstore, oidcEncryption crypto.EncryptionAlgorithm, userEncryption crypto.EncryptionAlgorithm) (*EsRepository, error) {
|
|
view, err := auth_view.StartView(dbClient, oidcEncryption, queries, esV2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
auth_handler.Register(ctx, conf.Spooler, view, queries)
|
|
auth_handler.Start(ctx)
|
|
|
|
authReq := cache.Start(dbClient, conf.AmountOfCachedAuthRequests)
|
|
|
|
userRepo := eventstore.UserRepo{
|
|
SearchLimit: conf.SearchLimit,
|
|
Eventstore: esV2,
|
|
View: view,
|
|
Query: queries,
|
|
SystemDefaults: systemDefaults,
|
|
}
|
|
//TODO: remove as soon as possible
|
|
queryView := queryViewWrapper{
|
|
queries,
|
|
view,
|
|
}
|
|
return &EsRepository{
|
|
userRepo,
|
|
eventstore.AuthRequestRepo{
|
|
PrivacyPolicyProvider: queries,
|
|
LabelPolicyProvider: queries,
|
|
Command: command,
|
|
Query: queries,
|
|
OrgViewProvider: queries,
|
|
AuthRequests: authReq,
|
|
View: view,
|
|
UserCodeAlg: userEncryption,
|
|
UserSessionViewProvider: view,
|
|
UserViewProvider: view,
|
|
UserCommandProvider: command,
|
|
UserEventProvider: &userRepo,
|
|
IDPProviderViewProvider: queries,
|
|
IDPUserLinksProvider: queries,
|
|
LockoutPolicyViewProvider: queries,
|
|
LoginPolicyViewProvider: queries,
|
|
PasswordAgePolicyProvider: queries,
|
|
UserGrantProvider: queryView,
|
|
ProjectProvider: queryView,
|
|
ApplicationProvider: queries,
|
|
CustomTextProvider: queries,
|
|
PasswordReset: command,
|
|
PasswordChecker: command,
|
|
IdGenerator: id.SonyFlakeGenerator(),
|
|
},
|
|
eventstore.TokenRepo{
|
|
View: view,
|
|
Eventstore: esV2,
|
|
},
|
|
eventstore.RefreshTokenRepo{
|
|
View: view,
|
|
Eventstore: esV2,
|
|
SearchLimit: conf.SearchLimit,
|
|
KeyAlgorithm: oidcEncryption,
|
|
},
|
|
eventstore.UserSessionRepo{
|
|
View: view,
|
|
},
|
|
eventstore.OrgRepository{
|
|
SearchLimit: conf.SearchLimit,
|
|
View: view,
|
|
SystemDefaults: systemDefaults,
|
|
Eventstore: esV2,
|
|
Query: queries,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
type queryViewWrapper struct {
|
|
*query.Queries
|
|
*auth_view.View
|
|
}
|
|
|
|
func (q queryViewWrapper) UserGrantsByProjectAndUserID(ctx context.Context, projectID, userID string) ([]*query.UserGrant, error) {
|
|
userGrantProjectID, err := query.NewUserGrantProjectIDSearchQuery(projectID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
userGrantUserID, err := query.NewUserGrantUserIDSearchQuery(userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
activeQuery, err := query.NewUserGrantStateQuery(domain.UserGrantStateActive)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
queries := &query.UserGrantsQueries{Queries: []query.SearchQuery{userGrantUserID, userGrantProjectID, activeQuery}}
|
|
grants, err := q.Queries.UserGrants(ctx, queries, true, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return grants.UserGrants, nil
|
|
}
|
|
func (repo *EsRepository) Health(ctx context.Context) error {
|
|
if err := repo.UserRepo.Health(ctx); err != nil {
|
|
return err
|
|
}
|
|
return repo.AuthRequestRepo.Health(ctx)
|
|
}
|