-
Notifications
You must be signed in to change notification settings - Fork 332
Fix saml corner case #2464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix saml corner case #2464
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b98e825
Cleanup.
fisx 42f6c0e
Cleanup.
fisx 3e51825
Cleanup.
fisx c353f25
Cleanup.
fisx bcccc81
Cleanup.
fisx 76e7225
Expose helper function needed in next commit.
fisx fe5c7ba
Fix: saml-auto-provisioned users don't get to change email address.
fisx 3b43c20
Changelog
fisx 16fd83f
hi ci
fisx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| saml-auto-provisioned users don't get to change email address |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -607,32 +607,42 @@ changeSelfEmail u email allowScim = do | |
| -- | Prepare changing the email (checking a number of invariants). | ||
| changeEmail :: UserId -> Email -> AllowSCIMUpdates -> ExceptT ChangeEmailError (AppT r) ChangeEmailResult | ||
| changeEmail u email allowScim = do | ||
| em <- | ||
| either | ||
| (throwE . InvalidNewEmail email) | ||
| pure | ||
| (validateEmail email) | ||
| let ek = userEmailKey em | ||
| blacklisted <- lift . wrapClient $ Blacklist.exists ek | ||
| eml <- either (throwE . InvalidNewEmail email) pure (validateEmail email) | ||
| let eky = userEmailKey eml | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally find the name I would use |
||
|
|
||
| blacklisted <- lift . wrapClient $ Blacklist.exists eky | ||
| when blacklisted $ | ||
| throwE (ChangeBlacklistedEmail email) | ||
| available <- lift . wrapClient $ Data.keyAvailable ek (Just u) | ||
|
|
||
| available <- lift . wrapClient $ Data.keyAvailable eky (Just u) | ||
| unless available $ | ||
| throwE $ | ||
| EmailExists email | ||
| usr <- maybe (throwM $ UserProfileNotFound u) pure =<< lift (wrapClient $ Data.lookupUser WithPendingInvitations u) | ||
| case emailIdentity =<< userIdentity usr of | ||
| -- The user already has an email address and the new one is exactly the same | ||
| Just current | current == em -> pure ChangeEmailIdempotent | ||
| _ -> do | ||
| unless | ||
| ( userManagedBy usr /= ManagedByScim | ||
| || allowScim == AllowSCIMUpdates | ||
| ) | ||
| $ throwE EmailManagedByScim | ||
| throwE (EmailExists email) | ||
|
|
||
| usr <- | ||
| maybe (throwM $ UserProfileNotFound u) pure | ||
| =<< lift (wrapClient $ Data.lookupUser WithPendingInvitations u) | ||
|
|
||
| if (emailIdentity =<< userIdentity usr) == Just eml | ||
| then do | ||
| -- The user already has an email address and the new one is exactly the same | ||
| pure ChangeEmailIdempotent | ||
| else do | ||
| -- case 2: No or different old email address | ||
| let changeAllowed = | ||
| ( userManagedBy usr /= ManagedByScim | ||
| || allowScim == AllowSCIMUpdates -- spar is always allowed to call this function (from the scim handlers) | ||
| ) | ||
| && not | ||
| ( -- user is auto-provisioned by saml (deprecated use case) | ||
| userManagedBy usr /= ManagedByScim && userHasSAML usr | ||
| ) | ||
|
|
||
| unless changeAllowed $ | ||
| throwE EmailManagedByScim | ||
|
|
||
| timeout <- setActivationTimeout <$> view settings | ||
| act <- lift . wrapClient $ Data.newActivation ek timeout (Just u) | ||
| pure $ ChangeEmailNeedsActivation (usr, act, em) | ||
| act <- lift . wrapClient $ Data.newActivation eky timeout (Just u) | ||
| pure $ ChangeEmailNeedsActivation (usr, act, eml) | ||
|
|
||
| ------------------------------------------------------------------------------- | ||
| -- Change Phone | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do refactorings in a separate PR :-P