async def oidc_response_to_user_attributes(failures: int) -> UserAttributes: """ Call the mapping provider to map the OIDC userinfo and token to user attributes. This is backwards compatibility for abstraction for the SSO handler. """ if supports_failures: attributes = await self._user_mapping_provider.map_user_attributes( userinfo, token, failures ) else: # If the mapping provider does not support processing failures, # do not continually generate the same Matrix ID since it will # continue to already be in use. Note that the error raised is # arbitrary and will get turned into a MappingException. if failures: raise MappingException( "Mapping provider does not support de-duplicating Matrix IDs" ) attributes = await self._user_mapping_provider.map_user_attributes( # type: ignore userinfo, token ) return UserAttributes(**attributes)
async def cas_response_to_user_attributes(failures: int) -> UserAttributes: """ Map from CAS attributes to user attributes. """ # Due to the grandfathering logic matching any previously registered # mxids it isn't expected for there to be any failures. if failures: raise RuntimeError("CAS is not expected to de-duplicate Matrix IDs") # Arbitrarily use the first attribute found. display_name = cas_response.attributes.get( self._cas_displayname_attribute, [None] )[0] return UserAttributes(localpart=localpart, display_name=display_name)
async def saml_response_to_remapped_user_attributes( failures: int, ) -> UserAttributes: """ Call the mapping provider to map a SAML response to user attributes and coerce the result into the standard form. This is backwards compatibility for abstraction for the SSO handler. """ # Call the mapping provider. result = self._user_mapping_provider.saml_response_to_user_attributes( saml2_auth, failures, client_redirect_url) # Remap some of the results. return UserAttributes( localpart=result.get("mxid_localpart"), display_name=result.get("displayname"), emails=result.get("emails", []), )
async def cas_response_to_user_attributes(failures: int) -> UserAttributes: """ Map from CAS attributes to user attributes. """ # Due to the grandfathering logic matching any previously registered # mxids it isn't expected for there to be any failures. if failures: raise RuntimeError("CAS is not expected to de-duplicate Matrix IDs") # Arbitrarily use the first attribute found. display_name = cas_response.attributes.get( self._cas_displayname_attribute, [None] )[0] return UserAttributes(localpart=localpart, display_name=display_name) async def grandfather_existing_users() -> Optional[str]: # Since CAS did not always use the user_external_ids table, always # to attempt to map to existing users. user_id = UserID(localpart, self._hostname).to_string() logger.debug( "Looking for existing account based on mapped %s", user_id, ) users = await self._store.get_users_by_id_case_insensitive(user_id) if users: registered_user_id = list(users.keys())[0] logger.info("Grandfathering mapping to %s", registered_user_id)