2021-09-27 13:43:49 +02:00
|
|
|
package domain
|
|
|
|
|
2024-02-26 11:49:43 +01:00
|
|
|
import (
|
|
|
|
"slices"
|
|
|
|
"strconv"
|
|
|
|
)
|
2022-10-06 14:23:59 +02:00
|
|
|
|
2021-09-27 13:43:49 +02:00
|
|
|
type FlowState int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
FlowStateActive FlowState = iota
|
|
|
|
FlowStateInactive
|
|
|
|
flowStateCount
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s FlowState) Valid() bool {
|
|
|
|
return s >= 0 && s < flowStateCount
|
|
|
|
}
|
|
|
|
|
|
|
|
type FlowType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
FlowTypeUnspecified FlowType = iota
|
|
|
|
FlowTypeExternalAuthentication
|
2022-10-06 14:23:59 +02:00
|
|
|
FlowTypeCustomiseToken
|
2023-01-25 14:08:01 +01:00
|
|
|
FlowTypeInternalAuthentication
|
2023-08-15 17:04:45 +02:00
|
|
|
FlowTypeCustomizeSAMLResponse
|
2021-09-27 13:43:49 +02:00
|
|
|
flowTypeCount
|
|
|
|
)
|
|
|
|
|
2024-02-26 11:49:43 +01:00
|
|
|
func AllFlowTypes() []FlowType {
|
|
|
|
return []FlowType{
|
|
|
|
FlowTypeExternalAuthentication,
|
|
|
|
FlowTypeCustomiseToken,
|
|
|
|
FlowTypeInternalAuthentication,
|
|
|
|
FlowTypeCustomizeSAMLResponse,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-27 13:43:49 +02:00
|
|
|
func (s FlowType) Valid() bool {
|
|
|
|
return s > 0 && s < flowTypeCount
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s FlowType) HasTrigger(triggerType TriggerType) bool {
|
2022-10-06 14:23:59 +02:00
|
|
|
for _, trigger := range s.TriggerTypes() {
|
|
|
|
if trigger == triggerType {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s FlowType) TriggerTypes() []TriggerType {
|
|
|
|
switch s {
|
|
|
|
case FlowTypeExternalAuthentication:
|
|
|
|
return []TriggerType{
|
|
|
|
TriggerTypePostAuthentication,
|
|
|
|
TriggerTypePreCreation,
|
|
|
|
TriggerTypePostCreation,
|
|
|
|
}
|
|
|
|
case FlowTypeCustomiseToken:
|
|
|
|
return []TriggerType{
|
|
|
|
TriggerTypePreUserinfoCreation,
|
|
|
|
TriggerTypePreAccessTokenCreation,
|
|
|
|
}
|
2023-01-25 14:08:01 +01:00
|
|
|
case FlowTypeInternalAuthentication:
|
|
|
|
return []TriggerType{
|
|
|
|
TriggerTypePostAuthentication,
|
|
|
|
TriggerTypePreCreation,
|
|
|
|
TriggerTypePostCreation,
|
|
|
|
}
|
2023-08-15 17:04:45 +02:00
|
|
|
case FlowTypeCustomizeSAMLResponse:
|
|
|
|
return []TriggerType{
|
|
|
|
TriggerTypePreSAMLResponseCreation,
|
|
|
|
}
|
2022-10-06 14:23:59 +02:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s FlowType) ID() string {
|
|
|
|
if s < 0 && s >= flowTypeCount {
|
|
|
|
return FlowTypeUnspecified.ID()
|
|
|
|
}
|
|
|
|
return strconv.Itoa(int(s))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s FlowType) LocalizationKey() string {
|
|
|
|
if s < 0 && s >= flowTypeCount {
|
|
|
|
return FlowTypeUnspecified.LocalizationKey()
|
|
|
|
}
|
|
|
|
|
|
|
|
switch s {
|
|
|
|
case FlowTypeExternalAuthentication:
|
|
|
|
return "Action.Flow.Type.ExternalAuthentication"
|
|
|
|
case FlowTypeCustomiseToken:
|
|
|
|
return "Action.Flow.Type.CustomiseToken"
|
2023-01-25 14:08:01 +01:00
|
|
|
case FlowTypeInternalAuthentication:
|
|
|
|
return "Action.Flow.Type.InternalAuthentication"
|
2023-08-15 17:04:45 +02:00
|
|
|
case FlowTypeCustomizeSAMLResponse:
|
|
|
|
return "Action.Flow.Type.CustomizeSAMLResponse"
|
2021-09-27 13:43:49 +02:00
|
|
|
default:
|
2022-10-06 14:23:59 +02:00
|
|
|
return "Action.Flow.Type.Unspecified"
|
2021-09-27 13:43:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type TriggerType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
TriggerTypeUnspecified TriggerType = iota
|
|
|
|
TriggerTypePostAuthentication
|
|
|
|
TriggerTypePreCreation
|
|
|
|
TriggerTypePostCreation
|
2022-10-06 14:23:59 +02:00
|
|
|
TriggerTypePreUserinfoCreation
|
|
|
|
TriggerTypePreAccessTokenCreation
|
2023-08-15 17:04:45 +02:00
|
|
|
TriggerTypePreSAMLResponseCreation
|
2021-09-27 13:43:49 +02:00
|
|
|
triggerTypeCount
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s TriggerType) Valid() bool {
|
|
|
|
return s >= 0 && s < triggerTypeCount
|
|
|
|
}
|
2022-10-06 14:23:59 +02:00
|
|
|
|
|
|
|
func (s TriggerType) ID() string {
|
|
|
|
if !s.Valid() {
|
|
|
|
return TriggerTypeUnspecified.ID()
|
|
|
|
}
|
|
|
|
return strconv.Itoa(int(s))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s TriggerType) LocalizationKey() string {
|
|
|
|
if !s.Valid() {
|
|
|
|
return FlowTypeUnspecified.LocalizationKey()
|
|
|
|
}
|
|
|
|
|
|
|
|
switch s {
|
|
|
|
case TriggerTypePostAuthentication:
|
|
|
|
return "Action.TriggerType.PostAuthentication"
|
|
|
|
case TriggerTypePreCreation:
|
|
|
|
return "Action.TriggerType.PreCreation"
|
|
|
|
case TriggerTypePostCreation:
|
|
|
|
return "Action.TriggerType.PostCreation"
|
|
|
|
case TriggerTypePreUserinfoCreation:
|
|
|
|
return "Action.TriggerType.PreUserinfoCreation"
|
|
|
|
case TriggerTypePreAccessTokenCreation:
|
|
|
|
return "Action.TriggerType.PreAccessTokenCreation"
|
2023-08-15 17:04:45 +02:00
|
|
|
case TriggerTypePreSAMLResponseCreation:
|
|
|
|
return "Action.TriggerType.PreSAMLResponseCreation"
|
2022-10-06 14:23:59 +02:00
|
|
|
default:
|
|
|
|
return "Action.TriggerType.Unspecified"
|
|
|
|
}
|
|
|
|
}
|
2024-02-26 11:49:43 +01:00
|
|
|
|
|
|
|
func AllFunctions() []string {
|
|
|
|
functions := make([]string, 0)
|
|
|
|
for _, flowType := range AllFlowTypes() {
|
|
|
|
for _, triggerType := range flowType.TriggerTypes() {
|
|
|
|
functions = append(functions, flowType.LocalizationKey()+"."+triggerType.LocalizationKey())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return functions
|
|
|
|
}
|
|
|
|
|
|
|
|
func FunctionExists() func(string) bool {
|
|
|
|
functions := AllFunctions()
|
|
|
|
return func(s string) bool {
|
|
|
|
return slices.Contains(functions, s)
|
|
|
|
}
|
|
|
|
}
|