mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-25 08:42:16 +00:00
feat: federated logout for SAML IdPs (#9931)
# Which Problems Are Solved Currently if a user signs in using an IdP, once they sign out of Zitadel, the corresponding IdP session is not terminated. This can be the desired behavior. In some cases, e.g. when using a shared computer it results in a potential security risk, since a follower user might be able to sign in as the previous using the still open IdP session. # How the Problems Are Solved - Admins can enabled a federated logout option on SAML IdPs through the Admin and Management APIs. - During the termination of a login V1 session using OIDC end_session endpoint, Zitadel will check if an IdP was used to authenticate that session. - In case there was a SAML IdP used with Federated Logout enabled, it will intercept the logout process, store the information into the shared cache and redirect to the federated logout endpoint in the V1 login. - The V1 login federated logout endpoint checks every request on an existing cache entry. On success it will create a SAML logout request for the used IdP and either redirect or POST to the configured SLO endpoint. The cache entry is updated with a `redirected` state. - A SLO endpoint is added to the `/idp` handlers, which will handle the SAML logout responses. At the moment it will check again for an existing federated logout entry (with state `redirected`) in the cache. On success, the user is redirected to the initially provided `post_logout_redirect_uri` from the end_session request. # Additional Changes None # Additional Context - This PR merges the https://github.com/zitadel/zitadel/pull/9841 and https://github.com/zitadel/zitadel/pull/9854 to main, additionally updating the docs on Entra ID SAML. - closes #9228 - backport to 3.x --------- Co-authored-by: Silvan <[email protected]> Co-authored-by: Zach Hirschtritt <[email protected]>
This commit is contained in:
co-authored by
Silvan
Zach Hirschtritt
parent
7eb45c6cfd
commit
2cf3ef4de4
@@ -488,6 +488,7 @@ func addSAMLProviderToCommand(req *admin_pb.AddSAMLProviderRequest) *command.SAM
|
||||
WithSignedRequest: req.WithSignedRequest,
|
||||
NameIDFormat: nameIDFormat,
|
||||
TransientMappingAttributeName: req.GetTransientMappingAttributeName(),
|
||||
FederatedLogoutEnabled: req.GetFederatedLogoutEnabled(),
|
||||
IDPOptions: idp_grpc.OptionsToCommand(req.ProviderOptions),
|
||||
}
|
||||
}
|
||||
@@ -505,6 +506,7 @@ func updateSAMLProviderToCommand(req *admin_pb.UpdateSAMLProviderRequest) *comma
|
||||
WithSignedRequest: req.WithSignedRequest,
|
||||
NameIDFormat: nameIDFormat,
|
||||
TransientMappingAttributeName: req.GetTransientMappingAttributeName(),
|
||||
FederatedLogoutEnabled: req.GetFederatedLogoutEnabled(),
|
||||
IDPOptions: idp_grpc.OptionsToCommand(req.ProviderOptions),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,6 +669,7 @@ func samlConfigToPb(providerConfig *idp_pb.ProviderConfig, template *query.SAMLI
|
||||
WithSignedRequest: template.WithSignedRequest,
|
||||
NameIdFormat: nameIDFormat,
|
||||
TransientMappingAttributeName: gu.Ptr(template.TransientMappingAttributeName),
|
||||
FederatedLogoutEnabled: gu.Ptr(template.FederatedLogoutEnabled),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,6 +336,7 @@ func samlConfigToPb(idpConfig *idp_pb.IDPConfig, template *query.SAMLIDPTemplate
|
||||
WithSignedRequest: template.WithSignedRequest,
|
||||
NameIdFormat: nameIDFormat,
|
||||
TransientMappingAttributeName: gu.Ptr(template.TransientMappingAttributeName),
|
||||
FederatedLogoutEnabled: gu.Ptr(template.FederatedLogoutEnabled),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,6 +481,7 @@ func addSAMLProviderToCommand(req *mgmt_pb.AddSAMLProviderRequest) *command.SAML
|
||||
WithSignedRequest: req.WithSignedRequest,
|
||||
NameIDFormat: nameIDFormat,
|
||||
TransientMappingAttributeName: req.GetTransientMappingAttributeName(),
|
||||
FederatedLogoutEnabled: req.GetFederatedLogoutEnabled(),
|
||||
IDPOptions: idp_grpc.OptionsToCommand(req.ProviderOptions),
|
||||
}
|
||||
}
|
||||
@@ -498,6 +499,7 @@ func updateSAMLProviderToCommand(req *mgmt_pb.UpdateSAMLProviderRequest) *comman
|
||||
WithSignedRequest: req.WithSignedRequest,
|
||||
NameIDFormat: nameIDFormat,
|
||||
TransientMappingAttributeName: req.GetTransientMappingAttributeName(),
|
||||
FederatedLogoutEnabled: req.GetFederatedLogoutEnabled(),
|
||||
IDPOptions: idp_grpc.OptionsToCommand(req.ProviderOptions),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,13 @@ import (
|
||||
"github.com/muhlemmer/gu"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
http_utils "github.com/zitadel/zitadel/internal/api/http"
|
||||
"github.com/zitadel/zitadel/internal/api/ui/login"
|
||||
"github.com/zitadel/zitadel/internal/cache"
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/domain/federatedlogout"
|
||||
"github.com/zitadel/zitadel/internal/form"
|
||||
"github.com/zitadel/zitadel/internal/idp"
|
||||
"github.com/zitadel/zitadel/internal/idp/providers/apple"
|
||||
@@ -44,6 +47,7 @@ const (
|
||||
metadataPath = idpPrefix + "/saml/metadata"
|
||||
acsPath = idpPrefix + "/saml/acs"
|
||||
certificatePath = idpPrefix + "/saml/certificate"
|
||||
sloPath = idpPrefix + "/saml/slo"
|
||||
|
||||
paramIntentID = "id"
|
||||
paramToken = "token"
|
||||
@@ -62,6 +66,7 @@ type Handler struct {
|
||||
callbackURL func(ctx context.Context) string
|
||||
samlRootURL func(ctx context.Context, idpID string) string
|
||||
loginSAMLRootURL func(ctx context.Context) string
|
||||
caches *Caches
|
||||
}
|
||||
|
||||
type externalIDPCallbackData struct {
|
||||
@@ -104,6 +109,7 @@ func NewHandler(
|
||||
queries *query.Queries,
|
||||
encryptionAlgorithm crypto.EncryptionAlgorithm,
|
||||
instanceInterceptor func(next http.Handler) http.Handler,
|
||||
federatedLogoutCache cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout],
|
||||
) http.Handler {
|
||||
h := &Handler{
|
||||
commands: commands,
|
||||
@@ -113,6 +119,7 @@ func NewHandler(
|
||||
callbackURL: CallbackURL(),
|
||||
samlRootURL: SAMLRootURL(),
|
||||
loginSAMLRootURL: LoginSAMLRootURL(),
|
||||
caches: &Caches{federatedLogouts: federatedLogoutCache},
|
||||
}
|
||||
|
||||
router := mux.NewRouter()
|
||||
@@ -121,9 +128,14 @@ func NewHandler(
|
||||
router.HandleFunc(metadataPath, h.handleMetadata)
|
||||
router.HandleFunc(certificatePath, h.handleCertificate)
|
||||
router.HandleFunc(acsPath, h.handleACS)
|
||||
router.HandleFunc(sloPath, h.handleSLO)
|
||||
return router
|
||||
}
|
||||
|
||||
type Caches struct {
|
||||
federatedLogouts cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout]
|
||||
}
|
||||
|
||||
func parseSAMLRequest(r *http.Request) *externalSAMLIDPCallbackData {
|
||||
vars := mux.Vars(r)
|
||||
return &externalSAMLIDPCallbackData{
|
||||
@@ -351,6 +363,38 @@ func (h *Handler) handleCallback(w http.ResponseWriter, r *http.Request) {
|
||||
redirectToSuccessURL(w, r, intent, token, userID)
|
||||
}
|
||||
|
||||
func (h *Handler) handleSLO(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
data := parseSAMLRequest(r)
|
||||
|
||||
logoutState, ok := h.caches.federatedLogouts.Get(ctx, federatedlogout.IndexRequestID, federatedlogout.Key(authz.GetInstance(ctx).InstanceID(), data.RelayState))
|
||||
if !ok || logoutState.State != federatedlogout.StateRedirected {
|
||||
err := zerrors.ThrowNotFound(nil, "SAML-3uor2", "Errors.Intent.NotFound")
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// For the moment we just make sure the callback matches the IDP it was started on / intended for.
|
||||
|
||||
provider, err := h.getProvider(ctx, data.IDPID)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if _, ok = provider.(*saml2.Provider); !ok {
|
||||
err := zerrors.ThrowInvalidArgument(nil, "SAML-ui9wyux0hp", "Errors.Intent.IDPInvalid")
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// We could also parse and validate the response here, but for example Azure does not sign it and thus would already fail.
|
||||
// Also we can't really act on it if it fails.
|
||||
|
||||
err = h.caches.federatedLogouts.Delete(ctx, federatedlogout.IndexRequestID, federatedlogout.Key(logoutState.InstanceID, logoutState.SessionID))
|
||||
logging.WithFields("instanceID", logoutState.InstanceID, "sessionID", logoutState.SessionID).OnError(err).Error("could not delete federated logout")
|
||||
http.Redirect(w, r, logoutState.PostLogoutRedirectURI, http.StatusFound)
|
||||
}
|
||||
|
||||
func (h *Handler) tryMigrateExternalUser(ctx context.Context, idpID string, idpUser idp.User, idpSession idp.Session) (userID string, err error) {
|
||||
migration, ok := idpSession.(idp.SessionSupportsMigration)
|
||||
if !ok {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/auth/repository/eventsourcing/handler"
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/domain/federatedlogout"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
"github.com/zitadel/zitadel/internal/user/model"
|
||||
@@ -236,6 +237,11 @@ func (o *OPStorage) TokenRequestByRefreshToken(ctx context.Context, refreshToken
|
||||
}
|
||||
|
||||
func (o *OPStorage) TerminateSession(ctx context.Context, userID, clientID string) (err error) {
|
||||
_, err = o.terminateSession(ctx, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o *OPStorage) terminateSession(ctx context.Context, userID string) (sessions []command.HumanSignOutSession, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() {
|
||||
err = oidcError(err)
|
||||
@@ -244,22 +250,22 @@ func (o *OPStorage) TerminateSession(ctx context.Context, userID, clientID strin
|
||||
userAgentID, ok := middleware.UserAgentIDFromCtx(ctx)
|
||||
if !ok {
|
||||
logging.Error("no user agent id")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "OIDC-fso7F", "no user agent id")
|
||||
return nil, zerrors.ThrowPreconditionFailed(nil, "OIDC-fso7F", "no user agent id")
|
||||
}
|
||||
sessions, err := o.repo.UserSessionsByAgentID(ctx, userAgentID)
|
||||
sessions, err = o.repo.UserSessionsByAgentID(ctx, userAgentID)
|
||||
if err != nil {
|
||||
logging.WithError(err).Error("error retrieving user sessions")
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
if len(sessions) == 0 {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
data := authz.CtxData{
|
||||
UserID: userID,
|
||||
}
|
||||
err = o.command.HumansSignOut(authz.SetCtxData(ctx, data), userAgentID, sessions)
|
||||
logging.OnError(err).Error("error signing out")
|
||||
return err
|
||||
return sessions, err
|
||||
}
|
||||
|
||||
func (o *OPStorage) TerminateSessionFromRequest(ctx context.Context, endSessionRequest *op.EndSessionRequest) (redirectURI string, err error) {
|
||||
@@ -294,7 +300,16 @@ func (o *OPStorage) TerminateSessionFromRequest(ctx context.Context, endSessionR
|
||||
// So if any condition is not met, we handle the request as a V1 request and do a (v1) TerminateSession,
|
||||
// which terminates all sessions of the user agent, identified by cookie.
|
||||
if endSessionRequest.IDTokenHintClaims == nil || endSessionRequest.IDTokenHintClaims.SessionID == "" {
|
||||
return endSessionRequest.RedirectURI, o.TerminateSession(ctx, endSessionRequest.UserID, endSessionRequest.ClientID)
|
||||
sessions, err := o.terminateSession(ctx, endSessionRequest.UserID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(sessions) == 1 {
|
||||
if path := o.federatedLogout(ctx, sessions[0].ID, endSessionRequest.RedirectURI); path != "" {
|
||||
return path, nil
|
||||
}
|
||||
}
|
||||
return endSessionRequest.RedirectURI, nil
|
||||
}
|
||||
|
||||
// V1:
|
||||
@@ -305,6 +320,9 @@ func (o *OPStorage) TerminateSessionFromRequest(ctx context.Context, endSessionR
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if path := o.federatedLogout(ctx, endSessionRequest.IDTokenHintClaims.SessionID, endSessionRequest.RedirectURI); path != "" {
|
||||
return path, nil
|
||||
}
|
||||
return endSessionRequest.RedirectURI, nil
|
||||
}
|
||||
|
||||
@@ -317,6 +335,39 @@ func (o *OPStorage) TerminateSessionFromRequest(ctx context.Context, endSessionR
|
||||
return v2PostLogoutRedirectURI(endSessionRequest.RedirectURI), nil
|
||||
}
|
||||
|
||||
// federatedLogout checks whether the session has an idp session linked and the IDP template is configured for federated logout.
|
||||
// If so, it creates a federated logout request and stores it in the cache and returns the logout path.
|
||||
func (o *OPStorage) federatedLogout(ctx context.Context, sessionID string, postLogoutRedirectURI string) string {
|
||||
session, err := o.repo.UserSessionByID(ctx, sessionID)
|
||||
if err != nil {
|
||||
logging.WithFields("instanceID", authz.GetInstance(ctx).InstanceID(), "sessionID", sessionID).
|
||||
WithError(err).Error("error retrieving user session")
|
||||
return ""
|
||||
}
|
||||
if session.SelectedIDPConfigID.String == "" {
|
||||
return ""
|
||||
}
|
||||
identityProvider, err := o.query.IDPTemplateByID(ctx, false, session.SelectedIDPConfigID.String, false, nil)
|
||||
if err != nil {
|
||||
logging.WithFields("instanceID", authz.GetInstance(ctx).InstanceID(), "idpID", session.SelectedIDPConfigID.String, "sessionID", sessionID).
|
||||
WithError(err).Error("error retrieving idp template")
|
||||
return ""
|
||||
}
|
||||
if identityProvider.SAMLIDPTemplate == nil || !identityProvider.FederatedLogoutEnabled {
|
||||
return ""
|
||||
}
|
||||
o.federateLogoutCache.Set(ctx, &federatedlogout.FederatedLogout{
|
||||
InstanceID: authz.GetInstance(ctx).InstanceID(),
|
||||
FingerPrintID: authz.GetCtxData(ctx).AgentID,
|
||||
SessionID: sessionID,
|
||||
IDPID: session.SelectedIDPConfigID.String,
|
||||
UserID: session.UserID,
|
||||
PostLogoutRedirectURI: postLogoutRedirectURI,
|
||||
State: federatedlogout.StateCreated,
|
||||
})
|
||||
return login.ExternalLogoutPath(sessionID)
|
||||
}
|
||||
|
||||
func buildLoginV2LogoutURL(baseURI *url.URL, redirectURI string) string {
|
||||
baseURI.JoinPath(LogoutPath)
|
||||
q := baseURI.Query()
|
||||
|
||||
+17
-2
@@ -15,9 +15,11 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/api/http/middleware"
|
||||
"github.com/zitadel/zitadel/internal/api/ui/login"
|
||||
"github.com/zitadel/zitadel/internal/auth/repository"
|
||||
"github.com/zitadel/zitadel/internal/cache"
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/domain/federatedlogout"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
@@ -76,6 +78,7 @@ type OPStorage struct {
|
||||
locker crdb.Locker
|
||||
assetAPIPrefix func(ctx context.Context) string
|
||||
contextToIssuer func(context.Context) string
|
||||
federateLogoutCache cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout]
|
||||
}
|
||||
|
||||
// Provider is used to overload certain [op.Provider] methods
|
||||
@@ -115,12 +118,13 @@ func NewServer(
|
||||
accessHandler *middleware.AccessInterceptor,
|
||||
fallbackLogger *slog.Logger,
|
||||
hashConfig crypto.HashConfig,
|
||||
federatedLogoutCache cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout],
|
||||
) (*Server, error) {
|
||||
opConfig, err := createOPConfig(config, defaultLogoutRedirectURI, cryptoKey)
|
||||
if err != nil {
|
||||
return nil, zerrors.ThrowInternal(err, "OIDC-EGrqd", "cannot create op config: %w")
|
||||
}
|
||||
storage := newStorage(config, command, query, repo, encryptionAlg, es, projections, ContextToIssuer)
|
||||
storage := newStorage(config, command, query, repo, encryptionAlg, es, projections, ContextToIssuer, federatedLogoutCache)
|
||||
keyCache := newPublicKeyCache(ctx, config.PublicKeyCacheMaxAge, queryKeyFunc(query))
|
||||
accessTokenKeySet := newOidcKeySet(keyCache, withKeyExpiryCheck(true))
|
||||
idTokenHintKeySet := newOidcKeySet(keyCache)
|
||||
@@ -225,7 +229,17 @@ func createOPConfig(config Config, defaultLogoutRedirectURI string, cryptoKey []
|
||||
return opConfig, nil
|
||||
}
|
||||
|
||||
func newStorage(config Config, command *command.Commands, query *query.Queries, repo repository.Repository, encAlg crypto.EncryptionAlgorithm, es *eventstore.Eventstore, db *database.DB, contextToIssuer func(context.Context) string) *OPStorage {
|
||||
func newStorage(
|
||||
config Config,
|
||||
command *command.Commands,
|
||||
query *query.Queries,
|
||||
repo repository.Repository,
|
||||
encAlg crypto.EncryptionAlgorithm,
|
||||
es *eventstore.Eventstore,
|
||||
db *database.DB,
|
||||
contextToIssuer func(context.Context) string,
|
||||
federateLogoutCache cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout],
|
||||
) *OPStorage {
|
||||
return &OPStorage{
|
||||
repo: repo,
|
||||
command: command,
|
||||
@@ -242,6 +256,7 @@ func newStorage(config Config, command *command.Commands, query *query.Queries,
|
||||
locker: crdb.NewLocker(db.DB, locksTable, signingKey),
|
||||
assetAPIPrefix: assets.AssetAPI(),
|
||||
contextToIssuer: contextToIssuer,
|
||||
federateLogoutCache: federateLogoutCache,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ package login
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
crewjam_saml "github.com/crewjam/saml"
|
||||
"github.com/crewjam/saml/samlsp"
|
||||
"github.com/zitadel/logging"
|
||||
"github.com/zitadel/oidc/v3/pkg/client/rp"
|
||||
@@ -20,6 +22,7 @@ import (
|
||||
http_mw "github.com/zitadel/zitadel/internal/api/http/middleware"
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/domain/federatedlogout"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/idp"
|
||||
"github.com/zitadel/zitadel/internal/idp/providers/apple"
|
||||
@@ -1422,6 +1425,124 @@ func (l *Login) getUserLinks(ctx context.Context, userID, idpID string) (*query.
|
||||
)
|
||||
}
|
||||
|
||||
type federatedLogoutData struct {
|
||||
SessionID string `schema:"sessionID"`
|
||||
}
|
||||
|
||||
const (
|
||||
federatedLogoutDataSessionID = "sessionID"
|
||||
)
|
||||
|
||||
func ExternalLogoutPath(sessionID string) string {
|
||||
v := url.Values{}
|
||||
v.Set(federatedLogoutDataSessionID, sessionID)
|
||||
return HandlerPrefix + EndpointExternalLogout + "?" + v.Encode()
|
||||
}
|
||||
|
||||
// handleExternalLogout is called when a user signed out of ZITADEL with a federated logout
|
||||
func (l *Login) handleExternalLogout(w http.ResponseWriter, r *http.Request) {
|
||||
data := new(federatedLogoutData)
|
||||
err := l.parser.Parse(r, data)
|
||||
if err != nil {
|
||||
l.renderError(w, r, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
logoutRequest, ok := l.caches.federatedLogouts.Get(r.Context(), federatedlogout.IndexRequestID, federatedlogout.Key(authz.GetInstance(r.Context()).InstanceID(), data.SessionID))
|
||||
if !ok || logoutRequest.State != federatedlogout.StateCreated || logoutRequest.FingerPrintID != authz.GetCtxData(r.Context()).AgentID {
|
||||
l.renderError(w, r, nil, zerrors.ThrowNotFound(nil, "LOGIN-ADK21", "Errors.ExternalIDP.LogoutRequestNotFound"))
|
||||
return
|
||||
}
|
||||
|
||||
provider, err := l.externalLogoutProvider(r, logoutRequest.IDPID)
|
||||
if err != nil {
|
||||
l.renderError(w, r, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
nameID, err := l.externalUserID(r.Context(), logoutRequest.UserID, logoutRequest.IDPID)
|
||||
if err != nil {
|
||||
l.renderError(w, r, nil, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = samlLogoutRequest(w, r, provider, nameID, logoutRequest.SessionID)
|
||||
if err != nil {
|
||||
l.renderError(w, r, nil, err)
|
||||
return
|
||||
}
|
||||
logoutRequest.State = federatedlogout.StateRedirected
|
||||
l.caches.federatedLogouts.Set(r.Context(), logoutRequest)
|
||||
}
|
||||
|
||||
func (l *Login) externalLogoutProvider(r *http.Request, providerID string) (*saml.Provider, error) {
|
||||
identityProvider, err := l.getIDPByID(r, providerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if identityProvider.Type != domain.IDPTypeSAML {
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "LOGIN-ADK21", "Errors.ExternalIDP.IDPTypeNotImplemented")
|
||||
}
|
||||
return l.samlProvider(r.Context(), identityProvider)
|
||||
}
|
||||
|
||||
func samlLogoutRequest(w http.ResponseWriter, r *http.Request, provider *saml.Provider, nameID, sessionID string) error {
|
||||
mw, err := provider.GetSP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// We ignore the configured binding and only check the available SLO endpoints from the metadata.
|
||||
// For example, Azure documents that only redirect binding is possible and also only provides a redirect SLO in the metadata.
|
||||
slo := mw.ServiceProvider.GetSLOBindingLocation(crewjam_saml.HTTPRedirectBinding)
|
||||
if slo != "" {
|
||||
return samlRedirectLogoutRequest(w, r, mw.ServiceProvider, slo, nameID, sessionID)
|
||||
}
|
||||
slo = mw.ServiceProvider.GetSLOBindingLocation(crewjam_saml.HTTPPostBinding)
|
||||
return samlPostLogoutRequest(w, mw.ServiceProvider, slo, nameID, sessionID)
|
||||
}
|
||||
|
||||
func samlRedirectLogoutRequest(w http.ResponseWriter, r *http.Request, sp crewjam_saml.ServiceProvider, slo, nameID, sessionID string) error {
|
||||
lr, err := sp.MakeLogoutRequest(slo, nameID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
http.Redirect(w, r, lr.Redirect(sessionID).String(), http.StatusFound)
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
samlSLOPostTemplate = template.Must(template.New("samlSLOPost").Parse(`<!DOCTYPE html><html><body>{{.Form}}</body></html>`))
|
||||
)
|
||||
|
||||
type samlSLOPostData struct {
|
||||
Form template.HTML
|
||||
}
|
||||
|
||||
func samlPostLogoutRequest(w http.ResponseWriter, sp crewjam_saml.ServiceProvider, slo, nameID, sessionID string) error {
|
||||
lr, err := sp.MakeLogoutRequest(slo, nameID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return samlSLOPostTemplate.Execute(w, &samlSLOPostData{Form: template.HTML(lr.Post(sessionID))})
|
||||
}
|
||||
|
||||
func (l *Login) externalUserID(ctx context.Context, userID, idpID string) (string, error) {
|
||||
userIDQuery, err := query.NewIDPUserLinksUserIDSearchQuery(userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
idpIDQuery, err := query.NewIDPUserLinkIDPIDSearchQuery(idpID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
links, err := l.query.IDPUserLinks(ctx, &query.IDPUserLinksSearchQuery{Queries: []query.SearchQuery{userIDQuery, idpIDQuery}}, nil)
|
||||
if err != nil || len(links.Links) != 1 {
|
||||
return "", zerrors.ThrowPreconditionFailed(err, "LOGIN-ADK21", "Errors.User.ExternalIDP.NotFound")
|
||||
}
|
||||
return links.Links[0].ProvidedUserID, nil
|
||||
}
|
||||
|
||||
// IdPError wraps an error from an external IDP to be able to distinguish it from other errors and to display it
|
||||
// more prominent (popup style) .
|
||||
// It's used if an error occurs during the login process with an external IDP and local authentication is allowed,
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/domain/federatedlogout"
|
||||
"github.com/zitadel/zitadel/internal/form"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/static"
|
||||
@@ -60,25 +61,20 @@ const (
|
||||
DefaultLoggedOutPath = HandlerPrefix + EndpointLogoutDone
|
||||
)
|
||||
|
||||
func CreateLogin(config Config,
|
||||
func CreateLogin(
|
||||
config Config,
|
||||
command *command.Commands,
|
||||
query *query.Queries,
|
||||
authRepo *eventsourcing.EsRepository,
|
||||
staticStorage static.Storage,
|
||||
consolePath string,
|
||||
oidcAuthCallbackURL func(context.Context, string) string,
|
||||
samlAuthCallbackURL func(context.Context, string) string,
|
||||
oidcAuthCallbackURL, samlAuthCallbackURL func(context.Context, string) string,
|
||||
externalSecure bool,
|
||||
userAgentCookie,
|
||||
issuerInterceptor,
|
||||
oidcInstanceHandler,
|
||||
samlInstanceHandler,
|
||||
assetCache,
|
||||
accessHandler mux.MiddlewareFunc,
|
||||
userCodeAlg crypto.EncryptionAlgorithm,
|
||||
idpConfigAlg crypto.EncryptionAlgorithm,
|
||||
userAgentCookie, issuerInterceptor, oidcInstanceHandler, samlInstanceHandler, assetCache, accessHandler mux.MiddlewareFunc,
|
||||
userCodeAlg, idpConfigAlg crypto.EncryptionAlgorithm,
|
||||
csrfCookieKey []byte,
|
||||
cacheConnectors connector.Connectors,
|
||||
federateLogoutCache cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout],
|
||||
) (*Login, error) {
|
||||
login := &Login{
|
||||
oidcAuthCallbackURL: oidcAuthCallbackURL,
|
||||
@@ -101,7 +97,7 @@ func CreateLogin(config Config,
|
||||
login.parser = form.NewParser()
|
||||
|
||||
var err error
|
||||
login.caches, err = startCaches(context.Background(), cacheConnectors)
|
||||
login.caches, err = startCaches(context.Background(), cacheConnectors, federateLogoutCache)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -112,7 +108,11 @@ func csp() *middleware.CSP {
|
||||
csp := middleware.DefaultSCP
|
||||
csp.ObjectSrc = middleware.CSPSourceOptsSelf()
|
||||
csp.StyleSrc = csp.StyleSrc.AddNonce()
|
||||
csp.ScriptSrc = csp.ScriptSrc.AddNonce().AddHash("sha256", "AjPdJSbZmeWHnEc5ykvJFay8FTWeTeRbs9dutfZ0HqE=")
|
||||
csp.ScriptSrc = csp.ScriptSrc.AddNonce().
|
||||
// SAML POST ACS
|
||||
AddHash("sha256", "AjPdJSbZmeWHnEc5ykvJFay8FTWeTeRbs9dutfZ0HqE=").
|
||||
// SAML POST SLO
|
||||
AddHash("sha256", "4Su6mBWzEIFnH4pAGMOuaeBrstwJN4Z3pq/s1Kn4/KQ=")
|
||||
return &csp
|
||||
}
|
||||
|
||||
@@ -215,14 +215,16 @@ func (l *Login) baseURL(ctx context.Context) string {
|
||||
|
||||
type Caches struct {
|
||||
idpFormCallbacks cache.Cache[idpFormCallbackIndex, string, *idpFormCallback]
|
||||
federatedLogouts cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout]
|
||||
}
|
||||
|
||||
func startCaches(background context.Context, connectors connector.Connectors) (_ *Caches, err error) {
|
||||
func startCaches(background context.Context, connectors connector.Connectors, federateLogoutCache cache.Cache[federatedlogout.Index, string, *federatedlogout.FederatedLogout]) (_ *Caches, err error) {
|
||||
caches := new(Caches)
|
||||
caches.idpFormCallbacks, err = connector.StartCache[idpFormCallbackIndex, string, *idpFormCallback](background, []idpFormCallbackIndex{idpFormCallbackIndexRequestID}, cache.PurposeIdPFormCallback, connectors.Config.IdPFormCallbacks, connectors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
caches.federatedLogouts = federateLogoutCache
|
||||
return caches, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ const (
|
||||
EndpointExternalLogin = "/login/externalidp"
|
||||
EndpointExternalLoginCallback = "/login/externalidp/callback"
|
||||
EndpointExternalLoginCallbackFormPost = "/login/externalidp/callback/form"
|
||||
EndpointExternalLogout = "/logout/externalidp"
|
||||
EndpointSAMLACS = "/login/externalidp/saml/acs"
|
||||
EndpointJWTAuthorize = "/login/jwt/authorize"
|
||||
EndpointJWTCallback = "/login/jwt/callback"
|
||||
@@ -77,6 +78,7 @@ func CreateRouter(login *Login, interceptors ...mux.MiddlewareFunc) *mux.Router
|
||||
router.HandleFunc(EndpointExternalLogin, login.handleExternalLogin).Methods(http.MethodGet)
|
||||
router.HandleFunc(EndpointExternalLoginCallback, login.handleExternalLoginCallback).Methods(http.MethodGet)
|
||||
router.HandleFunc(EndpointExternalLoginCallbackFormPost, login.handleExternalLoginCallbackForm).Methods(http.MethodPost)
|
||||
router.HandleFunc(EndpointExternalLogout, login.handleExternalLogout).Methods(http.MethodGet)
|
||||
router.HandleFunc(EndpointSAMLACS, login.handleExternalLoginCallback).Methods(http.MethodGet)
|
||||
router.HandleFunc(EndpointSAMLACS, login.handleExternalLoginCallbackForm).Methods(http.MethodPost)
|
||||
router.HandleFunc(EndpointJWTAuthorize, login.handleJWTRequest).Methods(http.MethodGet)
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
usr_view "github.com/zitadel/zitadel/internal/user/repository/view"
|
||||
"github.com/zitadel/zitadel/internal/user/repository/view/model"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
@@ -49,6 +50,10 @@ func (repo *UserRepo) UserAgentIDBySessionID(ctx context.Context, sessionID stri
|
||||
return repo.View.UserAgentIDBySessionID(ctx, sessionID, authz.GetInstance(ctx).InstanceID())
|
||||
}
|
||||
|
||||
func (repo *UserRepo) UserSessionByID(ctx context.Context, sessionID string) (*model.UserSessionView, error) {
|
||||
return repo.View.UserSessionByID(ctx, sessionID, authz.GetInstance(ctx).InstanceID())
|
||||
}
|
||||
|
||||
func (repo *UserRepo) ActiveUserSessionsBySessionID(ctx context.Context, sessionID string) (userAgentID string, signoutSessions []command.HumanSignOutSession, err error) {
|
||||
userAgentID, sessions, err := repo.View.ActiveUserSessionsBySessionID(ctx, sessionID, authz.GetInstance(ctx).InstanceID())
|
||||
if err != nil {
|
||||
|
||||
@@ -16,6 +16,10 @@ func (v *View) UserSessionByIDs(ctx context.Context, agentID, userID, instanceID
|
||||
return view.UserSessionByIDs(ctx, v.client, agentID, userID, instanceID)
|
||||
}
|
||||
|
||||
func (v *View) UserSessionByID(ctx context.Context, userSessionID, instanceID string) (*model.UserSessionView, error) {
|
||||
return view.UserSessionByID(ctx, v.client, userSessionID, instanceID)
|
||||
}
|
||||
|
||||
func (v *View) UserSessionsByAgentID(ctx context.Context, agentID, instanceID string) ([]*model.UserSessionView, error) {
|
||||
return view.UserSessionsByAgentID(ctx, v.client, agentID, instanceID)
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/user/repository/view/model"
|
||||
)
|
||||
|
||||
type UserRepository interface {
|
||||
UserSessionsByAgentID(ctx context.Context, agentID string) (sessions []command.HumanSignOutSession, err error)
|
||||
UserAgentIDBySessionID(ctx context.Context, sessionID string) (string, error)
|
||||
UserSessionByID(ctx context.Context, sessionID string) (*model.UserSessionView, error)
|
||||
ActiveUserSessionsBySessionID(ctx context.Context, sessionID string) (userAgentID string, sessions []command.HumanSignOutSession, err error)
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -18,6 +18,7 @@ const (
|
||||
PurposeMilestones
|
||||
PurposeOrganization
|
||||
PurposeIdPFormCallback
|
||||
PurposeFederatedLogout
|
||||
)
|
||||
|
||||
// Cache stores objects with a value of type `V`.
|
||||
|
||||
+1
@@ -23,6 +23,7 @@ type CachesConfig struct {
|
||||
Milestones *cache.Config
|
||||
Organization *cache.Config
|
||||
IdPFormCallbacks *cache.Config
|
||||
FederatedLogouts *cache.Config
|
||||
}
|
||||
|
||||
type Connectors struct {
|
||||
|
||||
Vendored
+8
-4
@@ -7,11 +7,11 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const _PurposeName = "unspecifiedauthz_instancemilestonesorganizationid_p_form_callback"
|
||||
const _PurposeName = "unspecifiedauthz_instancemilestonesorganizationid_p_form_callbackfederated_logout"
|
||||
|
||||
var _PurposeIndex = [...]uint8{0, 11, 25, 35, 47, 65}
|
||||
var _PurposeIndex = [...]uint8{0, 11, 25, 35, 47, 65, 81}
|
||||
|
||||
const _PurposeLowerName = "unspecifiedauthz_instancemilestonesorganizationid_p_form_callback"
|
||||
const _PurposeLowerName = "unspecifiedauthz_instancemilestonesorganizationid_p_form_callbackfederated_logout"
|
||||
|
||||
func (i Purpose) String() string {
|
||||
if i < 0 || i >= Purpose(len(_PurposeIndex)-1) {
|
||||
@@ -29,9 +29,10 @@ func _PurposeNoOp() {
|
||||
_ = x[PurposeMilestones-(2)]
|
||||
_ = x[PurposeOrganization-(3)]
|
||||
_ = x[PurposeIdPFormCallback-(4)]
|
||||
_ = x[PurposeFederatedLogout-(5)]
|
||||
}
|
||||
|
||||
var _PurposeValues = []Purpose{PurposeUnspecified, PurposeAuthzInstance, PurposeMilestones, PurposeOrganization, PurposeIdPFormCallback}
|
||||
var _PurposeValues = []Purpose{PurposeUnspecified, PurposeAuthzInstance, PurposeMilestones, PurposeOrganization, PurposeIdPFormCallback, PurposeFederatedLogout}
|
||||
|
||||
var _PurposeNameToValueMap = map[string]Purpose{
|
||||
_PurposeName[0:11]: PurposeUnspecified,
|
||||
@@ -44,6 +45,8 @@ var _PurposeNameToValueMap = map[string]Purpose{
|
||||
_PurposeLowerName[35:47]: PurposeOrganization,
|
||||
_PurposeName[47:65]: PurposeIdPFormCallback,
|
||||
_PurposeLowerName[47:65]: PurposeIdPFormCallback,
|
||||
_PurposeName[65:81]: PurposeFederatedLogout,
|
||||
_PurposeLowerName[65:81]: PurposeFederatedLogout,
|
||||
}
|
||||
|
||||
var _PurposeNames = []string{
|
||||
@@ -52,6 +55,7 @@ var _PurposeNames = []string{
|
||||
_PurposeName[25:35],
|
||||
_PurposeName[35:47],
|
||||
_PurposeName[47:65],
|
||||
_PurposeName[65:81],
|
||||
}
|
||||
|
||||
// PurposeString retrieves an enum value from the enum constants string name.
|
||||
|
||||
@@ -122,6 +122,7 @@ type SAMLProvider struct {
|
||||
WithSignedRequest bool
|
||||
NameIDFormat *domain.SAMLNameIDFormat
|
||||
TransientMappingAttributeName string
|
||||
FederatedLogoutEnabled bool
|
||||
IDPOptions idp.Options
|
||||
}
|
||||
|
||||
|
||||
@@ -743,6 +743,7 @@ func TestCommands_AuthFromProvider_SAML(t *testing.T) {
|
||||
false,
|
||||
gu.Ptr(domain.SAMLNameIDFormatUnspecified),
|
||||
"",
|
||||
false,
|
||||
rep_idp.Options{},
|
||||
)),
|
||||
),
|
||||
@@ -763,6 +764,7 @@ func TestCommands_AuthFromProvider_SAML(t *testing.T) {
|
||||
false,
|
||||
gu.Ptr(domain.SAMLNameIDFormatUnspecified),
|
||||
"",
|
||||
false,
|
||||
rep_idp.Options{},
|
||||
)),
|
||||
),
|
||||
|
||||
@@ -1760,6 +1760,7 @@ type SAMLIDPWriteModel struct {
|
||||
WithSignedRequest bool
|
||||
NameIDFormat *domain.SAMLNameIDFormat
|
||||
TransientMappingAttributeName string
|
||||
FederatedLogoutEnabled bool
|
||||
idp.Options
|
||||
|
||||
State domain.IDPState
|
||||
@@ -1788,6 +1789,7 @@ func (wm *SAMLIDPWriteModel) reduceAddedEvent(e *idp.SAMLIDPAddedEvent) {
|
||||
wm.WithSignedRequest = e.WithSignedRequest
|
||||
wm.NameIDFormat = e.NameIDFormat
|
||||
wm.TransientMappingAttributeName = e.TransientMappingAttributeName
|
||||
wm.FederatedLogoutEnabled = e.FederatedLogoutEnabled
|
||||
wm.Options = e.Options
|
||||
wm.State = domain.IDPStateActive
|
||||
}
|
||||
@@ -1817,6 +1819,9 @@ func (wm *SAMLIDPWriteModel) reduceChangedEvent(e *idp.SAMLIDPChangedEvent) {
|
||||
if e.TransientMappingAttributeName != nil {
|
||||
wm.TransientMappingAttributeName = *e.TransientMappingAttributeName
|
||||
}
|
||||
if e.FederatedLogoutEnabled != nil {
|
||||
wm.FederatedLogoutEnabled = *e.FederatedLogoutEnabled
|
||||
}
|
||||
wm.Options.ReduceChanges(e.OptionChanges)
|
||||
}
|
||||
|
||||
@@ -1830,6 +1835,7 @@ func (wm *SAMLIDPWriteModel) NewChanges(
|
||||
withSignedRequest bool,
|
||||
nameIDFormat *domain.SAMLNameIDFormat,
|
||||
transientMappingAttributeName string,
|
||||
federatedLogoutEnabled bool,
|
||||
options idp.Options,
|
||||
) ([]idp.SAMLIDPChanges, error) {
|
||||
changes := make([]idp.SAMLIDPChanges, 0)
|
||||
@@ -1861,6 +1867,9 @@ func (wm *SAMLIDPWriteModel) NewChanges(
|
||||
if wm.TransientMappingAttributeName != transientMappingAttributeName {
|
||||
changes = append(changes, idp.ChangeSAMLTransientMappingAttributeName(transientMappingAttributeName))
|
||||
}
|
||||
if wm.FederatedLogoutEnabled != federatedLogoutEnabled {
|
||||
changes = append(changes, idp.ChangeSAMLFederatedLogoutEnabled(federatedLogoutEnabled))
|
||||
}
|
||||
opts := wm.Options.Changes(options)
|
||||
if !opts.IsZero() {
|
||||
changes = append(changes, idp.ChangeSAMLOptions(opts))
|
||||
@@ -1899,6 +1908,7 @@ func (wm *SAMLIDPWriteModel) ToProvider(callbackURL string, idpAlg crypto.Encryp
|
||||
if wm.TransientMappingAttributeName != "" {
|
||||
opts = append(opts, saml2.WithTransientMappingAttributeName(wm.TransientMappingAttributeName))
|
||||
}
|
||||
// TODO: ? if wm.FederatedLogoutEnabled
|
||||
opts = append(opts, saml2.WithCustomRequestTracker(
|
||||
requesttracker.New(
|
||||
addRequest,
|
||||
|
||||
@@ -1795,6 +1795,7 @@ func (c *Commands) prepareAddInstanceSAMLProvider(a *instance.Aggregate, writeMo
|
||||
provider.WithSignedRequest,
|
||||
provider.NameIDFormat,
|
||||
provider.TransientMappingAttributeName,
|
||||
provider.FederatedLogoutEnabled,
|
||||
provider.IDPOptions,
|
||||
),
|
||||
}, nil
|
||||
@@ -1848,6 +1849,7 @@ func (c *Commands) prepareUpdateInstanceSAMLProvider(a *instance.Aggregate, writ
|
||||
provider.WithSignedRequest,
|
||||
provider.NameIDFormat,
|
||||
provider.TransientMappingAttributeName,
|
||||
provider.FederatedLogoutEnabled,
|
||||
provider.IDPOptions,
|
||||
)
|
||||
if err != nil || event == nil {
|
||||
@@ -1893,6 +1895,7 @@ func (c *Commands) prepareRegenerateInstanceSAMLProviderCertificate(a *instance.
|
||||
writeModel.WithSignedRequest,
|
||||
writeModel.NameIDFormat,
|
||||
writeModel.TransientMappingAttributeName,
|
||||
writeModel.FederatedLogoutEnabled,
|
||||
writeModel.Options,
|
||||
)
|
||||
if err != nil || event == nil {
|
||||
|
||||
@@ -923,6 +923,7 @@ func (wm *InstanceSAMLIDPWriteModel) NewChangedEvent(
|
||||
withSignedRequest bool,
|
||||
nameIDFormat *domain.SAMLNameIDFormat,
|
||||
transientMappingAttributeName string,
|
||||
federatedLogoutEnabled bool,
|
||||
options idp.Options,
|
||||
) (*instance.SAMLIDPChangedEvent, error) {
|
||||
changes, err := wm.SAMLIDPWriteModel.NewChanges(
|
||||
@@ -935,6 +936,7 @@ func (wm *InstanceSAMLIDPWriteModel) NewChangedEvent(
|
||||
withSignedRequest,
|
||||
nameIDFormat,
|
||||
transientMappingAttributeName,
|
||||
federatedLogoutEnabled,
|
||||
options,
|
||||
)
|
||||
if err != nil || len(changes) == 0 {
|
||||
|
||||
@@ -5437,6 +5437,7 @@ func TestCommandSide_AddInstanceSAMLIDP(t *testing.T) {
|
||||
false,
|
||||
nil,
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
),
|
||||
),
|
||||
@@ -5478,6 +5479,7 @@ func TestCommandSide_AddInstanceSAMLIDP(t *testing.T) {
|
||||
true,
|
||||
gu.Ptr(domain.SAMLNameIDFormatTransient),
|
||||
"customAttribute",
|
||||
true,
|
||||
idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsLinkingAllowed: true,
|
||||
@@ -5500,6 +5502,7 @@ func TestCommandSide_AddInstanceSAMLIDP(t *testing.T) {
|
||||
WithSignedRequest: true,
|
||||
NameIDFormat: gu.Ptr(domain.SAMLNameIDFormatTransient),
|
||||
TransientMappingAttributeName: "customAttribute",
|
||||
FederatedLogoutEnabled: true,
|
||||
IDPOptions: idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsLinkingAllowed: true,
|
||||
@@ -5665,6 +5668,7 @@ func TestCommandSide_UpdateInstanceGenericSAMLIDP(t *testing.T) {
|
||||
false,
|
||||
nil,
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
)),
|
||||
),
|
||||
@@ -5703,6 +5707,7 @@ func TestCommandSide_UpdateInstanceGenericSAMLIDP(t *testing.T) {
|
||||
false,
|
||||
gu.Ptr(domain.SAMLNameIDFormatUnspecified),
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
)),
|
||||
),
|
||||
@@ -5718,6 +5723,7 @@ func TestCommandSide_UpdateInstanceGenericSAMLIDP(t *testing.T) {
|
||||
idp.ChangeSAMLWithSignedRequest(true),
|
||||
idp.ChangeSAMLNameIDFormat(gu.Ptr(domain.SAMLNameIDFormatTransient)),
|
||||
idp.ChangeSAMLTransientMappingAttributeName("customAttribute"),
|
||||
idp.ChangeSAMLFederatedLogoutEnabled(true),
|
||||
idp.ChangeSAMLOptions(idp.OptionChanges{
|
||||
IsCreationAllowed: &t,
|
||||
IsLinkingAllowed: &t,
|
||||
@@ -5742,6 +5748,7 @@ func TestCommandSide_UpdateInstanceGenericSAMLIDP(t *testing.T) {
|
||||
WithSignedRequest: true,
|
||||
NameIDFormat: gu.Ptr(domain.SAMLNameIDFormatTransient),
|
||||
TransientMappingAttributeName: "customAttribute",
|
||||
FederatedLogoutEnabled: true,
|
||||
IDPOptions: idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsLinkingAllowed: true,
|
||||
@@ -5845,6 +5852,7 @@ func TestCommandSide_RegenerateInstanceSAMLProviderCertificate(t *testing.T) {
|
||||
false,
|
||||
gu.Ptr(domain.SAMLNameIDFormatUnspecified),
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
)),
|
||||
),
|
||||
|
||||
@@ -1768,6 +1768,7 @@ func (c *Commands) prepareAddOrgSAMLProvider(a *org.Aggregate, writeModel *OrgSA
|
||||
provider.WithSignedRequest,
|
||||
provider.NameIDFormat,
|
||||
provider.TransientMappingAttributeName,
|
||||
provider.FederatedLogoutEnabled,
|
||||
provider.IDPOptions,
|
||||
),
|
||||
}, nil
|
||||
@@ -1821,6 +1822,7 @@ func (c *Commands) prepareUpdateOrgSAMLProvider(a *org.Aggregate, writeModel *Or
|
||||
provider.WithSignedRequest,
|
||||
provider.NameIDFormat,
|
||||
provider.TransientMappingAttributeName,
|
||||
provider.FederatedLogoutEnabled,
|
||||
provider.IDPOptions,
|
||||
)
|
||||
if err != nil || event == nil {
|
||||
@@ -1866,6 +1868,7 @@ func (c *Commands) prepareRegenerateOrgSAMLProviderCertificate(a *org.Aggregate,
|
||||
writeModel.WithSignedRequest,
|
||||
writeModel.NameIDFormat,
|
||||
writeModel.TransientMappingAttributeName,
|
||||
writeModel.FederatedLogoutEnabled,
|
||||
writeModel.Options,
|
||||
)
|
||||
if err != nil || event == nil {
|
||||
|
||||
@@ -935,6 +935,7 @@ func (wm *OrgSAMLIDPWriteModel) NewChangedEvent(
|
||||
withSignedRequest bool,
|
||||
nameIDFormat *domain.SAMLNameIDFormat,
|
||||
transientMappingAttributeName string,
|
||||
federatedLogoutEnabled bool,
|
||||
options idp.Options,
|
||||
) (*org.SAMLIDPChangedEvent, error) {
|
||||
changes, err := wm.SAMLIDPWriteModel.NewChanges(
|
||||
@@ -947,6 +948,7 @@ func (wm *OrgSAMLIDPWriteModel) NewChangedEvent(
|
||||
withSignedRequest,
|
||||
nameIDFormat,
|
||||
transientMappingAttributeName,
|
||||
federatedLogoutEnabled,
|
||||
options,
|
||||
)
|
||||
if err != nil || len(changes) == 0 {
|
||||
|
||||
@@ -5519,6 +5519,7 @@ func TestCommandSide_AddOrgSAMLIDP(t *testing.T) {
|
||||
false,
|
||||
nil,
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
),
|
||||
),
|
||||
@@ -5560,6 +5561,7 @@ func TestCommandSide_AddOrgSAMLIDP(t *testing.T) {
|
||||
true,
|
||||
gu.Ptr(domain.SAMLNameIDFormatTransient),
|
||||
"customAttribute",
|
||||
true,
|
||||
idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsLinkingAllowed: true,
|
||||
@@ -5583,6 +5585,7 @@ func TestCommandSide_AddOrgSAMLIDP(t *testing.T) {
|
||||
WithSignedRequest: true,
|
||||
NameIDFormat: gu.Ptr(domain.SAMLNameIDFormatTransient),
|
||||
TransientMappingAttributeName: "customAttribute",
|
||||
FederatedLogoutEnabled: true,
|
||||
IDPOptions: idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsLinkingAllowed: true,
|
||||
@@ -5756,6 +5759,7 @@ func TestCommandSide_UpdateOrgSAMLIDP(t *testing.T) {
|
||||
false,
|
||||
nil,
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
)),
|
||||
),
|
||||
@@ -5795,6 +5799,7 @@ func TestCommandSide_UpdateOrgSAMLIDP(t *testing.T) {
|
||||
false,
|
||||
gu.Ptr(domain.SAMLNameIDFormatUnspecified),
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
)),
|
||||
),
|
||||
@@ -5810,6 +5815,7 @@ func TestCommandSide_UpdateOrgSAMLIDP(t *testing.T) {
|
||||
idp.ChangeSAMLWithSignedRequest(true),
|
||||
idp.ChangeSAMLNameIDFormat(gu.Ptr(domain.SAMLNameIDFormatTransient)),
|
||||
idp.ChangeSAMLTransientMappingAttributeName("customAttribute"),
|
||||
idp.ChangeSAMLFederatedLogoutEnabled(true),
|
||||
idp.ChangeSAMLOptions(idp.OptionChanges{
|
||||
IsCreationAllowed: &t,
|
||||
IsLinkingAllowed: &t,
|
||||
@@ -5835,6 +5841,7 @@ func TestCommandSide_UpdateOrgSAMLIDP(t *testing.T) {
|
||||
WithSignedRequest: true,
|
||||
NameIDFormat: gu.Ptr(domain.SAMLNameIDFormatTransient),
|
||||
TransientMappingAttributeName: "customAttribute",
|
||||
FederatedLogoutEnabled: true,
|
||||
IDPOptions: idp.Options{
|
||||
IsCreationAllowed: true,
|
||||
IsLinkingAllowed: true,
|
||||
@@ -5943,6 +5950,7 @@ func TestCommandSide_RegenerateOrgSAMLProviderCertificate(t *testing.T) {
|
||||
false,
|
||||
gu.Ptr(domain.SAMLNameIDFormatUnspecified),
|
||||
"",
|
||||
false,
|
||||
idp.Options{},
|
||||
)),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package federatedlogout
|
||||
|
||||
type Index int
|
||||
|
||||
const (
|
||||
IndexUnspecified Index = iota
|
||||
IndexRequestID
|
||||
)
|
||||
|
||||
type FederatedLogout struct {
|
||||
InstanceID string
|
||||
FingerPrintID string
|
||||
SessionID string
|
||||
IDPID string
|
||||
UserID string
|
||||
PostLogoutRedirectURI string
|
||||
State State
|
||||
}
|
||||
|
||||
// Keys implements cache.Entry
|
||||
func (c *FederatedLogout) Keys(i Index) []string {
|
||||
if i == IndexRequestID {
|
||||
return []string{Key(c.InstanceID, c.SessionID)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Key(instanceID, sessionID string) string {
|
||||
return instanceID + "-" + sessionID
|
||||
}
|
||||
|
||||
type State int
|
||||
|
||||
const (
|
||||
StateCreated State = iota
|
||||
StateRedirected
|
||||
)
|
||||
@@ -165,6 +165,7 @@ type SAMLIDPTemplate struct {
|
||||
WithSignedRequest bool
|
||||
NameIDFormat sql.Null[domain.SAMLNameIDFormat]
|
||||
TransientMappingAttributeName string
|
||||
FederatedLogoutEnabled bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -724,6 +725,10 @@ var (
|
||||
name: projection.SAMLTransientMappingAttributeName,
|
||||
table: samlIdpTemplateTable,
|
||||
}
|
||||
SAMLFederatedLogoutEnabledCol = Column{
|
||||
name: projection.SAMLFederatedLogoutEnabled,
|
||||
table: samlIdpTemplateTable,
|
||||
}
|
||||
)
|
||||
|
||||
// IDPTemplateByID searches for the requested id with permission check if necessary
|
||||
@@ -948,6 +953,7 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
SAMLWithSignedRequestCol.identifier(),
|
||||
SAMLNameIDFormatCol.identifier(),
|
||||
SAMLTransientMappingAttributeNameCol.identifier(),
|
||||
SAMLFederatedLogoutEnabledCol.identifier(),
|
||||
// ldap
|
||||
LDAPIDCol.identifier(),
|
||||
LDAPServersCol.identifier(),
|
||||
@@ -1067,6 +1073,7 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
samlWithSignedRequest := sql.NullBool{}
|
||||
samlNameIDFormat := sql.Null[domain.SAMLNameIDFormat]{}
|
||||
samlTransientMappingAttributeName := sql.NullString{}
|
||||
samlFederatedLogoutEnabled := sql.NullBool{}
|
||||
|
||||
ldapID := sql.NullString{}
|
||||
ldapServers := database.TextArray[string]{}
|
||||
@@ -1184,6 +1191,7 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
&samlWithSignedRequest,
|
||||
&samlNameIDFormat,
|
||||
&samlTransientMappingAttributeName,
|
||||
&samlFederatedLogoutEnabled,
|
||||
// ldap
|
||||
&ldapID,
|
||||
&ldapServers,
|
||||
@@ -1323,6 +1331,7 @@ func prepareIDPTemplateByIDQuery() (sq.SelectBuilder, func(*sql.Row) (*IDPTempla
|
||||
WithSignedRequest: samlWithSignedRequest.Bool,
|
||||
NameIDFormat: samlNameIDFormat,
|
||||
TransientMappingAttributeName: samlTransientMappingAttributeName.String,
|
||||
FederatedLogoutEnabled: samlFederatedLogoutEnabled.Bool,
|
||||
}
|
||||
}
|
||||
if ldapID.Valid {
|
||||
@@ -1456,6 +1465,7 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
SAMLWithSignedRequestCol.identifier(),
|
||||
SAMLNameIDFormatCol.identifier(),
|
||||
SAMLTransientMappingAttributeNameCol.identifier(),
|
||||
SAMLFederatedLogoutEnabledCol.identifier(),
|
||||
// ldap
|
||||
LDAPIDCol.identifier(),
|
||||
LDAPServersCol.identifier(),
|
||||
@@ -1580,6 +1590,7 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
samlWithSignedRequest := sql.NullBool{}
|
||||
samlNameIDFormat := sql.Null[domain.SAMLNameIDFormat]{}
|
||||
samlTransientMappingAttributeName := sql.NullString{}
|
||||
samlFederatedLogoutEnabled := sql.NullBool{}
|
||||
|
||||
ldapID := sql.NullString{}
|
||||
ldapServers := database.TextArray[string]{}
|
||||
@@ -1697,6 +1708,7 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
&samlWithSignedRequest,
|
||||
&samlNameIDFormat,
|
||||
&samlTransientMappingAttributeName,
|
||||
&samlFederatedLogoutEnabled,
|
||||
// ldap
|
||||
&ldapID,
|
||||
&ldapServers,
|
||||
@@ -1835,6 +1847,7 @@ func prepareIDPTemplatesQuery() (sq.SelectBuilder, func(*sql.Rows) (*IDPTemplate
|
||||
WithSignedRequest: samlWithSignedRequest.Bool,
|
||||
NameIDFormat: samlNameIDFormat,
|
||||
TransientMappingAttributeName: samlTransientMappingAttributeName.String,
|
||||
FederatedLogoutEnabled: samlFederatedLogoutEnabled.Bool,
|
||||
}
|
||||
}
|
||||
if ldapID.Valid {
|
||||
|
||||
@@ -99,6 +99,7 @@ var (
|
||||
` projections.idp_templates6_saml.with_signed_request,` +
|
||||
` projections.idp_templates6_saml.name_id_format,` +
|
||||
` projections.idp_templates6_saml.transient_mapping_attribute_name,` +
|
||||
` projections.idp_templates6_saml.federated_logout_enabled,` +
|
||||
// ldap
|
||||
` projections.idp_templates6_ldap2.idp_id,` +
|
||||
` projections.idp_templates6_ldap2.servers,` +
|
||||
@@ -228,6 +229,7 @@ var (
|
||||
"with_signed_request",
|
||||
"name_id_format",
|
||||
"transient_mapping_attribute_name",
|
||||
"federated_logout_enabled",
|
||||
// ldap config
|
||||
"idp_id",
|
||||
"servers",
|
||||
@@ -344,6 +346,7 @@ var (
|
||||
` projections.idp_templates6_saml.with_signed_request,` +
|
||||
` projections.idp_templates6_saml.name_id_format,` +
|
||||
` projections.idp_templates6_saml.transient_mapping_attribute_name,` +
|
||||
` projections.idp_templates6_saml.federated_logout_enabled,` +
|
||||
// ldap
|
||||
` projections.idp_templates6_ldap2.idp_id,` +
|
||||
` projections.idp_templates6_ldap2.servers,` +
|
||||
@@ -474,6 +477,7 @@ var (
|
||||
"with_signed_request",
|
||||
"name_id_format",
|
||||
"transient_mapping_attribute_name",
|
||||
"federated_logout_enabled",
|
||||
// ldap config
|
||||
"idp_id",
|
||||
"servers",
|
||||
@@ -630,6 +634,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -784,6 +789,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -936,6 +942,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -1086,6 +1093,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -1235,6 +1243,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -1384,6 +1393,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -1534,6 +1544,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -1683,6 +1694,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
false,
|
||||
domain.SAMLNameIDFormatTransient,
|
||||
"customAttribute",
|
||||
true,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -1742,6 +1754,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
WithSignedRequest: false,
|
||||
NameIDFormat: sql.Null[domain.SAMLNameIDFormat]{V: domain.SAMLNameIDFormatTransient, Valid: true},
|
||||
TransientMappingAttributeName: "customAttribute",
|
||||
FederatedLogoutEnabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1836,6 +1849,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
"idp-id",
|
||||
database.TextArray[string]{"server"},
|
||||
@@ -2006,6 +2020,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -2157,6 +2172,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -2336,6 +2352,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
"idp-id",
|
||||
database.TextArray[string]{"server"},
|
||||
@@ -2515,6 +2532,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -2667,6 +2685,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
"idp-id-ldap",
|
||||
database.TextArray[string]{"server"},
|
||||
@@ -2784,6 +2803,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
false,
|
||||
domain.SAMLNameIDFormatTransient,
|
||||
"customAttribute",
|
||||
true,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -2901,6 +2921,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -3018,6 +3039,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -3135,6 +3157,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -3252,6 +3275,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
// ldap config
|
||||
nil,
|
||||
nil,
|
||||
@@ -3360,6 +3384,7 @@ func Test_IDPTemplateTemplatesPrepares(t *testing.T) {
|
||||
WithSignedRequest: false,
|
||||
NameIDFormat: sql.Null[domain.SAMLNameIDFormat]{V: domain.SAMLNameIDFormatTransient, Valid: true},
|
||||
TransientMappingAttributeName: "customAttribute",
|
||||
FederatedLogoutEnabled: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -173,6 +173,7 @@ const (
|
||||
SAMLWithSignedRequestCol = "with_signed_request"
|
||||
SAMLNameIDFormatCol = "name_id_format"
|
||||
SAMLTransientMappingAttributeName = "transient_mapping_attribute_name"
|
||||
SAMLFederatedLogoutEnabled = "federated_logout_enabled"
|
||||
)
|
||||
|
||||
type idpTemplateProjection struct{}
|
||||
@@ -377,6 +378,7 @@ func (*idpTemplateProjection) Init() *old_handler.Check {
|
||||
handler.NewColumn(SAMLWithSignedRequestCol, handler.ColumnTypeBool, handler.Nullable()),
|
||||
handler.NewColumn(SAMLNameIDFormatCol, handler.ColumnTypeEnum, handler.Nullable()),
|
||||
handler.NewColumn(SAMLTransientMappingAttributeName, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(SAMLFederatedLogoutEnabled, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
handler.NewPrimaryKey(SAMLInstanceIDCol, SAMLIDCol),
|
||||
IDPTemplateSAMLSuffix,
|
||||
@@ -1990,6 +1992,7 @@ func (p *idpTemplateProjection) reduceSAMLIDPAdded(event eventstore.Event) (*han
|
||||
handler.NewCol(SAMLBindingCol, idpEvent.Binding),
|
||||
handler.NewCol(SAMLWithSignedRequestCol, idpEvent.WithSignedRequest),
|
||||
handler.NewCol(SAMLTransientMappingAttributeName, idpEvent.TransientMappingAttributeName),
|
||||
handler.NewCol(SAMLFederatedLogoutEnabled, idpEvent.FederatedLogoutEnabled),
|
||||
}
|
||||
if idpEvent.NameIDFormat != nil {
|
||||
columns = append(columns, handler.NewCol(SAMLNameIDFormatCol, *idpEvent.NameIDFormat))
|
||||
@@ -2525,5 +2528,8 @@ func reduceSAMLIDPChangedColumns(idpEvent idp.SAMLIDPChangedEvent) []handler.Col
|
||||
if idpEvent.TransientMappingAttributeName != nil {
|
||||
SAMLCols = append(SAMLCols, handler.NewCol(SAMLTransientMappingAttributeName, *idpEvent.TransientMappingAttributeName))
|
||||
}
|
||||
if idpEvent.FederatedLogoutEnabled != nil {
|
||||
SAMLCols = append(SAMLCols, handler.NewCol(SAMLFederatedLogoutEnabled, *idpEvent.FederatedLogoutEnabled))
|
||||
}
|
||||
return SAMLCols
|
||||
}
|
||||
|
||||
@@ -2793,7 +2793,8 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true,
|
||||
"autoLinkingOption": 1
|
||||
"autoLinkingOption": 1,
|
||||
"federatedLogoutEnabled": true
|
||||
}`),
|
||||
), instance.SAMLIDPAddedEventMapper),
|
||||
},
|
||||
@@ -2824,7 +2825,7 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates6_saml (idp_id, instance_id, metadata, key, certificate, binding, with_signed_request, transient_mapping_attribute_name, name_id_format) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.idp_templates6_saml (idp_id, instance_id, metadata, key, certificate, binding, with_signed_request, transient_mapping_attribute_name, federated_logout_enabled, name_id_format) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -2834,6 +2835,7 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
"binding",
|
||||
true,
|
||||
"customAttribute",
|
||||
true,
|
||||
domain.SAMLNameIDFormatTransient,
|
||||
},
|
||||
},
|
||||
@@ -2865,7 +2867,8 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true,
|
||||
"autoLinkingOption": 1
|
||||
"autoLinkingOption": 1,
|
||||
"federatedLogoutEnabled": true
|
||||
}`),
|
||||
), org.SAMLIDPAddedEventMapper),
|
||||
},
|
||||
@@ -2896,7 +2899,7 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.idp_templates6_saml (idp_id, instance_id, metadata, key, certificate, binding, with_signed_request, transient_mapping_attribute_name, name_id_format) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.idp_templates6_saml (idp_id, instance_id, metadata, key, certificate, binding, with_signed_request, transient_mapping_attribute_name, federated_logout_enabled, name_id_format) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedArgs: []interface{}{
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
@@ -2906,6 +2909,7 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
"binding",
|
||||
true,
|
||||
"customAttribute",
|
||||
true,
|
||||
domain.SAMLNameIDFormatTransient,
|
||||
},
|
||||
},
|
||||
@@ -2976,7 +2980,8 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
"isLinkingAllowed": true,
|
||||
"isAutoCreation": true,
|
||||
"isAutoUpdate": true,
|
||||
"autoLinkingOption": 1
|
||||
"autoLinkingOption": 1,
|
||||
"federatedLogoutEnabled": true
|
||||
}`),
|
||||
), instance.SAMLIDPChangedEventMapper),
|
||||
},
|
||||
@@ -3002,13 +3007,14 @@ func TestIDPTemplateProjection_reducesSAML(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.idp_templates6_saml SET (metadata, key, certificate, binding, with_signed_request) = ($1, $2, $3, $4, $5) WHERE (idp_id = $6) AND (instance_id = $7)",
|
||||
expectedStmt: "UPDATE projections.idp_templates6_saml SET (metadata, key, certificate, binding, with_signed_request, federated_logout_enabled) = ($1, $2, $3, $4, $5, $6) WHERE (idp_id = $7) AND (instance_id = $8)",
|
||||
expectedArgs: []interface{}{
|
||||
[]byte("metadata"),
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
"binding",
|
||||
true,
|
||||
true,
|
||||
"idp-id",
|
||||
"instance-id",
|
||||
},
|
||||
|
||||
@@ -19,6 +19,7 @@ type SAMLIDPAddedEvent struct {
|
||||
WithSignedRequest bool `json:"withSignedRequest,omitempty"`
|
||||
NameIDFormat *domain.SAMLNameIDFormat `json:"nameIDFormat,omitempty"`
|
||||
TransientMappingAttributeName string `json:"transientMappingAttributeName,omitempty"`
|
||||
FederatedLogoutEnabled bool `json:"federatedLogoutEnabled,omitempty"`
|
||||
Options
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ func NewSAMLIDPAddedEvent(
|
||||
withSignedRequest bool,
|
||||
nameIDFormat *domain.SAMLNameIDFormat,
|
||||
transientMappingAttributeName string,
|
||||
federatedLogoutEnabled bool,
|
||||
options Options,
|
||||
) *SAMLIDPAddedEvent {
|
||||
return &SAMLIDPAddedEvent{
|
||||
@@ -46,6 +48,7 @@ func NewSAMLIDPAddedEvent(
|
||||
WithSignedRequest: withSignedRequest,
|
||||
NameIDFormat: nameIDFormat,
|
||||
TransientMappingAttributeName: transientMappingAttributeName,
|
||||
FederatedLogoutEnabled: federatedLogoutEnabled,
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
@@ -83,6 +86,7 @@ type SAMLIDPChangedEvent struct {
|
||||
WithSignedRequest *bool `json:"withSignedRequest,omitempty"`
|
||||
NameIDFormat *domain.SAMLNameIDFormat `json:"nameIDFormat,omitempty"`
|
||||
TransientMappingAttributeName *string `json:"transientMappingAttributeName,omitempty"`
|
||||
FederatedLogoutEnabled *bool `json:"federatedLogoutEnabled,omitempty"`
|
||||
OptionChanges
|
||||
}
|
||||
|
||||
@@ -154,6 +158,12 @@ func ChangeSAMLTransientMappingAttributeName(name string) func(*SAMLIDPChangedEv
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeSAMLFederatedLogoutEnabled(federatedLogoutEnabled bool) func(*SAMLIDPChangedEvent) {
|
||||
return func(e *SAMLIDPChangedEvent) {
|
||||
e.FederatedLogoutEnabled = &federatedLogoutEnabled
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeSAMLOptions(options OptionChanges) func(*SAMLIDPChangedEvent) {
|
||||
return func(e *SAMLIDPChangedEvent) {
|
||||
e.OptionChanges = options
|
||||
|
||||
@@ -1024,6 +1024,7 @@ func NewSAMLIDPAddedEvent(
|
||||
withSignedRequest bool,
|
||||
nameIDFormat *domain.SAMLNameIDFormat,
|
||||
transientMappingAttributeName string,
|
||||
federatedLogoutEnabled bool,
|
||||
options idp.Options,
|
||||
) *SAMLIDPAddedEvent {
|
||||
return &SAMLIDPAddedEvent{
|
||||
@@ -1042,6 +1043,7 @@ func NewSAMLIDPAddedEvent(
|
||||
withSignedRequest,
|
||||
nameIDFormat,
|
||||
transientMappingAttributeName,
|
||||
federatedLogoutEnabled,
|
||||
options,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -1025,6 +1025,7 @@ func NewSAMLIDPAddedEvent(
|
||||
withSignedRequest bool,
|
||||
nameIDFormat *domain.SAMLNameIDFormat,
|
||||
transientMappingAttributeName string,
|
||||
federatedLogoutEnabled bool,
|
||||
options idp.Options,
|
||||
) *SAMLIDPAddedEvent {
|
||||
|
||||
@@ -1044,6 +1045,7 @@ func NewSAMLIDPAddedEvent(
|
||||
withSignedRequest,
|
||||
nameIDFormat,
|
||||
transientMappingAttributeName,
|
||||
federatedLogoutEnabled,
|
||||
options,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
SELECT s.creation_date,
|
||||
s.change_date,
|
||||
s.resource_owner,
|
||||
s.state,
|
||||
s.user_agent_id,
|
||||
s.user_id,
|
||||
u.username,
|
||||
l.login_name,
|
||||
h.display_name,
|
||||
h.avatar_key,
|
||||
s.selected_idp_config_id,
|
||||
s.password_verification,
|
||||
s.passwordless_verification,
|
||||
s.external_login_verification,
|
||||
s.second_factor_verification,
|
||||
s.second_factor_verification_type,
|
||||
s.multi_factor_verification,
|
||||
s.multi_factor_verification_type,
|
||||
s.sequence,
|
||||
s.instance_id,
|
||||
s.id
|
||||
FROM auth.user_sessions s
|
||||
LEFT JOIN projections.users14 u ON s.user_id = u.id AND s.instance_id = u.instance_id
|
||||
LEFT JOIN projections.users14_humans h ON s.user_id = h.user_id AND s.instance_id = h.instance_id
|
||||
LEFT JOIN projections.login_names3 l ON s.user_id = l.user_id AND s.instance_id = l.instance_id AND l.is_primary = true
|
||||
WHERE (s.id = $1)
|
||||
AND (s.instance_id = $2)
|
||||
LIMIT 1
|
||||
;
|
||||
@@ -12,6 +12,9 @@ import (
|
||||
)
|
||||
|
||||
//go:embed user_session_by_id.sql
|
||||
var userSessionByIDsQuery string
|
||||
|
||||
//go:embed user_session.sql
|
||||
var userSessionByIDQuery string
|
||||
|
||||
//go:embed user_sessions_by_user_agent.sql
|
||||
@@ -30,7 +33,7 @@ func UserSessionByIDs(ctx context.Context, db *database.DB, agentID, userID, ins
|
||||
userSession, err = scanUserSession(row)
|
||||
return err
|
||||
},
|
||||
userSessionByIDQuery,
|
||||
userSessionByIDsQuery,
|
||||
agentID,
|
||||
userID,
|
||||
instanceID,
|
||||
@@ -38,6 +41,20 @@ func UserSessionByIDs(ctx context.Context, db *database.DB, agentID, userID, ins
|
||||
return userSession, err
|
||||
}
|
||||
|
||||
func UserSessionByID(ctx context.Context, db *database.DB, userSessionID, instanceID string) (userSession *model.UserSessionView, err error) {
|
||||
err = db.QueryRowContext(
|
||||
ctx,
|
||||
func(row *sql.Row) error {
|
||||
userSession, err = scanUserSession(row)
|
||||
return err
|
||||
},
|
||||
userSessionByIDQuery,
|
||||
userSessionID,
|
||||
instanceID,
|
||||
)
|
||||
return userSession, err
|
||||
}
|
||||
|
||||
func UserSessionsByAgentID(ctx context.Context, db *database.DB, agentID, instanceID string) (userSessions []*model.UserSessionView, err error) {
|
||||
err = db.QueryContext(
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user