usecase

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoginChallengeNotFound = errors.New("login challenge not found")
	ErrLoginAlreadyUsed       = errors.New("login challenge already authenticated")
)
View Source
var (
	ErrInvalidPasswordLoginURL           = errors.New("login_url must be an absolute http or https URL with a non-empty host")
	ErrEmptyPasswordLoginName            = errors.New("name must not be empty")
	ErrPasswordLoginEndpointNotFound     = errors.New("password login endpoint not found")
	ErrPasswordLoginAssignmentNotFound   = errors.New("password login assignment not found")
	ErrDuplicateActivePasswordAssignment = errors.New("an active password login assignment already exists for this scope; disable or delete it first")
)
View Source
var (
	ErrScopeValidation         = errors.New("scope validation failed")
	ErrScopeNotFound           = errors.New("scope not found")
	ErrScopeConflict           = errors.New("scope already exists")
	ErrSystemScopeRenameDenied = errors.New("cannot rename system scope")
	ErrSystemScopeDeleteDenied = errors.New("cannot delete a system-level scope")
)
View Source
var (
	ErrWebhookValidation      = errors.New("webhook validation failed")
	ErrWebhookPolicyViolation = errors.New("webhook policy violation")
)

Functions

func HasUnpublishedChanges added in v1.1.0

func HasUnpublishedChanges(b *model.TenantBranding) bool

HasUnpublishedChanges returns true when draft differs from the effective published state. If Published is nil, the effective published state is the system defaults.

func ParseAndDecryptJWE

func ParseAndDecryptJWE(rawToken string, privateKey interface{}) (string, error)

Types

type AuditUseCase

type AuditUseCase interface {
	GetTenantLogs(ctx context.Context, tenantID string, limit, offset int) ([]*model.AuditLog, error)
	GetAuthActivity(ctx context.Context, timeRange string) (*model.AuthActivity, error)
	GetAuthFailures(ctx context.Context, timeRange string) (*model.AuthFailures, error)
	GetRoutingInsights(ctx context.Context, timeRange string) (*model.RoutingInsights, error)
}

func NewAuditUseCase

func NewAuditUseCase(repo port.AuditLogRepository) AuditUseCase

type AuthUseCase

type AuthUseCase interface {
	CreateLoginRequest(ctx context.Context, req *model.LoginRequest) (*model.LoginRequest, error)
	UpdateLoginRequest(ctx context.Context, req *model.LoginRequest) (*model.LoginRequest, error)
	GetLoginRequest(ctx context.Context, challenge string) (*model.LoginRequest, error)
	GetRecentLogins(ctx context.Context, tenantID string, limit int) ([]model.LoginRequest, error)
	GetAuthenticatedLoginRequest(ctx context.Context, tenantID, challenge string) (*model.LoginRequest, error)
	GetAuthenticatedLoginRequestBySubject(ctx context.Context, tenantID, subject string) (*model.LoginRequest, error)
	GetLoginRequestBySessionToken(ctx context.Context, tenantID, sessionToken string) (*model.LoginRequest, error)
	AcceptLoginRequest(ctx context.Context, challenge string, remember bool, rememberFor int, subject string, contextData map[string]interface{}, actorIP, userAgent string) (*model.LoginRequest, error)
	RejectLoginRequest(ctx context.Context, challenge string, errName, errDesc, actorIP, userAgent string) (*model.LoginRequest, error)
	MarkLoginAsProviderStarted(ctx context.Context, challenge, provider, connectionID string, providerContext map[string]interface{}, actorIP, userAgent string) error
	CompleteProviderLogin(ctx context.Context, challenge, subject, connectionName, providerType string, contextData map[string]interface{}, actorIP, userAgent string) (*model.LoginRequest, error)
	MarkLoginRequestConsumed(ctx context.Context, id string) error

	CreateConsentRequest(ctx context.Context, req *model.ConsentRequest) (*model.ConsentRequest, error)
	GetConsentRequest(ctx context.Context, challenge string) (*model.ConsentRequest, error)
	GetAuthenticatedConsentRequest(ctx context.Context, challenge string) (*model.ConsentRequest, error)
	GetAuthenticatedConsentRequestBySubject(ctx context.Context, subject string) (*model.ConsentRequest, error)
	AcceptConsentRequest(ctx context.Context, challenge string, grantScope, grantAudience []string, remember bool, rememberFor int, contextData map[string]interface{}, actorIP, userAgent string) (*model.ConsentRequest, error)
	RejectConsentRequest(ctx context.Context, challenge string, errName, errDesc, actorIP, userAgent string) (*model.ConsentRequest, error)
}

func NewAuthUseCase

func NewAuthUseCase(repo port.AuthRequestRepository, audit port.AuditLogger) AuthUseCase

type BrandingUseCase added in v1.1.0

type BrandingUseCase interface {
	GetBranding(ctx context.Context, tenantID string) (*model.TenantBranding, error)
	UpdateDraft(ctx context.Context, tenantID string, config model.BrandingConfig) (*model.TenantBranding, error)
	Publish(ctx context.Context, tenantID string) (*model.TenantBranding, error)
	Discard(ctx context.Context, tenantID string) (*model.TenantBranding, error)
	Reset(ctx context.Context, tenantID string, target string) (*model.TenantBranding, error)
}

BrandingUseCase manages the draft/published branding lifecycle for a tenant.

func NewBrandingUseCase added in v1.1.0

func NewBrandingUseCase(repo port.BrandingRepository) BrandingUseCase

NewBrandingUseCase returns a new BrandingUseCase.

type HealthUseCase

type HealthUseCase interface {
	CheckDatabase(ctx context.Context) error
	GetHealthSummary(ctx context.Context) (*model.HealthSummary, error)
}

func NewHealthUseCase

func NewHealthUseCase(repo port.HealthRepository, km utils.KeyManager) HealthUseCase

type LDAPConnectionUseCase added in v1.1.0

type LDAPConnectionUseCase interface {
	CreateConnection(ctx context.Context, conn *model.LDAPConnection, actorIP, userAgent string) (*model.LDAPConnection, error)
	GetConnection(ctx context.Context, tenantID, id string) (*model.LDAPConnection, error)
	GetConnectionCount(ctx context.Context, tenantID string) (int64, error)
	TestConnection(ctx context.Context, tenantID, id string) error
	UpdateConnection(ctx context.Context, conn *model.LDAPConnection, actorIP, userAgent string) error
	DeleteConnection(ctx context.Context, tenantID, id string, actorIP, userAgent string) error
	ListConnectionsByTenant(ctx context.Context, tenantID string) ([]*model.LDAPConnection, error)
	ListAllConnections(ctx context.Context) ([]*model.LDAPConnection, error)
	AuthenticateUser(ctx context.Context, tenantID, id, username, password string) (*model.LDAPEntry, error)
	// contains filtered or unexported methods
}

LDAPConnectionUseCase manages LDAP/Active-Directory identity-provider connections.

func NewLDAPConnectionUseCase added in v1.1.0

func NewLDAPConnectionUseCase(
	repo port.LDAPConnectionRepository,
	dialer port.LDAPDialer,
	audit port.AuditLogger,
	scopeUse ScopeUseCase,
	outbound port.OutboundGuard,
) LDAPConnectionUseCase

type ManagementUseCase

type ManagementUseCase interface {
	GetLoginMethods(ctx context.Context, challenge string) ([]model.AuthMethod, *model.LoginRequest, error)
}

type OAuth2ClientUseCase

type OAuth2ClientUseCase interface {
	InitiateAuth(ctx context.Context, tenantID, connectionID, stateToken, csrfToken string) (string, map[string]interface{}, error)
	VerifyState(encryptedState, csrfToken string) (loginChallenge, connectionID string, err error)
	ExchangeAndUserInfo(ctx context.Context, tenantID, code, connectionID, codeVerifier, expectedNonce string) (map[string]interface{}, error)
	SendBackchannelLogout(ctx context.Context, tenantID, clientID, logoutURI, subject, issuer string)
	CreateClient(ctx context.Context, client *model.OAuth2Client, unhashedSecret string, actorIP, userAgent string) (*model.OAuth2Client, string, error)
	UpdateClient(ctx context.Context, client *model.OAuth2Client, unhashedSecret string, actorIP, userAgent string) (*model.OAuth2Client, string, error)
	GetClient(ctx context.Context, tenantID, clientID string) (*model.OAuth2Client, error)
	GetClientCount(ctx context.Context, tenantID string) (int64, error)
	GetPublicClientCount(ctx context.Context, tenantID string) (int64, error)
	GetConfidentialClientCount(ctx context.Context, tenantID string) (int64, error)
	DeleteClient(ctx context.Context, tenantID, clientID string, actorIP, userAgent string) error
	ListClientsByTenant(ctx context.Context, tenantID string) ([]*payload.OAuth2ClientResponse, error)
	ListAllClients(ctx context.Context) ([]*payload.OAuth2ClientResponse, error)
}

type OAuth2SessionUseCase

type OAuth2SessionUseCase interface {
	GetBySubject(ctx context.Context, subject, clientID string) (*model.OAuth2Session, error)
	DeleteByClient(ctx context.Context, subject, clientID string) error
	Delete(ctx context.Context, subject string) error
	RecordAuthorization(ctx context.Context, requestID, tenantID, clientID, actorIP, userAgent string, grantedScopes []string)
	RecordTokenIssuance(ctx context.Context, requestID, tenantID, clientID, actorIP, userAgent string, grantedScopes []string)
	RecordLogout(ctx context.Context, subject, tenantID, clientID, actorIP, userAgent string, hasHint bool)
	RecordRevocation(ctx context.Context, tenantID, actorIP, userAgent string, status bool)
}

type OIDCConnectionUseCase

type OIDCConnectionUseCase interface {
	CreateConnection(ctx context.Context, conn *model.OIDCConnection, actorIP, userAgent string) (*model.OIDCConnection, error)
	UpdateConnection(ctx context.Context, conn *model.OIDCConnection, actorIP, userAgent string) error
	GetConnection(ctx context.Context, tenantID, id string) (*model.OIDCConnection, error)
	GetConnectionCount(ctx context.Context, tenantID string) (int64, error)
	DeleteConnection(ctx context.Context, tenantID, id string, actorIP, userAgent string) error
	ListConnectionsByTenant(ctx context.Context, tenantID string) ([]*model.OIDCConnection, error)
	ListAllConnections(ctx context.Context) ([]*model.OIDCConnection, error)
	// contains filtered or unexported methods
}

type OutboundPolicyUseCase

type OutboundPolicyUseCase interface {
	CreatePolicy(ctx context.Context, policy *model.OutboundPolicy, actorID, actorIP, userAgent string) (*model.OutboundPolicy, error)
	UpdatePolicy(ctx context.Context, policy *model.OutboundPolicy, actorID, actorIP, userAgent string) (*model.OutboundPolicy, error)
	GetPolicy(ctx context.Context, id string) (*model.OutboundPolicy, error)
	ListPolicies(ctx context.Context, tenantID string) ([]*model.OutboundPolicy, error)
	DeletePolicy(ctx context.Context, id string, actorID, actorIP, userAgent string) error
}

type PasswordLoginUseCase added in v1.1.0

type PasswordLoginUseCase interface {
	// Endpoint operations
	CreateEndpoint(ctx context.Context, e *model.PasswordLoginEndpoint) (*model.PasswordLoginEndpoint, error)
	GetEndpoint(ctx context.Context, id string) (*model.PasswordLoginEndpoint, error)
	UpdateEndpoint(ctx context.Context, e *model.PasswordLoginEndpoint) (*model.PasswordLoginEndpoint, error)
	DeleteEndpoint(ctx context.Context, id string) error
	ListEndpoints(ctx context.Context) ([]*model.PasswordLoginEndpoint, error)

	// Assignment operations
	CreateAssignment(ctx context.Context, a *model.PasswordLoginAssignment) (*model.PasswordLoginAssignment, error)
	GetAssignment(ctx context.Context, id string) (*model.PasswordLoginAssignment, error)
	UpdateAssignment(ctx context.Context, a *model.PasswordLoginAssignment) (*model.PasswordLoginAssignment, error)
	DeleteAssignment(ctx context.Context, id string) error
	ListAssignments(ctx context.Context, tenantID *string) ([]*model.PasswordLoginAssignment, error)
}

PasswordLoginUseCase provides admin operations for password login endpoint definitions and their tenant assignments.

func NewPasswordLoginUseCase added in v1.1.0

func NewPasswordLoginUseCase(repo port.PasswordLoginRepository) PasswordLoginUseCase

type PersistentAssertionMaker

type PersistentAssertionMaker interface {
	MakeAssertion(req *crewjamsaml.IdpAuthnRequest, session *crewjamsaml.Session)
}

type SAMLClientUseCase

type SAMLClientUseCase interface {
	CreateClient(ctx context.Context, client *model.SAMLClient, actorIP, userAgent string) (*model.SAMLClient, error)
	GetClient(ctx context.Context, tenantID, id string) (*model.SAMLClient, error)
	GetClientCount(ctx context.Context, tenantID string) (int64, error)
	GetClientByEntityID(ctx context.Context, tenantID, entityID string) (*model.SAMLClient, error)
	UpdateClient(ctx context.Context, client *model.SAMLClient, actorIP, userAgent string) error
	DeleteClient(ctx context.Context, tenantID, id string, actorIP, userAgent string) error
	ListClientsByTenant(ctx context.Context, tenantID string) ([]*payload.SAMLClientResponse, error)
	ListAllClients(ctx context.Context) ([]*payload.SAMLClientResponse, error)
}

func NewSAMLClientUseCase

func NewSAMLClientUseCase(repo port.SAMLClientRepository, tenant port.TenantRepository, audit port.AuditLogger, outboundGuard port.OutboundGuard) SAMLClientUseCase

type SAMLConnectionUseCase

type SAMLConnectionUseCase interface {
	CreateConnection(ctx context.Context, conn *model.SAMLConnection, actorIP, userAgent string) (*model.SAMLConnection, error)
	GetConnection(ctx context.Context, tenantID, id string) (*model.SAMLConnection, error)
	GetConnectionCount(ctx context.Context, tenantID string) (int64, error)
	GetConnectionByIdpEntity(ctx context.Context, tenantID, idpEntity string) (*model.SAMLConnection, error)
	UpdateConnection(ctx context.Context, conn *model.SAMLConnection, actorIP, userAgent string) error
	DeleteConnection(ctx context.Context, tenantID, id string, actorIP, userAgent string) error
	ListConnectionsByTenant(ctx context.Context, tenantID string) ([]*model.SAMLConnection, error)
	ListAllConnections(ctx context.Context) ([]*model.SAMLConnection, error)
	// contains filtered or unexported methods
}

type SamlBuilderUseCase

type SamlBuilderUseCase interface {
	BuildServiceProvider(ctx context.Context, tenantID string, conn *model.SAMLConnection) (*crewjamsaml.ServiceProvider, error)
	InitiateSSO(ctx context.Context, tenantID, connectionID, loginChallenge, csrfToken string) (string, string, error)
	HandleACS(ctx context.Context, tenantID string, req *http.Request, possibleRequestID string) (*crewjamsaml.Assertion, string, error)
	GetIdentityProvider(ctx context.Context, tenantID string) (*crewjamsaml.IdentityProvider, error)
	GetServiceProvider(r *http.Request, serviceProviderID string) (*crewjamsaml.EntityDescriptor, error)
	ParseAuthnRequest(ctx context.Context, tenantID string, req *http.Request) (*crewjamsaml.AuthnRequest, error)
	GenerateSAMLResponse(ctx context.Context, tenantID string, authReq *crewjamsaml.AuthnRequest, sp *model.SAMLClient, userAttributes map[string]interface{}, relayState string) (string, error)
	RegisterConnection(ctx context.Context, tenantID, name, metadataXML string) (*model.SAMLConnection, error)
	ParseLogoutRequest(req *http.Request) (*crewjamsaml.LogoutRequest, error)
	GenerateLogoutResponse(ctx context.Context, tenantID string, req *crewjamsaml.LogoutRequest, sp *model.SAMLClient, relayState string) (string, error)

	VerifyRelayState(ctx context.Context, tenantID, encryptedState, csrfToken string) (*security.FederationStatePayload, error)
	// contains filtered or unexported methods
}

type ScopeUseCase

type ScopeUseCase interface {
	CreateScope(ctx context.Context, scope *model.Scope, actorIP, userAgent string) (*model.Scope, error)
	GetScope(ctx context.Context, tenantID, id string) (*model.Scope, error)
	GetScopesByNames(ctx context.Context, tenantID string, names []string) ([]*model.Scope, error)
	ListScopes(ctx context.Context, tenantID string) ([]*model.Scope, error)
	UpdateScope(ctx context.Context, scope *model.Scope, actorIP, userAgent string) error
	DeleteScope(ctx context.Context, tenantID, id string, actorIP, userAgent string) error
	AddClaimToScopes(ctx context.Context, tenantID string, claim string, scopeNames []string) error
}

func NewScopeUseCase

func NewScopeUseCase(repo port.ScopeRepository, audit port.AuditLogger) ScopeUseCase

type SingleCertStore

type SingleCertStore struct {
	Cert *x509.Certificate
}

func (*SingleCertStore) Certificates

func (s *SingleCertStore) Certificates() ([]*x509.Certificate, error)

type TenantUseCase

type TenantUseCase interface {
	CreateTenant(ctx context.Context, tenant *model.Tenant, actorIP, userAgent string) (*model.Tenant, error)
	GetTenant(ctx context.Context, id string) (*model.Tenant, error)
	GetCount(ctx context.Context) (int64, error)
	GetTenantByName(ctx context.Context, name string) (*model.Tenant, error)
	UpdateTenant(ctx context.Context, tenant *model.Tenant, actorIP, userAgent string) error
	DeleteTenant(ctx context.Context, id string, actorIP, userAgent string) error
	ListTenants(ctx context.Context) ([]*payload.TenantResponse, error)
}

func NewTenantUseCase

func NewTenantUseCase(repo port.TenantRepository, audit port.AuditLogger, scopeRepo port.ScopeRepository) TenantUseCase

type WebhookUseCase

type WebhookUseCase interface {
	CreateWebhook(ctx context.Context, webhook *model.Webhook, actorIP, userAgent string) (*model.Webhook, string, error)
	GetWebhook(ctx context.Context, id string) (*model.Webhook, error)
	DeleteWebhook(ctx context.Context, id string, actorIP, userAgent string) error
	ListWebhooks(ctx context.Context) ([]*model.Webhook, error)
	FireEvent(tenantID, eventType string, data map[string]interface{})
	StartDispatcher()
}

func NewWebhookUseCase

func NewWebhookUseCase(
	repo port.WebhookRepository,
	eventRepo port.WebhookEventRepository,
	audit port.AuditLogger,
	outbound port.OutboundGuard,
) WebhookUseCase

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL