1
1
"""Internal data representation for SAML/OAuth/OpenID connect."""
2
2
3
3
4
+ import warnings as _warnings
5
+
6
+
7
+ _warnings .simplefilter ("default" )
8
+
9
+
4
10
class AuthenticationInformation (object ):
5
11
"""
6
12
Class that holds information about the authentication
@@ -65,6 +71,10 @@ def __init__(
65
71
subject_id = None ,
66
72
subject_type = None ,
67
73
attributes = None ,
74
+ user_id = None ,
75
+ user_id_hash_type = None ,
76
+ name_id = None ,
77
+ approved_attributes = None ,
68
78
):
69
79
"""
70
80
:param auth_info:
@@ -86,24 +96,39 @@ def __init__(
86
96
self .requester_name = requester_name or [
87
97
{"text" : requester , "lang" : "en" }
88
98
]
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
+ )
92
108
93
109
def to_dict (self ):
94
110
"""
95
111
Converts an InternalData object to a dict
96
112
:rtype: dict[str, str]
97
113
:return: A dict representation of the object
98
114
"""
99
- return {
115
+ data = {
100
116
"auth_info" : self .auth_info .to_dict (),
101
117
"requester" : self .requester ,
102
118
"requester_name" : self .requester_name ,
103
119
"attributes" : self .attributes ,
104
120
"subject_id" : self .subject_id ,
105
121
"subject_type" : self .subject_type ,
106
122
}
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
107
132
108
133
@classmethod
109
134
def from_dict (cls , data ):
@@ -114,7 +139,7 @@ def from_dict(cls, data):
114
139
:return: An InternalData object
115
140
"""
116
141
auth_info = data .get ("auth_info" , AuthenticationInformation ())
117
- return cls (
142
+ instance = cls (
118
143
auth_info = AuthenticationInformation .from_dict (auth_info ),
119
144
requester = data .get ("requester" ),
120
145
requester_name = data .get ("requester_name" ),
@@ -123,5 +148,66 @@ def from_dict(cls, data):
123
148
attributes = data .get ("attributes" ),
124
149
)
125
150
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
+
126
212
def __repr__ (self ):
127
213
return str (self .to_dict ())
0 commit comments