Skip to content

Commit 452fdf9

Browse files
committed
Move deprecated properties to InternalData
Previously the private class _DeprecatedInternalData used to hold the deprecated properties captured by InternalRequest and InternalResponse. Properties are now moved to the actual superclass InternalData as this is now the one used to define the internal representation. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 0dd7232 commit 452fdf9

File tree

2 files changed

+93
-107
lines changed

2 files changed

+93
-107
lines changed

src/satosa/deprecated.py

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -14,107 +14,7 @@
1414
_warnings.simplefilter("default")
1515

1616

17-
class _DeprecatedInternalData(InternalData):
18-
def __init__(
19-
self,
20-
auth_info=None,
21-
requester=None,
22-
requester_name=None,
23-
subject_id=None,
24-
subject_type=None,
25-
attributes=None,
26-
user_id=None,
27-
user_id_hash_type=None,
28-
name_id=None,
29-
approved_attributes=None,
30-
):
31-
return super().__init__(
32-
auth_info=auth_info,
33-
requester=requester,
34-
requester_name=requester_name,
35-
subject_id=subject_id or user_id or name_id,
36-
subject_type=subject_type or user_id_hash_type,
37-
attributes=attributes,
38-
)
39-
40-
def to_dict(self):
41-
data = super().to_dict()
42-
data.update(
43-
{
44-
"user_id": self.subject_id,
45-
"user_id_hash_type": self.subject_type,
46-
"name_id": self.subject_id,
47-
"approved_attributes": self.attributes,
48-
}
49-
)
50-
return data
51-
52-
@classmethod
53-
def from_dict(cls, data):
54-
instance = InternalData.from_dict(data)
55-
instance.attributes = data.get("attributes") or data.get(
56-
"approved_attributes"
57-
)
58-
instance.subject_type = data.get("subject_type") or data.get(
59-
"user_id_hash_type"
60-
)
61-
instance.subject_id = (
62-
data.get("subject_id")
63-
or data.get("user_id")
64-
or data.get("name_id")
65-
)
66-
return instance
67-
68-
@property
69-
def user_id(self):
70-
msg = "user_id is deprecated; use subject_id instead."
71-
_warnings.warn(msg, DeprecationWarning)
72-
return self.subject_id
73-
74-
@user_id.setter
75-
def user_id(self, value):
76-
msg = "user_id is deprecated; use subject_id instead."
77-
_warnings.warn(msg, DeprecationWarning)
78-
self.subject_id = value
79-
80-
@property
81-
def user_id_hash_type(self):
82-
msg = "user_id_hash_type is deprecated; use subject_type instead."
83-
_warnings.warn(msg, DeprecationWarning)
84-
return self.subject_type
85-
86-
@user_id_hash_type.setter
87-
def user_id_hash_type(self, value):
88-
msg = "user_id_hash_type is deprecated; use subject_type instead."
89-
_warnings.warn(msg, DeprecationWarning)
90-
self.subject_type = value
91-
92-
@property
93-
def approved_attributes(self):
94-
msg = "approved_attributes is deprecated; use attributes instead."
95-
_warnings.warn(msg, DeprecationWarning)
96-
return self.attributes
97-
98-
@approved_attributes.setter
99-
def approved_attributes(self, value):
100-
msg = "approved_attributes is deprecated; use attributes instead."
101-
_warnings.warn(msg, DeprecationWarning)
102-
self.attributes = value
103-
104-
@property
105-
def name_id(self):
106-
msg = "name_id is deprecated; use subject_id instead."
107-
_warnings.warn(msg, DeprecationWarning)
108-
return self.subject_id
109-
110-
@name_id.setter
111-
def name_id(self, value):
112-
msg = "name_id is deprecated; use subject_id instead."
113-
_warnings.warn(msg, DeprecationWarning)
114-
self.subject_id = value
115-
116-
117-
class InternalRequest(_DeprecatedInternalData):
17+
class InternalRequest(InternalData):
11818
def __init__(self, user_id_hash_type, requester, requester_name=None):
11919
msg = (
12020
"InternalRequest is deprecated."
@@ -128,7 +28,7 @@ def __init__(self, user_id_hash_type, requester, requester_name=None):
12828
)
12929

13030

131-
class InternalResponse(_DeprecatedInternalData):
31+
class InternalResponse(InternalData):
13232
def __init__(self, auth_info=None):
13333
msg = (
13434
"InternalResponse is deprecated."

src/satosa/internal.py

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
"""Internal data representation for SAML/OAuth/OpenID connect."""
22

33

4+
import warnings as _warnings
5+
6+
7+
_warnings.simplefilter("default")
8+
9+
410
class AuthenticationInformation(object):
511
"""
612
Class that holds information about the authentication
@@ -65,6 +71,10 @@ def __init__(
6571
subject_id=None,
6672
subject_type=None,
6773
attributes=None,
74+
user_id=None,
75+
user_id_hash_type=None,
76+
name_id=None,
77+
approved_attributes=None,
6878
):
6979
"""
7080
:param auth_info:
@@ -86,24 +96,39 @@ def __init__(
8696
self.requester_name = requester_name or [
8797
{"text": requester, "lang": "en"}
8898
]
89-
self.subject_id = subject_id
90-
self.subject_type = subject_type
91-
self.attributes = {} if attributes is None else attributes
99+
self.subject_id = subject_id or user_id or name_id
100+
self.subject_type = subject_type or user_id_hash_type
101+
self.attributes = (
102+
attributes
103+
if attributes is not None
104+
else approved_attributes
105+
if approved_attributes is not None
106+
else {}
107+
)
92108

93109
def to_dict(self):
94110
"""
95111
Converts an InternalData object to a dict
96112
:rtype: dict[str, str]
97113
:return: A dict representation of the object
98114
"""
99-
return {
115+
data = {
100116
"auth_info": self.auth_info.to_dict(),
101117
"requester": self.requester,
102118
"requester_name": self.requester_name,
103119
"attributes": self.attributes,
104120
"subject_id": self.subject_id,
105121
"subject_type": self.subject_type,
106122
}
123+
data.update(
124+
{
125+
"user_id": self.subject_id,
126+
"user_id_hash_type": self.subject_type,
127+
"name_id": self.subject_id,
128+
"approved_attributes": self.attributes,
129+
}
130+
)
131+
return data
107132

108133
@classmethod
109134
def from_dict(cls, data):
@@ -114,7 +139,7 @@ def from_dict(cls, data):
114139
:return: An InternalData object
115140
"""
116141
auth_info = data.get("auth_info", AuthenticationInformation())
117-
return cls(
142+
instance = cls(
118143
auth_info=AuthenticationInformation.from_dict(auth_info),
119144
requester=data.get("requester"),
120145
requester_name=data.get("requester_name"),
@@ -123,5 +148,66 @@ def from_dict(cls, data):
123148
attributes=data.get("attributes"),
124149
)
125150

151+
if instance.attributes is None:
152+
approved_attributes = data.get("approved_attributes")
153+
instance.attributes = (
154+
approved_attributes
155+
if approved_attributes is not None
156+
else {}
157+
)
158+
if instance.subject_type is None:
159+
instance.subject_type = data.get("subject_type")
160+
if instance.subject_id is None:
161+
instance.subject_id = data.get("user_id") or data.get("name_id")
162+
return instance
163+
164+
@property
165+
def user_id(self):
166+
msg = "user_id is deprecated; use subject_id instead."
167+
_warnings.warn(msg, DeprecationWarning)
168+
return self.subject_id
169+
170+
@user_id.setter
171+
def user_id(self, value):
172+
msg = "user_id is deprecated; use subject_id instead."
173+
_warnings.warn(msg, DeprecationWarning)
174+
self.subject_id = value
175+
176+
@property
177+
def user_id_hash_type(self):
178+
msg = "user_id_hash_type is deprecated; use subject_type instead."
179+
_warnings.warn(msg, DeprecationWarning)
180+
return self.subject_type
181+
182+
@user_id_hash_type.setter
183+
def user_id_hash_type(self, value):
184+
msg = "user_id_hash_type is deprecated; use subject_type instead."
185+
_warnings.warn(msg, DeprecationWarning)
186+
self.subject_type = value
187+
188+
@property
189+
def approved_attributes(self):
190+
msg = "approved_attributes is deprecated; use attributes instead."
191+
_warnings.warn(msg, DeprecationWarning)
192+
return self.attributes
193+
194+
@approved_attributes.setter
195+
def approved_attributes(self, value):
196+
msg = "approved_attributes is deprecated; use attributes instead."
197+
_warnings.warn(msg, DeprecationWarning)
198+
self.attributes = value
199+
200+
@property
201+
def name_id(self):
202+
msg = "name_id is deprecated; use subject_id instead."
203+
_warnings.warn(msg, DeprecationWarning)
204+
return self.subject_id
205+
206+
@name_id.setter
207+
def name_id(self, value):
208+
msg = "name_id is deprecated; use subject_id instead."
209+
_warnings.warn(msg, DeprecationWarning)
210+
self.subject_id = value
211+
126212
def __repr__(self):
127213
return str(self.to_dict())

0 commit comments

Comments
 (0)