Skip to content

Commit 2ed2ad8

Browse files
committed
[stash]
1 parent 666be30 commit 2ed2ad8

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

services/spar/src/Spar/API.hs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ import qualified URI.ByteString as URI
107107
import Wire.API.Routes.Internal.Spar
108108
import Wire.API.Routes.Named
109109
import Wire.API.Routes.Public.Spar
110+
import Wire.API.Servant.Tentatively
111+
import qualified Wire.API.Servant.Tentatively as Tentatively
110112
import Wire.API.Team.Member (HiddenPerm (CreateUpdateDeleteIdp, ReadIdp))
111113
import Wire.API.User
112114
import Wire.API.User.IdentityProvider
@@ -122,7 +124,9 @@ app ctx0 req cont = do
122124
let rid = getRequestId defaultRequestIdHeaderName req
123125
let ctx = ctx0 {sparCtxRequestId = rid}
124126
SAML.setHttpCachePolicy
125-
( serve
127+
( serve -- TODO: "instance MimeUnrender JSON (Tentatively IdPMetadataInfo)" missing,
128+
-- probably because IdPMetadataInfo doesn't have one. is this something we didn't
129+
-- need before?
126130
(Proxy @SparAPI)
127131
(hoistServer (Proxy @SparAPI) (runSparToHandler ctx) (api $ sparCtxOpts ctx) :: Server SparAPI)
128132
)
@@ -607,13 +611,14 @@ idpCreate ::
607611
Member (Error SparError) r
608612
) =>
609613
Maybe UserId ->
610-
IdPMetadataInfo ->
614+
Tentatively IdPMetadataInfo ->
611615
Maybe SAML.IdPId ->
612616
Maybe WireIdPAPIVersion ->
613617
Maybe (Range 1 32 Text) ->
614618
Sem r IdP
615-
idpCreate zusr (IdPMetadataValue rawIdpMetadata idpmeta) mReplaces (fromMaybe defWireIdPAPIVersion -> apiversion) mHandle = withDebugLog "idpCreateXML" (Just . show . (^. SAML.idpId)) $ do
619+
idpCreate zusr tentativeMetaData mReplaces (fromMaybe defWireIdPAPIVersion -> apiversion) mHandle = withDebugLog "idpCreateXML" (Just . show . (^. SAML.idpId)) $ do
616620
teamid <- Brig.getZUsrCheckPerm zusr CreateUpdateDeleteIdp
621+
IdPMetadataValue rawIdpMetadata idpmeta <- forceIt tentativeMetaData
617622
GalleyAccess.assertSSOEnabled teamid
618623
idp <-
619624
maybe (IdPConfigStore.newHandle teamid) (pure . IdPHandle . fromRange) mHandle
@@ -624,6 +629,10 @@ idpCreate zusr (IdPMetadataValue rawIdpMetadata idpmeta) mReplaces (fromMaybe de
624629
IdPConfigStore.setReplacedBy (Replaced replaces) (Replacing (idp ^. SAML.idpId))
625630
pure idp
626631

632+
-- what should we give you, forceIt? an error action? a function that takes an http error and throws it in the locally appropriate fashion?
633+
forceIt :: (Applicative m) => Tentatively a -> m a
634+
forceIt = undefined -- t e = Tentatively.forceTentatively t & either e pure
635+
627636
idpCreateV7 ::
628637
( Member Random r,
629638
Member (Logger String) r,
@@ -734,14 +743,14 @@ idpUpdate ::
734743
Member (Error SparError) r
735744
) =>
736745
Maybe UserId ->
737-
IdPMetadataInfo ->
746+
Tentatively IdPMetadataInfo ->
738747
SAML.IdPId ->
739748
Maybe (Range 1 32 Text) ->
740749
Sem r IdP
741-
idpUpdate zusr (IdPMetadataValue raw xml) idpid mHandle = withDebugLog "idpUpdateCore" (Just . show . (^. SAML.idpId)) $ do
742-
(teamid, idp) <- validateIdPUpdate zusr idpmeta idpid
750+
idpUpdate zusr idpmeta idpid mHandle = withDebugLog "idpUpdateCore" (Just . show . (^. SAML.idpId)) $ do
751+
(idpText, teamid, idp) <- validateIdPUpdate zusr idpmeta idpid
743752
GalleyAccess.assertSSOEnabled teamid
744-
IdPRawMetadataStore.store (idp ^. SAML.idpId) raw
753+
IdPRawMetadataStore.store (idp ^. SAML.idpId) idpText
745754
let idp' :: IdP = case mHandle of
746755
Just idpHandle -> idp & (SAML.idpExtraInfo . handle) .~ IdPHandle (fromRange idpHandle)
747756
Nothing -> idp
@@ -772,12 +781,16 @@ validateIdPUpdate ::
772781
Member (Error SparError) r
773782
) =>
774783
Maybe UserId ->
775-
SAML.IdPMetadata ->
784+
Tentatively IdPMetadataInfo ->
776785
SAML.IdPId ->
777-
m (TeamId, IdP)
778-
validateIdPUpdate zusr _idpMetadata _idpId = withDebugLog "validateIdPUpdate" (Just . show . (_2 %~ (^. SAML.idpId))) $ do
786+
m (Text, TeamId, IdP)
787+
validateIdPUpdate zusr tentativeIdpMeta _idpId = withDebugLog "validateIdPUpdate" (const $ Just $ show _idpId) $ do
788+
-- access control
779789
previousIdP <- IdPConfigStore.getConfig _idpId
780790
(_, teamId) <- authorizeIdP zusr previousIdP
791+
792+
-- parse xml & continue with application logic.
793+
IdPMetadataValue idpText _idpMetadata <- forceIt tentativeIdpMeta
781794
unless (previousIdP ^. SAML.idpExtraInfo . team == teamId) $
782795
throw errUnknownIdP
783796
_idpExtraInfo <- do
@@ -807,7 +820,7 @@ validateIdPUpdate zusr _idpMetadata _idpId = withDebugLog "validateIdPUpdate" (J
807820

808821
let requri = _idpMetadata ^. SAML.edRequestURI
809822
enforceHttps requri
810-
pure (teamId, SAML.IdPConfig {..})
823+
pure (idpText, teamId, SAML.IdPConfig {..})
811824
where
812825
-- If the new issuer was previously used, it has to be removed from the list of old issuers,
813826
-- to prevent it from getting deleted in a later step

services/spar/src/Spar/Orphans.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,8 @@ module Spar.Orphans
2424
)
2525
where
2626

27-
import qualified Data.Text.Lazy as LText
2827
import Imports
29-
import qualified SAML2.WebSSO as SAML
3028
import Servant (MimeRender (..), PlainText)
31-
import Servant.API.Extended
32-
import Spar.Error
33-
import Wire.API.User.IdentityProvider (IdPMetadataInfo)
3429

3530
instance MimeRender PlainText Void where
3631
mimeRender _ = error "instance MimeRender HTML Void: impossible"
37-
38-
instance MakeCustomError "wai-error" IdPMetadataInfo where
39-
makeCustomError = sparToServerError . SAML.CustomError . SparNewIdPBadMetadata . LText.pack

0 commit comments

Comments
 (0)