Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

New listener resource for the federation API "openid/userinfo" endpoint #4420

Merged
merged 14 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/4420.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Federation OpenID listener resource can now be activated even if federation is disabled
13 changes: 12 additions & 1 deletion synapse/app/federation_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def _listen_http(self, listener_config):
resources.update({
FEDERATION_PREFIX: TransportLayerServer(self),
})
if name == "openid" and "federation" not in res["names"]:
# Only load the openid resource separately if federation resource
# is not specified since federation resource includes openid
# resource.
resources.update({
FEDERATION_PREFIX: TransportLayerServer(
self,
servlet_groups=["openid"],
),
})

root_resource = create_resource_tree(resources, NoResource())

Expand All @@ -99,7 +109,8 @@ def _listen_http(self, listener_config):
listener_config,
root_resource,
self.version_string,
)
),
reactor=self.get_reactor()
)

logger.info("Synapse federation reader now listening on port %d", port)
Expand Down
13 changes: 12 additions & 1 deletion synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def _listener_http(self, config, listener_config):
resources = {}
for res in listener_config["resources"]:
for name in res["names"]:
if name == "openid" and "federation" in res["names"]:
# Skip loading openid resource if federation is defined
# since federation resource will include openid
continue
resources.update(self._configure_named_resource(
name, res.get("compress", False),
))
Expand Down Expand Up @@ -130,6 +134,7 @@ def _listener_http(self, config, listener_config):
self.version_string,
),
self.tls_server_context_factory,
reactor=self.get_reactor(),
)

else:
Expand All @@ -142,7 +147,8 @@ def _listener_http(self, config, listener_config):
listener_config,
root_resource,
self.version_string,
)
),
reactor=self.get_reactor(),
)
logger.info("Synapse now listening on port %d", port)

Expand Down Expand Up @@ -190,6 +196,11 @@ def _configure_named_resource(self, name, compress=False):
FEDERATION_PREFIX: TransportLayerServer(self),
})

if name == "openid":
resources.update({
FEDERATION_PREFIX: TransportLayerServer(self, servlet_groups=["openid"]),
})

if name in ["static", "client"]:
resources.update({
STATIC_PREFIX: File(
Expand Down
10 changes: 10 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ def default_config(self, server_name, data_dir_path, **kwargs):
- names: [federation] # Federation APIs
compress: false

# # If federation is disabled synapse can still expose the open ID endpoint
# # to allow integrations to authenticate users
# - names: [openid]
# compress: false

# optional list of additional endpoints which can be loaded via
# dynamic modules
# additional_resources:
Expand All @@ -352,6 +357,10 @@ def default_config(self, server_name, data_dir_path, **kwargs):
compress: true
- names: [federation]
compress: false
# # If federation is disabled synapse can still expose the open ID endpoint
# # to allow integrations to authenticate users
# - names: [openid]
# compress: false

# Turn on the twisted ssh manhole service on localhost on the given
# port.
Expand Down Expand Up @@ -477,6 +486,7 @@ def _warn_if_webclient_configured(listeners):
'keys',
'media',
'metrics',
'openid',
'replication',
'static',
'webclient',
Expand Down
137 changes: 95 additions & 42 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,20 @@
class TransportLayerServer(JsonResource):
"""Handles incoming federation HTTP requests"""

def __init__(self, hs):
def __init__(self, hs, servlet_groups=None):
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
"""Initialize the TransportLayerServer

Will by default register all servlets. For custom behaviour, pass in
a list of servlet_groups to register.

Args:
hs (synapse.server.HomeServer): homeserver
servlet_groups (list[str], optional): List of servlet groups to register.
Defaults to ``DEFAULT_SERVLET_GROUPS``.
"""
self.hs = hs
self.clock = hs.get_clock()
self.servlet_groups = servlet_groups

super(TransportLayerServer, self).__init__(hs, canonical_json=False)

Expand All @@ -67,6 +78,7 @@ def register_servlets(self):
resource=self,
ratelimiter=self.ratelimiter,
authenticator=self.authenticator,
servlet_groups=self.servlet_groups,
)


Expand Down Expand Up @@ -1308,10 +1320,12 @@ def on_PUT(self, origin, content, query, group_id):
FederationClientKeysClaimServlet,
FederationThirdPartyInviteExchangeServlet,
On3pidBindServlet,
OpenIdUserInfo,
FederationVersionServlet,
)

OPENID_SERVLET_CLASSES = (
OpenIdUserInfo,
)

ROOM_LIST_CLASSES = (
PublicRoomList,
Expand Down Expand Up @@ -1350,44 +1364,83 @@ def on_PUT(self, origin, content, query, group_id):
FederationGroupsRenewAttestaionServlet,
)

DEFAULT_SERVLET_GROUPS = (
"federation",
"room_list",
"group_server",
"group_local",
"group_attestation",
"openid",
)


def register_servlets(hs, resource, authenticator, ratelimiter, servlet_groups=None):
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
"""Initialize and register servlet classes.

def register_servlets(hs, resource, authenticator, ratelimiter):
for servletclass in FEDERATION_SERVLET_CLASSES:
servletclass(
handler=hs.get_federation_server(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

for servletclass in ROOM_LIST_CLASSES:
servletclass(
handler=hs.get_room_list_handler(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

for servletclass in GROUP_SERVER_SERVLET_CLASSES:
servletclass(
handler=hs.get_groups_server_handler(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

for servletclass in GROUP_LOCAL_SERVLET_CLASSES:
servletclass(
handler=hs.get_groups_local_handler(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

for servletclass in GROUP_ATTESTATION_SERVLET_CLASSES:
servletclass(
handler=hs.get_groups_attestation_renewer(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)
Will by default register all servlets. For custom behaviour, pass in
a list of servlet_groups to register.

Args:
hs (synapse.server.HomeServer): homeserver
resource (TransportLayerServer): resource class to register to
authenticator (Authenticator): authenticator to use
ratelimiter (util.ratelimitutils.FederationRateLimiter): ratelimiter to use
servlet_groups (list[str], optional): List of servlet groups to register.
Defaults to ``DEFAULT_SERVLET_GROUPS``.
"""
if not servlet_groups:
servlet_groups = DEFAULT_SERVLET_GROUPS

if "federation" in servlet_groups:
for servletclass in FEDERATION_SERVLET_CLASSES:
servletclass(
handler=hs.get_federation_server(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

if "openid" in servlet_groups:
for servletclass in OPENID_SERVLET_CLASSES:
servletclass(
handler=hs.get_federation_server(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

if "room_list" in servlet_groups:
for servletclass in ROOM_LIST_CLASSES:
servletclass(
handler=hs.get_room_list_handler(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

if "group_server" in servlet_groups:
for servletclass in GROUP_SERVER_SERVLET_CLASSES:
servletclass(
handler=hs.get_groups_server_handler(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

if "group_local" in servlet_groups:
for servletclass in GROUP_LOCAL_SERVLET_CLASSES:
servletclass(
handler=hs.get_groups_local_handler(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)

if "group_attestation" in servlet_groups:
for servletclass in GROUP_ATTESTATION_SERVLET_CLASSES:
servletclass(
handler=hs.get_groups_attestation_renewer(),
authenticator=authenticator,
ratelimiter=ratelimiter,
server_name=hs.hostname,
).register(resource)
2 changes: 1 addition & 1 deletion synapse/python_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

"saml2": ["pysaml2>=4.5.0"],
"url_preview": ["lxml>=3.5.0"],
"test": ["mock>=2.0"],
"test": ["mock>=2.0", "parameterized"],
}


Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_frontend_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_listen_http_with_presence_enabled(self):

def test_listen_http_with_presence_disabled(self):
"""
When presence is on, the stub servlet will register.
When presence is off, the stub servlet will register.
"""
# Presence is off
self.hs.config.use_presence = False
Expand Down
Loading