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

Commit a0adf71

Browse files
agrimpardhughns
authored andcommitted
Add configuration setting for CAS protocol version (#15816)
1 parent 0cc3da9 commit a0adf71

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

changelog.d/15816.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add configuration setting for CAS protocol version. Contributed by Aurélien Grimpard.

docs/usage/configuration/config_documentation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,6 +3420,7 @@ Has the following sub-options:
34203420
to style the login flow according to the identity provider in question.
34213421
See the [spec](https://spec.matrix.org/latest/) for possible options here.
34223422
* `server_url`: The URL of the CAS authorization endpoint.
3423+
* `protocol_version`: The CAS protocol version, defaults to none (version 3 is required if you want to use "required_attributes").
34233424
* `displayname_attribute`: The attribute of the CAS response to use as the display name.
34243425
If no name is given here, no displayname will be set.
34253426
* `required_attributes`: It is possible to configure Synapse to only allow logins if CAS attributes
@@ -3433,6 +3434,7 @@ Example configuration:
34333434
cas_config:
34343435
enabled: true
34353436
server_url: "https://cas-server.com"
3437+
protocol_version: 3
34363438
displayname_attribute: name
34373439
required_attributes:
34383440
userGroup: "staff"

synapse/config/cas.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from synapse.config.sso import SsoAttributeRequirement
1919
from synapse.types import JsonDict
2020

21-
from ._base import Config
21+
from ._base import Config, ConfigError
2222
from ._util import validate_config
2323

2424

@@ -41,6 +41,16 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
4141
public_baseurl = self.root.server.public_baseurl
4242
self.cas_service_url = public_baseurl + "_matrix/client/r0/login/cas/ticket"
4343

44+
self.cas_protocol_version = cas_config.get("protocol_version")
45+
if (
46+
self.cas_protocol_version is not None
47+
and self.cas_protocol_version not in [1, 2, 3]
48+
):
49+
raise ConfigError(
50+
"Unsupported CAS protocol version %s (only versions 1, 2, 3 are supported)"
51+
% (self.cas_protocol_version,),
52+
("cas_config", "protocol_version"),
53+
)
4454
self.cas_displayname_attribute = cas_config.get("displayname_attribute")
4555
required_attributes = cas_config.get("required_attributes") or {}
4656
self.cas_required_attributes = _parsed_required_attributes_def(
@@ -54,6 +64,7 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
5464
else:
5565
self.cas_server_url = None
5666
self.cas_service_url = None
67+
self.cas_protocol_version = None
5768
self.cas_displayname_attribute = None
5869
self.cas_required_attributes = []
5970

synapse/handlers/cas.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(self, hs: "HomeServer"):
6767

6868
self._cas_server_url = hs.config.cas.cas_server_url
6969
self._cas_service_url = hs.config.cas.cas_service_url
70+
self._cas_protocol_version = hs.config.cas.cas_protocol_version
7071
self._cas_displayname_attribute = hs.config.cas.cas_displayname_attribute
7172
self._cas_required_attributes = hs.config.cas.cas_required_attributes
7273

@@ -121,7 +122,10 @@ async def _validate_ticket(
121122
Returns:
122123
The parsed CAS response.
123124
"""
124-
uri = self._cas_server_url + "/proxyValidate"
125+
if self._cas_protocol_version == 3:
126+
uri = self._cas_server_url + "/p3/proxyValidate"
127+
else:
128+
uri = self._cas_server_url + "/proxyValidate"
125129
args = {
126130
"ticket": ticket,
127131
"service": self._build_service_param(service_args),

0 commit comments

Comments
 (0)