Documentation
¶
Overview ¶
Package scim implements SCIM 2.0 provisioning (RFC-009): per-tenant bearer tokens and the User provisioning that maps SCIM operations onto OpenCTEM users + tenant memberships.
Index ¶
- Variables
- type GroupInput
- type GroupMembershipReader
- type GroupService
- func (s *GroupService) Create(ctx context.Context, tenantID shared.ID, in GroupInput) (*scimgroup.ScimGroup, error)
- func (s *GroupService) Delete(ctx context.Context, tenantID, id shared.ID) error
- func (s *GroupService) Get(ctx context.Context, tenantID, id shared.ID) (*scimgroup.ScimGroup, error)
- func (s *GroupService) GetRoleMappings(ctx context.Context, tenantID shared.ID) (map[string]string, error)
- func (s *GroupService) List(ctx context.Context, tenantID shared.ID) ([]*scimgroup.ScimGroup, error)
- func (s *GroupService) PatchMembers(ctx context.Context, tenantID, id shared.ID, add, remove []shared.ID) (*scimgroup.ScimGroup, error)
- func (s *GroupService) Replace(ctx context.Context, tenantID, id shared.ID, in GroupInput) (*scimgroup.ScimGroup, error)
- func (s *GroupService) ReplaceMembers(ctx context.Context, tenantID, id shared.ID, memberIDs []shared.ID) (*scimgroup.ScimGroup, error)
- func (s *GroupService) SetRoleMappings(ctx context.Context, tenantID shared.ID, mappings map[string]string) error
- type MembershipManager
- type MembershipReader
- type MintResult
- type ProvisionInput
- type ProvisioningService
- func (s *ProvisioningService) CreateOrActivate(ctx context.Context, tenantID shared.ID, in ProvisionInput) (ScimUser, bool, error)
- func (s *ProvisioningService) Get(ctx context.Context, tenantID, userID shared.ID) (ScimUser, error)
- func (s *ProvisioningService) List(ctx context.Context, tenantID shared.ID, filterEmail string, ...) ([]ScimUser, int, error)
- func (s *ProvisioningService) SetActive(ctx context.Context, tenantID, userID shared.ID, active bool) (ScimUser, error)
- type RoleManager
- type ScimUser
- type TokenService
- func (s *TokenService) Authenticate(ctx context.Context, plaintext string) (*scimtoken.ScimToken, error)
- func (s *TokenService) List(ctx context.Context, tenantID shared.ID) ([]*scimtoken.ScimToken, error)
- func (s *TokenService) Mint(ctx context.Context, tenantID shared.ID, name string, createdBy *shared.ID) (*MintResult, error)
- func (s *TokenService) Revoke(ctx context.Context, tenantID, id shared.ID) error
- type UserStore
Constants ¶
This section is empty.
Variables ¶
var ErrUserNotInTenant = fmt.Errorf("%w: user is not provisioned in this tenant", shared.ErrNotFound)
ErrUserNotInTenant is returned (wrapping ErrNotFound → SCIM 404) when a SCIM id is not a member of the requesting tenant.
Functions ¶
This section is empty.
Types ¶
type GroupInput ¶
GroupInput is a normalised SCIM Group create/replace request.
type GroupMembershipReader ¶
type GroupMembershipReader interface {
GetMembership(ctx context.Context, userID, tenantID shared.ID) (*tenantdom.Membership, error)
}
GroupMembershipReader resolves a user's tenant membership (tenant.Repository satisfies it via GetMembership).
type GroupService ¶
type GroupService struct {
// contains filtered or unexported fields
}
GroupService implements SCIM Group provisioning. Group membership drives a user's tenant role: a group whose displayName (case-insensitive) is a tenant role name (admin/member/viewer) maps its members to that role. A user's effective role is the highest-privilege role-group they belong to; when they belong to none, it defaults to member. 'owner' is never assignable via SCIM.
func NewGroupService ¶
func NewGroupService(groups scimgroup.Repository, members GroupMembershipReader, roles RoleManager, log *logger.Logger) *GroupService
NewGroupService wires the service.
func (*GroupService) Create ¶
func (s *GroupService) Create(ctx context.Context, tenantID shared.ID, in GroupInput) (*scimgroup.ScimGroup, error)
Create provisions a group and reconciles the role of every member.
func (*GroupService) Get ¶
func (s *GroupService) Get(ctx context.Context, tenantID, id shared.ID) (*scimgroup.ScimGroup, error)
Get returns a group scoped to the tenant.
func (*GroupService) GetRoleMappings ¶
func (s *GroupService) GetRoleMappings(ctx context.Context, tenantID shared.ID) (map[string]string, error)
GetRoleMappings returns the tenant's configured group → role overrides.
func (*GroupService) List ¶
func (s *GroupService) List(ctx context.Context, tenantID shared.ID) ([]*scimgroup.ScimGroup, error)
List returns the tenant's groups.
func (*GroupService) PatchMembers ¶
func (s *GroupService) PatchMembers(ctx context.Context, tenantID, id shared.ID, add, remove []shared.ID) (*scimgroup.ScimGroup, error)
PatchMembers applies incremental add/remove member operations (the common IdP PATCH) and reconciles affected users' roles.
func (*GroupService) Replace ¶
func (s *GroupService) Replace(ctx context.Context, tenantID, id shared.ID, in GroupInput) (*scimgroup.ScimGroup, error)
Replace (PUT) sets the group's displayName + full membership, reconciling the roles of both the previous and new members.
func (*GroupService) ReplaceMembers ¶
func (s *GroupService) ReplaceMembers(ctx context.Context, tenantID, id shared.ID, memberIDs []shared.ID) (*scimgroup.ScimGroup, error)
ReplaceMembers sets the group's full membership (SCIM PATCH op=replace on members) and reconciles previous + new members.
func (*GroupService) SetRoleMappings ¶
func (s *GroupService) SetRoleMappings(ctx context.Context, tenantID shared.ID, mappings map[string]string) error
SetRoleMappings replaces the tenant's group → role overrides (admin action) and re-reconciles every current group member so the change takes effect immediately. Roles are validated; 'owner' is rejected.
type MembershipManager ¶
type MembershipManager interface {
AddMember(ctx context.Context, tenantID, userID shared.ID, role string) error
SuspendMember(ctx context.Context, tenantID, membershipID shared.ID) error
ReactivateMember(ctx context.Context, tenantID, membershipID shared.ID) error
}
MembershipManager applies membership lifecycle with full side effects (session revoke, permission-cache clear, audit). An adapter over tenant.TenantService injects the SCIM system audit context.
type MembershipReader ¶
type MembershipReader interface {
GetMembership(ctx context.Context, userID, tenantID shared.ID) (*tenantdom.Membership, error)
ListMembersByTenant(ctx context.Context, tenantID shared.ID) ([]*tenantdom.Membership, error)
}
MembershipReader reads tenant memberships (tenant.Repository satisfies it).
type MintResult ¶
MintResult carries the plaintext, which is shown to the admin exactly once.
type ProvisionInput ¶
ProvisionInput is a normalised SCIM create/replace request.
type ProvisioningService ¶
type ProvisioningService struct {
// contains filtered or unexported fields
}
ProvisioningService maps SCIM User operations onto OpenCTEM users + tenant memberships.
func NewProvisioningService ¶
func NewProvisioningService(users UserStore, members MembershipReader, manager MembershipManager, log *logger.Logger) *ProvisioningService
NewProvisioningService wires the service.
func (*ProvisioningService) CreateOrActivate ¶
func (s *ProvisioningService) CreateOrActivate(ctx context.Context, tenantID shared.ID, in ProvisionInput) (ScimUser, bool, error)
CreateOrActivate provisions a user into the tenant (idempotent). Returns the resource and whether a NEW membership was created (caller maps to 201 vs 200).
func (*ProvisioningService) Get ¶
func (s *ProvisioningService) Get(ctx context.Context, tenantID, userID shared.ID) (ScimUser, error)
Get returns a provisioned user scoped to the tenant.
func (*ProvisioningService) List ¶
func (s *ProvisioningService) List(ctx context.Context, tenantID shared.ID, filterEmail string, startIndex, count int) ([]ScimUser, int, error)
List returns provisioned users. A non-empty filterEmail returns the matching member (or empty); otherwise tenant members are listed with SCIM 1-based pagination. Returns (page, totalResults, error).
func (*ProvisioningService) SetActive ¶
func (s *ProvisioningService) SetActive(ctx context.Context, tenantID, userID shared.ID, active bool) (ScimUser, error)
SetActive activates/deactivates a user's tenant membership (deprovision when active=false — suspends the membership, which revokes sessions immediately).
type RoleManager ¶
type RoleManager interface {
UpdateMemberRole(ctx context.Context, tenantID, membershipID shared.ID, role string) error
}
RoleManager applies a member's role with full side effects (audit + cache). Implemented by an adapter over tenant.TenantService.UpdateMemberRole.
type ScimUser ¶
type ScimUser struct {
ID string
UserName string
DisplayName string
Email string
Active bool
CreatedAt time.Time
UpdatedAt time.Time
}
ScimUser is the renderer-agnostic projection the HTTP layer wraps into SCIM JSON. Active reflects the tenant membership (suspended → active:false).
type TokenService ¶
type TokenService struct {
// contains filtered or unexported fields
}
TokenService mints, lists, revokes, and authenticates SCIM bearer tokens. Tokens are stored as peppered HMAC-SHA256 hashes (see crypto.HashTokenPeppered) exactly like API keys — a DB leak without APP_ENCRYPTION_KEY cannot be brute-forced offline.
func NewTokenService ¶
func NewTokenService(repo scimtoken.Repository, pepper string, log *logger.Logger) *TokenService
NewTokenService wires the service. pepper should be APP_ENCRYPTION_KEY.
func (*TokenService) Authenticate ¶
func (s *TokenService) Authenticate(ctx context.Context, plaintext string) (*scimtoken.ScimToken, error)
Authenticate validates a presented bearer token and returns it when active. Any invalid/revoked/unknown token returns scimtoken.ErrNotFound without distinction, so the caller cannot enumerate tokens.
func (*TokenService) List ¶
func (s *TokenService) List(ctx context.Context, tenantID shared.ID) ([]*scimtoken.ScimToken, error)
List returns a tenant's SCIM tokens (metadata only; never the plaintext/hash).
type UserStore ¶
type UserStore interface {
GetByEmail(ctx context.Context, email string) (*userdom.User, error)
GetByID(ctx context.Context, id shared.ID) (*userdom.User, error)
Create(ctx context.Context, u *userdom.User) error
Update(ctx context.Context, u *userdom.User) error
}
UserStore is the narrow user-repository surface SCIM provisioning needs.