|
65 | 65 | import com.nimbusds.jose.JWSAlgorithm;
|
66 | 66 |
|
67 | 67 | import static org.mitre.util.JsonUtils.base64UrlDecodeObject;
|
68 |
| -import static org.mitre.util.JsonUtils.base64UrlEncodeObject; |
69 | 68 | import static org.mitre.util.JsonUtils.readMap;
|
70 | 69 | import static org.mitre.util.JsonUtils.readSet;
|
71 | 70 | import static org.mitre.util.JsonUtils.writeNullSafeArray;
|
@@ -211,66 +210,78 @@ private void writeAuthenticationHolders(JsonWriter writer) throws IOException {
|
211 | 210 | for (AuthenticationHolderEntity holder : authHolderRepository.getAll()) {
|
212 | 211 | writer.beginObject();
|
213 | 212 | writer.name("id").value(holder.getId());
|
214 |
| - writer.name("authentication"); |
| 213 | + |
| 214 | + writer.name("requestParameters"); |
215 | 215 | writer.beginObject();
|
216 |
| - writer.name("authorizationRequest"); |
217 |
| - OAuth2Authentication oa2Auth = holder.getAuthentication(); |
218 |
| - writeAuthorizationRequest(oa2Auth.getOAuth2Request(), writer); |
219 |
| - String userAuthentication = base64UrlEncodeObject(oa2Auth.getUserAuthentication()); |
220 |
| - writer.name("userAuthentication").value(userAuthentication); |
| 216 | + for (Entry<String, String> entry : holder.getRequestParameters().entrySet()) { |
| 217 | + writer.name(entry.getKey()).value(entry.getValue()); |
| 218 | + } |
221 | 219 | writer.endObject();
|
| 220 | + writer.name("clientId").value(holder.getClientId()); |
| 221 | + Set<String> scope = holder.getScope(); |
| 222 | + writer.name("scope"); |
| 223 | + writer.beginArray(); |
| 224 | + for (String s : scope) { |
| 225 | + writer.value(s); |
| 226 | + } |
| 227 | + writer.endArray(); |
| 228 | + writer.name("resourceIds"); |
| 229 | + writer.beginArray(); |
| 230 | + if (holder.getResourceIds() != null) { |
| 231 | + for (String s : holder.getResourceIds()) { |
| 232 | + writer.value(s); |
| 233 | + } |
| 234 | + } |
| 235 | + writer.endArray(); |
| 236 | + writer.name("authorities"); |
| 237 | + writer.beginArray(); |
| 238 | + for (GrantedAuthority authority : holder.getAuthorities()) { |
| 239 | + writer.value(authority.getAuthority()); |
| 240 | + } |
| 241 | + writer.endArray(); |
| 242 | + writer.name("approved").value(holder.isApproved()); |
| 243 | + writer.name("redirectUri").value(holder.getRedirectUri()); |
| 244 | + writer.name("responseTypes"); |
| 245 | + writer.beginArray(); |
| 246 | + for (String s : holder.getResponseTypes()) { |
| 247 | + writer.value(s); |
| 248 | + } |
| 249 | + writer.endArray(); |
| 250 | + writer.name("extensions"); |
| 251 | + writer.beginObject(); |
| 252 | + for (Entry<String, Serializable> entry : holder.getExtensions().entrySet()) { |
| 253 | + // while the extension map itself is Serializable, we enforce storage of Strings |
| 254 | + if (entry.getValue() instanceof String) { |
| 255 | + writer.name(entry.getKey()).value((String) entry.getValue()); |
| 256 | + } else { |
| 257 | + logger.warn("Skipping non-string extension: " + entry); |
| 258 | + } |
| 259 | + } |
222 | 260 | writer.endObject();
|
223 |
| - logger.debug("Wrote authentication holder {}", holder.getId()); |
224 |
| - } |
225 |
| - logger.info("Done writing authentication holders"); |
226 |
| - } |
227 | 261 |
|
228 |
| - //used by writeAuthenticationHolders |
229 |
| - private void writeAuthorizationRequest(OAuth2Request authReq, JsonWriter writer) throws IOException { |
230 |
| - writer.beginObject(); |
231 |
| - writer.name("requestParameters"); |
232 |
| - writer.beginObject(); |
233 |
| - for (Entry<String, String> entry : authReq.getRequestParameters().entrySet()) { |
234 |
| - writer.name(entry.getKey()).value(entry.getValue()); |
235 |
| - } |
236 |
| - writer.endObject(); |
237 |
| - writer.name("clientId").value(authReq.getClientId()); |
238 |
| - Set<String> scope = authReq.getScope(); |
239 |
| - writer.name("scope"); |
240 |
| - writer.beginArray(); |
241 |
| - for (String s : scope) { |
242 |
| - writer.value(s); |
243 |
| - } |
244 |
| - writer.endArray(); |
245 |
| - writer.name("resourceIds"); |
246 |
| - writer.beginArray(); |
247 |
| - if (authReq.getResourceIds() != null) { |
248 |
| - for (String s : authReq.getResourceIds()) { |
249 |
| - writer.value(s); |
| 262 | + writer.name("savedUserAuthentication"); |
| 263 | + if (holder.getUserAuth() != null) { |
| 264 | + writer.beginObject(); |
| 265 | + writer.name("name").value(holder.getUserAuth().getName()); |
| 266 | + writer.name("sourceClass").value(holder.getUserAuth().getSourceClass()); |
| 267 | + |
| 268 | + writer.name("authorities"); |
| 269 | + writer.beginArray(); |
| 270 | + for (GrantedAuthority authority : holder.getUserAuth().getAuthorities()) { |
| 271 | + writer.value(authority.getAuthority()); |
| 272 | + } |
| 273 | + writer.endArray(); |
| 274 | + |
| 275 | + writer.endObject(); |
| 276 | + } else { |
| 277 | + writer.nullValue(); |
250 | 278 | }
|
| 279 | + |
| 280 | + |
| 281 | + writer.endObject(); |
| 282 | + logger.debug("Wrote authentication holder {}", holder.getId()); |
251 | 283 | }
|
252 |
| - writer.endArray(); |
253 |
| - writer.name("authorities"); |
254 |
| - writer.beginArray(); |
255 |
| - for (GrantedAuthority authority : authReq.getAuthorities()) { |
256 |
| - writer.value(authority.getAuthority()); |
257 |
| - } |
258 |
| - writer.endArray(); |
259 |
| - writer.name("approved").value(authReq.isApproved()); |
260 |
| - writer.name("redirectUri").value(authReq.getRedirectUri()); |
261 |
| - writer.name("responseTypes"); |
262 |
| - writer.beginArray(); |
263 |
| - for (String s : authReq.getResponseTypes()) { |
264 |
| - writer.value(s); |
265 |
| - } |
266 |
| - writer.endArray(); |
267 |
| - writer.name("extensions"); |
268 |
| - writer.beginObject(); |
269 |
| - for (Entry<String, Serializable> entry : authReq.getExtensions().entrySet()) { |
270 |
| - writer.name(entry.getKey()).value(base64UrlEncodeObject(entry.getValue())); |
271 |
| - } |
272 |
| - writer.endObject(); |
273 |
| - writer.endObject(); |
| 284 | + logger.info("Done writing authentication holders"); |
274 | 285 | }
|
275 | 286 |
|
276 | 287 | /**
|
|
0 commit comments