Skip to content
Closed
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
69ca5d3
WPB-1583: Setting up a type and assocaited type family for valid repr…
lepsa Aug 25, 2023
12a7fe5
WPB-1583: Minor changes based on Matthias' feedback
lepsa Aug 25, 2023
6d5a73f
No password in ExternalIdF, that's brig's business!
fisx Aug 27, 2023
5cd6889
Renames, fix logic of ExternalIdTag.
fisx Aug 27, 2023
5ca7c13
Make do without UserSSOId.
fisx Aug 27, 2023
8162a3e
Make do without UserSSOId (cont.)
fisx Aug 27, 2023
861b0a7
ormolu
fisx Aug 27, 2023
8387341
Make do without UserSSOId (cont.)
fisx Aug 27, 2023
63d001d
scope scim external id in team id!
fisx Aug 27, 2023
c39937a
email in UAuthId must come with source info.
fisx Aug 27, 2023
87fb121
WPB-1583: My thoughts and updates to code to help the compiler.
lepsa Aug 28, 2023
ae4dbac
WPB-1583: Small fixes, trying to generalise some code with lenses
lepsa Aug 28, 2023
35ff821
Filling in some more holes
lepsa Aug 28, 2023
1c08105
Re-order code.
fisx Aug 29, 2023
ab41cdb
Fix UserIdentityComponents type.
fisx Aug 29, 2023
fb93b7c
Move code around.
fisx Aug 29, 2023
159ae73
WIP
lepsa Aug 30, 2023
fa4fdaa
Merge branch 'WPB-1583' of github.com:lepsa/wire-server into WPB-1583
lepsa Aug 30, 2023
0d29aed
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Sep 4, 2023
489a327
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Sep 5, 2023
f623d91
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Sep 7, 2023
dc152ed
enable failing test case.
fisx Sep 7, 2023
03c833c
Merge branch 'develop' into WPB-1583
elland Sep 20, 2023
e607bd6
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Sep 26, 2023
d306392
...
fisx Sep 26, 2023
6e2567d
...
fisx Sep 26, 2023
b112ddb
...
fisx Sep 26, 2023
d8d8d91
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Sep 26, 2023
47c282b
...
fisx Sep 26, 2023
593908f
...
fisx Sep 26, 2023
a631b5d
...
fisx Sep 27, 2023
718cd7a
...
fisx Sep 27, 2023
cc65cfd
Merge branch 'develop' into WPB-1583
fisx Oct 16, 2023
e518160
..
fisx Oct 16, 2023
6185529
..
fisx Oct 16, 2023
f319397
...
fisx Oct 16, 2023
6a855b8
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Oct 16, 2023
68692eb
...
fisx Oct 16, 2023
312606a
...
fisx Oct 16, 2023
ef4a084
...
fisx Oct 18, 2023
3217875
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Oct 18, 2023
7430da3
...
fisx Oct 18, 2023
e8a5608
...
fisx Oct 18, 2023
2925694
[stash]
fisx Oct 18, 2023
c2b9e71
Revert "[stash]"
fisx Oct 18, 2023
f33dcc2
...
fisx Oct 19, 2023
a44dd13
...
fisx Oct 19, 2023
aee455c
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Oct 19, 2023
da72d18
...
fisx Oct 19, 2023
d82fded
wire-api golden tests.
fisx Oct 20, 2023
6f80e24
wire-api unit tests.
fisx Oct 20, 2023
2960481
UserIdentityComponents
fisx Oct 20, 2023
68aa18e
[stash]
fisx Oct 20, 2023
24cbe85
Revert "[stash]"
fisx Oct 20, 2023
f3b0f40
...
fisx Oct 20, 2023
1b7c3ba
...
fisx Oct 20, 2023
4eb210c
[stash]
fisx Oct 20, 2023
5b984f2
Revert "[stash]"
fisx Oct 20, 2023
3e4f771
...
fisx Oct 26, 2023
2310990
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Oct 26, 2023
3a0e325
...
fisx Oct 26, 2023
bf4989a
...
fisx Oct 26, 2023
1e78ac2
Revert "..."
fisx Oct 26, 2023
6ab8db1
...
fisx Oct 26, 2023
172e376
...
fisx Oct 26, 2023
e9bedea
...
fisx Nov 10, 2023
a4da35a
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Nov 10, 2023
07a79ff
Fixup
fisx Nov 10, 2023
3be2731
Fixup
fisx Nov 10, 2023
0882436
...
fisx Nov 12, 2023
dfc8642
[stash]
fisx Nov 12, 2023
a2ea488
Revert "[stash]"
fisx Nov 14, 2023
dec389b
...
fisx Nov 16, 2023
5b8c4bb
...
fisx Nov 17, 2023
1491812
...
fisx Nov 17, 2023
4ea52c1
...
fisx Nov 17, 2023
d4647bd
[stash]
fisx Nov 17, 2023
cf45a80
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Nov 17, 2023
afd779c
Revert "[stash]"
fisx Nov 20, 2023
5525fe6
...
fisx Nov 20, 2023
6da3fe1
...
fisx Nov 20, 2023
9e853d3
schema-profunctor business
fisx Nov 20, 2023
d3034b2
make use of schema-profunctor business
fisx Nov 20, 2023
e0e1a41
...
fisx Nov 20, 2023
704b2cd
...
fisx Nov 20, 2023
cfc3217
...
fisx Nov 20, 2023
5247398
[stash]
fisx Nov 20, 2023
9b26520
Merge remote-tracking branch 'origin/develop' into WPB-1583
fisx Nov 20, 2023
346b759
Revert "[stash]"
fisx Nov 20, 2023
ce19c83
...
fisx Nov 21, 2023
2bfeb8b
...
fisx Nov 21, 2023
d2221c5
...
fisx Nov 21, 2023
4f6699c
...
fisx Nov 21, 2023
e497bc1
[stash]
fisx Nov 21, 2023
de2dd0c
Revert "[stash]"
fisx Nov 21, 2023
4e11dfc
...
fisx Nov 22, 2023
f71c953
...
fisx Nov 23, 2023
65e15bc
...
fisx Nov 23, 2023
8b51f53
[stash]
fisx Nov 23, 2023
c8a8d9a
Revert "[stash]"
fisx Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cassandra-schema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,18 @@ CREATE TABLE brig_test.user (
provider uuid,
searchable boolean,
service uuid,
sso_id text,
--
-- NOTE(fisx): i'm breaking this on purpose to make it more obvious where i'm going with the schema migration.
-- we'll regenerate this file once we're done.
--
sso_id text, -- deprecated, but honored for compatibility if it is non-null and the following 3 fields are all null.
saml_entity_id text, -- issuer from UserRef, can be null
saml_name_id text, -- name id from UserRef, can be null
scim_external_id text, -- what you think it is, can be null
--
-- NOTE(fisx): cassandra does not prevent illegal cases like "entity_id null and name_id non-null".
-- i wouldn't know how, so that's the job of all parsers of incoming data, see `ValidUAuthIdF`
--
status int,
supported_protocols int,
team uuid
Expand Down Expand Up @@ -2204,4 +2215,3 @@ CREATE TABLE spar_test.user (
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';

2 changes: 1 addition & 1 deletion libs/brig-types/src/Brig/Types/User/Event.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ data UserUpdatedData = UserUpdatedData
eupHandle :: !(Maybe Handle),
eupLocale :: !(Maybe Locale),
eupManagedBy :: !(Maybe ManagedBy),
eupSSOId :: !(Maybe UserSSOId),
eupSSOId :: !(Maybe LegacyUserSSOId), -- FUTUREWORK: add fields `eupUAuthId`? (this can replace both SSOId and SSOIdRemoved, but beware of backward compatibility issues when removing those!)
eupSSOIdRemoved :: Bool,
eupSupportedProtocols :: !(Maybe (Set BaseProtocolTag))
}
Expand Down
2 changes: 2 additions & 0 deletions libs/wire-api/src/Wire/API/Deprecated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import Servant.Client
import Servant.OpenApi

-- Annotate that the route is deprecated
--
-- FUTUREWORK: give this a message string that explains how to migrate away from the deprecated end-point!
data Deprecated deriving (Typeable)

-- All of these instances are very similar to the instances
Expand Down
36 changes: 33 additions & 3 deletions libs/wire-api/src/Wire/API/Routes/Internal/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Servant hiding (Handler, WithStatus, addHeader, respond)
import Servant.OpenApi (HasOpenApi (toOpenApi))
import Servant.OpenApi.Internal.Orphans ()
import Wire.API.Connection
import Wire.API.Deprecated
import Wire.API.Error
import Wire.API.Error.Brig
import Wire.API.MLS.CipherSuite
Expand Down Expand Up @@ -338,10 +339,11 @@ type AccountAPI =
)
:<|> Named
"iPutUserSsoId"
( "users"
( Deprecated -- use `iPutUAuthId` instead
:> "users"
:> Capture "uid" UserId
:> "sso-id"
:> ReqBody '[Servant.JSON] UserSSOId
:> ReqBody '[Servant.JSON] LegacyUserSSOId
:> MultiVerb
'PUT
'[Servant.JSON]
Expand All @@ -352,7 +354,8 @@ type AccountAPI =
)
:<|> Named
"iDeleteUserSsoId"
( "users"
( Deprecated -- use `iDeleteUAuthId` instead
:> "users"
:> Capture "uid" UserId
:> "sso-id"
:> MultiVerb
Expand All @@ -363,6 +366,33 @@ type AccountAPI =
]
UpdateSSOIdResponse
)
:<|> Named
"iPutUAuthId"
( "users"
:> Capture "uid" UserId
:> "uauthid"
:> ReqBody '[Servant.JSON] PartialUAuthId
:> MultiVerb
'PUT
'[Servant.JSON]
'[ RespondEmpty 200 "UpdateSSOIdSuccess",
RespondEmpty 404 "UpdateSSOIdNotFound"
]
UpdateSSOIdResponse
)
:<|> Named
"iDeleteUAuthId"
( "users"
:> Capture "uid" UserId
:> "uauthid"
:> MultiVerb
'DELETE
'[Servant.JSON]
'[ RespondEmpty 200 "UpdateSSOIdSuccess",
RespondEmpty 404 "UpdateSSOIdNotFound"
]
UpdateSSOIdResponse
)
:<|> Named
"iPutManagedBy"
( "users"
Expand Down
59 changes: 38 additions & 21 deletions libs/wire-api/src/Wire/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -739,31 +739,33 @@ userEmail = emailIdentity <=< userIdentity
userPhone :: User -> Maybe Phone
userPhone = phoneIdentity <=< userIdentity

userSSOId :: User -> Maybe UserSSOId
userSSOId :: User -> Maybe PartialUAuthId
userSSOId = ssoIdentity <=< userIdentity

userSCIMExternalId :: User -> Maybe Text
userSCIMExternalId usr = scimExternalId (userManagedBy usr) =<< userSSOId usr

-- FUTUREWORK: this is only ignoring case in the email format, and emails should be
-- handled case-insensitively. https://wearezeta.atlassian.net/browse/SQSERVICES-909
scimExternalId :: ManagedBy -> UserSSOId -> Maybe Text
scimExternalId _ (UserScimExternalId extId) = Just extId
scimExternalId ManagedByScim (UserSSOId (SAML.UserRef _ nameIdXML)) = Just . CI.original . SAML.unsafeShowNameID $ nameIdXML
scimExternalId ManagedByWire (UserSSOId _) = Nothing

ssoIssuerAndNameId :: UserSSOId -> Maybe (Text, Text)
ssoIssuerAndNameId (UserSSOId (SAML.UserRef (SAML.Issuer uri) nameIdXML)) = Just (fromUri uri, fromNameId nameIdXML)
scimExternalId :: ManagedBy -> PartialUAuthId -> Maybe Text
scimExternalId _ (UAuthId _ (Just extId) _ _) = Just extId
scimExternalId ManagedByScim (UAuthId (Just (SAML.UserRef _ nameIdXML)) _ _ _) = Just . CI.original . SAML.unsafeShowNameID $ nameIdXML
scimExternalId ManagedByWire (UAuthId {}) = Nothing
-- TODO: Check that this makes sense.
scimExternalId _ _ = Nothing

ssoIssuerAndNameId :: PartialUAuthId -> Maybe (Text, Text)
ssoIssuerAndNameId (UAuthId (Just (SAML.UserRef (SAML.Issuer uri) nameIdXML)) _ _ _) = Just (fromUri uri, fromNameId nameIdXML)
where
fromUri = cs . toLazyByteString . serializeURIRef
fromNameId = CI.original . SAML.unsafeShowNameID
ssoIssuerAndNameId (UserScimExternalId _) = Nothing
ssoIssuerAndNameId (UAuthId {}) = Nothing

userIssuer :: User -> Maybe SAML.Issuer
userIssuer user = userSSOId user >>= fromSSOId
where
fromSSOId :: UserSSOId -> Maybe SAML.Issuer
fromSSOId (UserSSOId (SAML.UserRef issuer _)) = Just issuer
fromSSOId :: PartialUAuthId -> Maybe SAML.Issuer
fromSSOId (UAuthId (Just (SAML.UserRef issuer _)) _ _ _) = Just issuer
fromSSOId _ = Nothing

connectedProfile :: User -> UserLegalHoldStatus -> UserProfile
Expand Down Expand Up @@ -1006,7 +1008,7 @@ errFromEither (Right e) = CreateUserSparRegistrationError e

data NewUserSpar = NewUserSpar
{ newUserSparUUID :: UUID,
newUserSparSSOId :: UserSSOId,
newUserSparSSOId :: PartialUAuthId,
newUserSparDisplayName :: Name,
newUserSparTeamId :: TeamId,
newUserSparManagedBy :: ManagedBy,
Expand Down Expand Up @@ -1046,7 +1048,7 @@ newUserFromSpar new =
NewUser
{ newUserDisplayName = newUserSparDisplayName new,
newUserUUID = Just $ newUserSparUUID new,
newUserIdentity = Just $ SSOIdentity (newUserSparSSOId new) Nothing Nothing,
newUserIdentity = Just $ UAuthIdentity $ newUserSparSSOId new,
newUserPict = Nothing,
newUserAssets = [],
newUserAccentId = Nothing,
Expand Down Expand Up @@ -1112,9 +1114,15 @@ data NewUserRaw = NewUserRaw
newUserRawUUID :: Maybe UUID,
newUserRawEmail :: Maybe Email,
newUserRawPhone :: Maybe Phone,
newUserRawSSOId :: Maybe UserSSOId,
-- | DEPRECATED
newUserRawPict :: Maybe Pict,
newUserRawSSOId ::
-- DEPRECATED (use newUserRawUAuthId instead)
Maybe LegacyUserSSOId,
newUserRawUAuthId ::
-- NOTE(fisx): This defines a json object under a json field, just like newUserRawSSOId. no inlining!
Maybe PartialUAuthId,
newUserRawPict ::
-- DEPRECATED
Maybe Pict,
newUserRawAssets :: [Asset],
newUserRawAccentId :: Maybe ColourId,
newUserRawEmailCode :: Maybe ActivationCode,
Expand Down Expand Up @@ -1144,6 +1152,8 @@ newUserRawObjectSchema =
.= maybe_ (optField "phone" schema)
<*> newUserRawSSOId
.= maybe_ (optField "sso_id" genericToSchema)
<*> newUserRawUAuthId
.= maybe_ (optField "uauthid" genericToSchema)
<*> newUserRawPict
.= maybe_ (optField "picture" schema)
<*> newUserRawAssets
Expand Down Expand Up @@ -1187,7 +1197,8 @@ newUserToRaw NewUser {..} =
newUserRawUUID = newUserUUID,
newUserRawEmail = emailIdentity =<< newUserIdentity,
newUserRawPhone = phoneIdentity =<< newUserIdentity,
newUserRawSSOId = ssoIdentity =<< newUserIdentity,
newUserRawSSOId = _,
newUserRawUAuthId = ssoIdentity =<< newUserIdentity,
newUserRawPict = newUserPict,
newUserRawAssets = newUserAssets,
newUserRawAccentId = newUserAccentId,
Expand All @@ -1213,7 +1224,13 @@ newUserFromRaw NewUserRaw {..} = do
(isJust newUserRawPassword)
(isJust newUserRawSSOId)
(newUserRawInvitationCode, newUserRawTeamCode, newUserRawTeam, newUserRawTeamId)
let identity = maybeUserIdentityFromComponents (newUserRawEmail, newUserRawPhone, newUserRawSSOId)
let identity =
maybeUserIdentityFromComponents
( newUserRawEmail,
newUserRawPhone,
newUserRawSSOId,
newUserRawUAuthId
)
expiresIn <-
case (newUserRawExpiresIn, identity) of
(Just _, Just _) -> fail "Only users without an identity can expire"
Expand Down Expand Up @@ -1260,7 +1277,7 @@ instance Arbitrary NewUser where
genUserOrigin newUserIdentity = do
teamid <- arbitrary
let hasSSOId = case newUserIdentity of
Just SSOIdentity {} -> True
Just UAuthIdentity {} -> True
_ -> False
ssoOrigin = Just (NewUserOriginTeamUser (NewTeamMemberSSO teamid))
isSsoOrigin (Just (NewUserOriginTeamUser (NewTeamMemberSSO _))) = True
Expand All @@ -1270,7 +1287,7 @@ instance Arbitrary NewUser where
else arbitrary `QC.suchThat` (not . isSsoOrigin)
genUserPassword newUserIdentity newUserOrigin = do
let hasSSOId = case newUserIdentity of
Just SSOIdentity {} -> True
Just UAuthIdentity {} -> True
_ -> False
isTeamUser = case newUserOrigin of
Just (NewUserOriginTeamUser _) -> True
Expand All @@ -1295,7 +1312,7 @@ newUserEmail = emailIdentity <=< newUserIdentity
newUserPhone :: NewUser -> Maybe Phone
newUserPhone = phoneIdentity <=< newUserIdentity

newUserSSOId :: NewUser -> Maybe UserSSOId
newUserSSOId :: NewUser -> Maybe PartialUAuthId
newUserSSOId = ssoIdentity <=< newUserIdentity

--------------------------------------------------------------------------------
Expand Down
Loading