Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
01a5f199
Commit
01a5f199
authored
9 years ago
by
Steven Hammerton
Browse files
Options
Downloads
Patches
Plain Diff
Support multiple required attributes in CAS response, and in a nicer config format too
parent
76421c49
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/config/cas.py
+4
-15
4 additions, 15 deletions
synapse/config/cas.py
synapse/rest/client/v1/login.py
+6
-7
6 additions, 7 deletions
synapse/rest/client/v1/login.py
with
10 additions
and
22 deletions
synapse/config/cas.py
+
4
−
15
View file @
01a5f199
...
...
@@ -27,28 +27,17 @@ class CasConfig(Config):
if
cas_config
:
self
.
cas_enabled
=
True
self
.
cas_server_url
=
cas_config
[
"
server_url
"
]
if
"
required_attribute
"
in
cas_config
:
self
.
cas_required_attribute
=
cas_config
[
"
required_attribute
"
]
else
:
self
.
cas_required_attribute
=
None
if
"
required_attribute_value
"
in
cas_config
:
self
.
cas_required_attribute_value
=
cas_config
[
"
required_attribute_value
"
]
else
:
self
.
cas_required_attribute_value
=
None
self
.
cas_required_attributes
=
cas_config
.
get
(
"
required_attributes
"
,
None
)
else
:
self
.
cas_enabled
=
False
self
.
cas_server_url
=
None
self
.
cas_required_attribute
=
None
self
.
cas_required_attribute_value
=
None
self
.
cas_required_attributes
=
{}
def
default_config
(
self
,
config_dir_path
,
server_name
,
**
kwargs
):
return
"""
# Enable CAS for registration and login.
#cas_config:
# server_url:
"
https://cas-server.com
"
# #required_attribute:
something
# #
required_attribute_value: tr
ue
# #required_attribute
s
:
# #
name: val
ue
"""
This diff is collapsed.
Click to expand it.
synapse/rest/client/v1/login.py
+
6
−
7
View file @
01a5f199
...
...
@@ -46,8 +46,7 @@ class LoginRestServlet(ClientV1RestServlet):
self
.
saml2_enabled
=
hs
.
config
.
saml2_enabled
self
.
cas_enabled
=
hs
.
config
.
cas_enabled
self
.
cas_server_url
=
hs
.
config
.
cas_server_url
self
.
cas_required_attribute
=
hs
.
config
.
cas_required_attribute
self
.
cas_required_attribute_value
=
hs
.
config
.
cas_required_attribute_value
self
.
cas_required_attributes
=
hs
.
config
.
cas_required_attributes
self
.
servername
=
hs
.
config
.
server_name
def
on_GET
(
self
,
request
):
...
...
@@ -128,16 +127,16 @@ class LoginRestServlet(ClientV1RestServlet):
def
do_cas_login
(
self
,
cas_response_body
):
(
user
,
attributes
)
=
self
.
parse_cas_response
(
cas_response_body
)
i
f
self
.
cas_required_attribute
is
not
None
:
f
or
required_attribute
in
self
.
cas_required_attribute
s
:
# If required attribute was not in CAS Response - Forbidden
if
self
.
cas_
required_attribute
not
in
attributes
:
if
required_attribute
not
in
attributes
:
raise
LoginError
(
401
,
"
Unauthorized
"
,
errcode
=
Codes
.
UNAUTHORIZED
)
# Also need to check value
if
self
.
cas_required_attribute
_value
is
not
None
:
actualValue
=
attributes
[
self
.
cas_
required_attribute
]
if
self
.
cas_required_attribute
s
[
required_attribute
]
is
not
None
:
actualValue
=
attributes
[
required_attribute
]
# If required attribute value does not match expected - Forbidden
if
self
.
cas_required_attribute
_value
!=
actualValue
:
if
self
.
cas_required_attribute
s
[
required_attribute
]
!=
actualValue
:
raise
LoginError
(
401
,
"
Unauthorized
"
,
errcode
=
Codes
.
UNAUTHORIZED
)
user_id
=
UserID
.
create
(
user
,
self
.
hs
.
hostname
).
to_string
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment