Skip to content

Commit 762cff7

Browse files
committed
Calculate force_authn value with correct type
The force_authn value comes from different places and could be either a string or a boolean or NoneType. The value will later be used to set the ForceAuthn property and it is expected to be a string. We return 'true' to set the property, or False to omit it. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent d8bb07a commit 762cff7

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/satosa/backends/saml2.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,25 @@ def get_memorized_idp(context, config, force_authn):
4747
return value
4848

4949

50-
# XXX check KEY_FORCE_AUTHN value type (boolean vs str)
5150
def get_force_authn(context, config, sp_config):
52-
value = (
53-
config.get(SAMLBackend.KEY_MIRROR_FORCE_AUTHN)
54-
and (
55-
context.state.get(Context.KEY_FORCE_AUTHN)
56-
or context.get_decoration(Context.KEY_FORCE_AUTHN)
57-
)
58-
or sp_config.getattr("force_authn", "sp")
59-
)
51+
"""
52+
Return the force_authn value.
53+
54+
The value comes from one of three place:
55+
- the configuration of the backend
56+
- the context, as it came through in the AuthnRequest handled by the frontend.
57+
note: the frontend should have been set to mirror the force_authn value.
58+
- the cookie, as it has been stored by the proxy on a redirect to the DS
59+
note: the frontend should have been set to mirror the force_authn value.
60+
61+
The value is either "true" or False
62+
"""
63+
mirror = config.get(SAMLBackend.KEY_MIRROR_FORCE_AUTHN)
64+
from_state = mirror and context.state.get(Context.KEY_FORCE_AUTHN)
65+
from_context = mirror and context.get_decoration(Context.KEY_FORCE_AUTHN)
66+
from_config = sp_config.getattr("force_authn", "sp")
67+
is_set = str(from_state or from_context or from_config).lower() == "true"
68+
value = is_set and "true"
6069
return value
6170

6271

0 commit comments

Comments
 (0)