-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractMessage.java
More file actions
715 lines (674 loc) · 25.1 KB
/
AbstractMessage.java
File metadata and controls
715 lines (674 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
/*
* Copyright (C) 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.oidc.msg;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.JWTDecryptor;
import com.auth0.jwt.JWTEncryptor;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.exceptions.KeyAgreementException;
import com.auth0.jwt.exceptions.oicmsg_exceptions.JWKException;
import com.auth0.jwt.exceptions.oicmsg_exceptions.SerializationNotPossible;
import com.auth0.jwt.exceptions.oicmsg_exceptions.ValueError;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.auth0.msg.Key;
import com.auth0.msg.KeyJar;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.base.Strings;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;
import org.oidc.msg.oidc.util.AlgorithmResolver;
/**
* This abstract class provides basic processing of messages.
*/
public abstract class AbstractMessage implements Message {
/** Message request/response parameters. */
private Map<String, Object> claims;
/** Header when message is jwt like signed userinfo response. */
private Map<String, Object> header;
/** Json (de)serialization. */
private ObjectMapper mapper = new ObjectMapper();
/** Whether the message has been verified. */
private boolean verified;
/** Error if such has happened during message verification. */
protected Error error = new Error();
/** Parameter requirements. */
protected final Map<String, ParameterVerificationDefinition> paramVerDefs = new HashMap<String, ParameterVerificationDefinition>();
/** Default values for desired parameters. */
protected final Map<String, Object> defaultValues = new HashMap<String, Object>();
/** Allowed values for desired parameters. */
protected final Map<String, List<?>> allowedValues = new HashMap<String, List<?>>();
/**
* Constructor.
*
* @param claims
* message parameters
*/
public AbstractMessage(Map<String, Object> claims) {
this.claims = claims;
}
/**
* Constructs a message from the URL string.
*
* @param input
* The urlEncoded String representation of a message.
* @throws MalformedURLException
* Thrown if the message cannot be parsed from the input.
* @throws InvalidClaimException
* Thrown if the message content is invalid.
*/
public void fromUrlEncoded(String input) throws MalformedURLException, DeserializationException {
if (Strings.isNullOrEmpty(input)) {
return;
}
StringBuilder jsonBuilder = new StringBuilder("{ ");
StringTokenizer paramTokenizer = new StringTokenizer(
input.substring(input.startsWith("?") ? 1 : 0), "&");
while (paramTokenizer.hasMoreTokens()) {
String pair = paramTokenizer.nextToken();
StringTokenizer pairTokenizer = new StringTokenizer(pair, "=");
String key;
String value;
try {
key = URLDecoder.decode(pairTokenizer.nextToken(), "UTF-8");
value = URLDecoder.decode(pairTokenizer.nextToken(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new MalformedURLException("The parameters cannot be decoded using UTF-8");
}
jsonBuilder.append("\"" + key + "\" : ");
jsonBuilder.append(
value.startsWith("{") || value.startsWith("[") ? "\"" + value.replace("\"", "\\\"") + "\""
: "\"" + value + "\"");
jsonBuilder.append(paramTokenizer.hasMoreTokens() ? "," : new String());
}
jsonBuilder.append("}");
fromJson(jsonBuilder.toString());
}
/**
* Takes the claims of this instance of the AbstractMessage class and serializes them to an
* urlEncoded string.
*
* @return an urlEncoded string
* @throws SerializationException
* Thrown if message cannot be serialized.
*/
public String toUrlEncoded() throws SerializationException {
if (claims.size() == 0) {
return "";
}
JsonFactory factory = mapper.getFactory();
JsonNode rootNode;
try {
JsonParser parser = factory.createParser(this.toJson());
rootNode = mapper.readTree(parser);
} catch (IOException e) {
throw new SerializationException("Could not build the JSON", e);
}
StringBuilder query = new StringBuilder("");
Iterator<String> keys = claims.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
JsonNode value = rootNode.get(key);
try {
String pair = URLEncoder.encode(key, "UTF-8") + "="
+ URLEncoder.encode(value.asText(), "UTF-8");
query.append(keys.hasNext() ? pair + "&" : pair);
} catch (UnsupportedEncodingException e) {
throw new SerializationException("Could not URL encode the parameter", e);
}
}
return query.toString();
}
/**
* Constructs a message from the JSON string.
*
* @param input
* The JSON String representation of a message
* @throws InvalidClaimException
* Thrown if the message content is invalid.
*/
public void fromJson(String input) throws DeserializationException {
Map<String, Object> newClaims;
try {
newClaims = mapper.readValue(input, new TypeReference<Map<String, Object>>() {
});
} catch (IOException e) {
throw new DeserializationException(String.format("Unable to parse message from '%s'", input));
}
this.claims = newClaims;
verified = false;
}
/**
* Takes the parameters of this instance of the AbstractMessage class and serializes them to a
* json string.
*
* @return a JSON String representation in the form of a hashMap mapping string -> string
* @throws SerializationException
* Thrown if message cannot be serialized.
*/
public String toJson() throws SerializationException {
SimpleModule module = new SimpleModule();
module.addSerializer(AbstractMessage.class, new MessageSerializer());
mapper.registerModule(module);
try {
return mapper.writeValueAsString(this);
} catch (JsonProcessingException e) {
throw new SerializationException("Could not serialize to JSON", e);
}
}
/**
* Constructs message from JWT. If JWT has no kid defined, allows to try with any otherwise
* matching key in the bundle. Allows extending the keyjar by JKU.
*
* @param jwt
* the jwt String representation of a message
* @param keyJar
* KeyJar having a key for verifying the signature. If null, signature is not verified.
* @param keyOwner
* For whom the key belongs to.
* @throws IOException
* thrown if message parameters do not match the message requirements.
*/
public void fromJwt(String jwt, KeyJar keyJar, String keyOwner) throws DeserializationException {
fromJwt(jwt, keyJar, keyOwner, null, true, true);
}
/**
* Constructs message from JWT.
*
* @param jwt
* the jwt String representation of a message
* @param keyJar
* KeyJar having a key for verifying the signature. If null, signature is not verified.
* @param keyOwner
* For whom the key belongs to.
* @param noKidIssuers
* If jwt is missing kid, set the list of allowed kids in keyjar to verify jwt. if
* allowMissingKid is set to true, list is not used.
* @param allowMissingKid
* If jwt is missing kid, try any of the owners keys to verify jwt.
* @param trustJKU
* Whether extending keyjar by JKU is allowed or not.
* @throws DeserializationException
* Thrown if the message content is invalid.
* @throws JWTDecodeException
* Thrown if the JWT cannot be decoded.
*/
public void fromJwt(String jwt, KeyJar keyJar, String keyOwner,
Map<String, List<String>> noKidIssuers, boolean allowMissingKid, boolean trustJKU)
throws DeserializationException {
fromJwt(jwt, keyJar, keyOwner, noKidIssuers, allowMissingKid, trustJKU, null, null, null);
}
/**
* Constructs message from JWT.
*
* @param jwt
* the jwt String representation of a message
* @param keyJar
* KeyJar having a key for verifying the signature. If null, signature is not verified.
* @param keyOwner
* For whom the key belongs to.
* @param noKidIssuers
* If jwt is missing kid, set the list of allowed kids in keyjar to verify jwt. if
* allowMissingKid is set to true, list is not used.
* @param allowMissingKid
* If jwt is missing kid, try any of the owners keys to verify jwt.
* @param trustJKU
* Whether extending keyjar by JKU is allowed or not.
* @param encAlg
* The allowed id token encryption key transport algorithm
* @param encEnc
* The allowed id token encryption encryption algorithm
* @param sigAlg
* The allowed id token signing algorithm
* @throws JWTDecodeException
* Thrown if the JWT cannot be decoded.
*/
public void fromJwt(String jwt, KeyJar keyJar, String keyOwner,
Map<String, List<String>> noKidIssuers, boolean allowMissingKid, boolean trustJKU,
String encAlg, String encEnc, String sigAlg) throws JWTDecodeException {
try {
jwt = parseFromToken(jwt, keyJar, encAlg, encEnc);
if (jwt == null) {
// successfully parsed from jwe(json)
return;
}
} catch (IOException e) {
throw new JWTDecodeException(
String.format("Unable to parse JWT '%s': '%s'", jwt, e.getMessage()));
}
verified = false;
if (keyJar == null) {
return;
}
if (header.get("alg") == null || !(header.get("alg") instanceof String)) {
throw new JWTDecodeException("JWT does not have alg in header");
}
String alg = (String) header.get("alg");
if (sigAlg != null && !sigAlg.equals(alg)) {
throw new JWTDecodeException(String.format(
"JWT siging algorithm '%s' not matching the required algorithm '%s'", sigAlg, alg));
}
if ("none".equals(alg)) {
Algorithm algorithm = Algorithm.none();
JWTVerifier verifier = JWT.require(algorithm).build();
verifier.verify(jwt);
return;
}
//Now we expect to have keys
List<Key> keys;
try {
keys = keyJar.getJWTVerifyKeys(jwt, keyOwner, noKidIssuers, allowMissingKid, trustJKU);
} catch (JWKException | ValueError | IOException e) {
throw new JWTDecodeException(
String.format("Not able to locate keys to verify JWT, '%s'", e.getMessage()));
}
if (keys == null || keys.size() == 0) {
throw new JWTDecodeException("Not able to locate keys to verify JWT");
}
// We try each located key
for (Iterator<Key> iter = keys.iterator(); iter.hasNext();) {
Key key = iter.next();
try {
JWT.require(AlgorithmResolver.resolveVerificationAlgorithm(key, alg)).build().verify(jwt);
// Success
return;
} catch (JWTVerificationException | IllegalArgumentException | ValueError
| UnsupportedEncodingException | SerializationNotPossible e) {
if (iter.hasNext()) {
//We move on to try next key
continue;
} else {
throw new JWTDecodeException(String.format("Unable to verify JWT: '%s'", e.getMessage()));
}
}
}
throw new JWTDecodeException("Not able to verify JWT with any of the keys provided");
}
/**
* Parses header and claims from JWT.
* @param jwt jwt to parse.
* @throws IOException if parsing fails.
*/
@SuppressWarnings("unchecked")
private void parseFromJwt(String jwt)
throws IOException {
String[] parts = MessageUtil.splitToken(jwt);
String headerJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[0]));
String payloadJson = StringUtils.newStringUtf8(Base64.decodeBase64(parts[1]));
this.header = mapper.readValue(headerJson, Map.class);
this.claims = mapper.readValue(payloadJson, Map.class);
}
/**
* Parses header and claims from JWT or from JWE.
*
* @param token
* jwe/jwt to parse from
* @param keyJar
* key jar used, must not be null for jwe
* @param keyOwner
* key owner, may be null
* @param encAlg
* key transport algorithm required, may be null.
* @param encEnc
* enc algorithm required, may be null.
* @return jwt or null if response was json
* @throws JWTDecodeException
* if unable to decrypt jwe
* @throws IOException
* if parsing of jwt fails
*/
private String parseFromToken(String token, KeyJar keyJar, String encAlg, String encEnc)
throws JWTDecodeException, IOException {
DecodedJWT decodedJwt = JWT.decode(token);
if (!decodedJwt.isJWE()) {
parseFromJwt(token);
return token;
}
if (keyJar == null) {
throw new JWTDecodeException("KeyJar not set for decrypting JWE");
}
List<Key> keys = keyJar.getDecryptKey(null, "", decodedJwt.getKeyId(), null);
//We try with each suitable private key we have
for (Iterator<Key> iter = keys.iterator(); iter.hasNext();) {
Key key = iter.next();
Algorithm decyptionAlg;
try {
decyptionAlg = AlgorithmResolver.resolveKeyTransportAlgorithmForDecryption(key, decodedJwt);
} catch (ValueError | UnsupportedEncodingException | SerializationNotPossible e) {
if (iter.hasNext()) {
// We move on to try next key
continue;
} else {
throw new JWTDecodeException(
String.format("Unable to decrypt JWE: '%s'", e.getMessage()));
}
}
JWTDecryptor decryptor = new JWTDecryptor(decyptionAlg);
String decryptedJwe = new String(decryptor.decrypt(token));
// Now we have a string that should be either jwt or json
try {
parseFromJwt(decryptedJwe);
return decryptedJwe;
} catch (Exception e) {
// no op, we try our luck with json
}
try {
fromJson(decryptedJwe);
return null;
} catch (Exception e) {
// no op if we have still more keys
if (iter.hasNext()) {
continue;
} else {
throw new JWTDecodeException(
String.format("Unable to decode decrypted JWE '%s'", decryptedJwe));
}
}
}
throw new JWTDecodeException("Unable to decrypt JWE with any of the keys provided");
}
/**
* Serialize the content of this instance (the claims map) into a jwt string.
*
* @param signingKey
* signing key
* @param alg
* signing algorithm name
* @param transportKey
* key transport key, if null encryption is not done.
* @param encAlg
* key transport algorithm name. Must not be null if transportKey is set.
* @param encEnc
* content encryption algorithm name. Must not be null if transportKey is set.
* @param keyjar
* key jar containing receiver ephemeral public key when using ECDH family of key transport
* @param sender
* sender i.e. client id
* @param receiver
* receiver i.e. issuer id of the o.
* @return message as jwt string.
*/
public String toJwt(Key signingKey, String alg, Key transportKey, String encAlg, String encEnc, KeyJar keyjar, String sender, String receiver)
throws SerializationException {
header = new HashMap<String, Object>();
header.put("alg", alg);
header.put("typ", "JWT");
if (signingKey != null && !Strings.isNullOrEmpty(signingKey.getKid())) {
header.put("kid", signingKey.getKid());
}
Algorithm algorithm = null;
try {
algorithm = AlgorithmResolver.resolveSigningAlgorithm(signingKey, alg);
} catch (IllegalArgumentException | ValueError | UnsupportedEncodingException
| SerializationNotPossible e) {
throw new SerializationException(String
.format("Not able to initialize algorithm '%s' to sign JWT, '%s'", alg, e.getMessage()));
}
JWTCreator.Builder newBuilder = JWT.create().withHeader(this.header);
for (String claimName : claims.keySet()) {
Object value = claims.get(claimName);
if (value instanceof Boolean) {
newBuilder.withClaim(claimName, (Boolean) value);
} else if (value instanceof String) {
newBuilder.withClaim(claimName, (String) value);
} else if (value instanceof Date) {
newBuilder.withClaim(claimName, (Date) value);
} else if (value instanceof Long) {
newBuilder.withClaim(claimName, (Long) value);
} else if (value instanceof List<?>) {
if (((List<?>) value).get(0) instanceof String) {
newBuilder.withArrayClaim(claimName, ((List<?>) value).toArray(new String[0]));
} else if (((List<?>) value).get(0) instanceof Long) {
newBuilder.withArrayClaim(claimName, ((List<?>) value).toArray(new Long[0]));
}
}
}
String signedJwt = newBuilder.sign(algorithm);
if (transportKey == null) {
return signedJwt;
}
if (encAlg == null || encEnc == null) {
throw new SerializationException(
"encAlg and encEnc are mandatory parameters if transport key is set");
}
try {
Algorithm keyTransportAlgorithm = AlgorithmResolver.resolveKeyTransportAlgorithmForEncryption(
transportKey, encAlg, encEnc, keyjar, sender, receiver);
Algorithm contentEncryptionAlgorithm = AlgorithmResolver
.resolveContentEncryptionAlg(keyTransportAlgorithm, encEnc);
return JWTEncryptor.init().withPayload(signedJwt.getBytes("UTF-8"))
.encrypt(keyTransportAlgorithm, contentEncryptionAlgorithm);
} catch (UnsupportedEncodingException | ValueError | SerializationNotPossible
| KeyAgreementException e) {
throw new SerializationException(
String.format("Not able to initialize key transport algorithm '%s' to encrypt JWS, '%s'",
encAlg, e.getMessage()));
}
}
/**
* Adds default values to the claims which are not yet set.
*/
protected void addDefaultValues() {
for (String key : defaultValues.keySet()) {
if (!this.claims.containsKey(key)) {
this.claims.put(key, defaultValues.get(key));
}
}
}
/**
* Verifies the presence of required message parameters. Verifies the the format of message
* parameters.
*
* @param paramVerDefs verification parameters. Must not be null.
*/
private void verifyParameters(Map<String, ParameterVerificationDefinition> paramVerDefs) {
for (String paramName : paramVerDefs.keySet()) {
// If parameter is defined as REQUIRED, it must exist.
if (paramVerDefs.get(paramName).isRequired()
&& (!claims.containsKey(paramName) || claims.get(paramName) == null)) {
ErrorDetails details = new ErrorDetails(paramName, ErrorType.MISSING_REQUIRED_VALUE);
error.getDetails().add(details);
}
Object value = claims.get(paramName);
if (value == null) {
continue;
}
// If parameter exists, we verify the type of it and possibly transform it.
try {
Object transformed = paramVerDefs.get(paramName).getClaimValidator().validate(value);
claims.put(paramName, transformed);
} catch (InvalidClaimException e) {
ErrorDetails details = new ErrorDetails(paramName, ErrorType.INVALID_VALUE_FORMAT, e);
error.getDetails().add(details);
}
}
for (String paramName : allowedValues.keySet()) {
if (claims.containsKey(paramName)) {
Object value = claims.get(paramName);
List<?> allowed = allowedValues.get(paramName);
boolean checked = true;
if (allowed.isEmpty()) {
checked = false;
}
if (value instanceof String) {
String[] values = ((String) value).split(" ");
for (String item : values) {
if (!(allowed.get(0) instanceof String) || !allowed.contains(item)) {
checked = false;
}
}
} else if (value instanceof Long) {
if (!(allowed.get(0) instanceof Long) || !allowed.contains(value)) {
checked = false;
}
} else if (value instanceof List) {
for (Object item : (List<?>) value) {
if (!allowed.contains(item)) {
checked = false;
}
}
// Should we support more value types?
} else {
checked = false;
}
if (!checked) {
ErrorDetails details = new ErrorDetails(paramName, ErrorType.VALUE_NOT_ALLOWED);
error.getDetails().add(details);
}
}
}
}
/**
* Verifies the presence of required message parameters. Verifies the the format of message
* parameters. If any messages extending this class wants to do any additional verifications, they
* should implement it in the doVerify() method.
*
* @return true if parameters are successfully verified.
*/
public final boolean verify() {
error.getDetails().clear();
Map<String, ParameterVerificationDefinition> paramVerDefs =
getParameterVerificationDefinitions();
if (paramVerDefs != null && !paramVerDefs.isEmpty()) {
verifyParameters(paramVerDefs);
if (!isValidStructure()) {
setVerified(false);
return false;
}
}
doVerify();
setVerified(!hasError());
return !hasError();
}
/**
* Extension point for any extending classes to add further verifications to the message. If any
* errors are found, the implementations must add the details to the list getError().getDetails().
*/
protected void doVerify() {
}
/**
* Tests if the structure is valid, i.e. parameters are not having unexpected format in the value.
*
* @return true if structure is verified.
*/
protected boolean isValidStructure() {
for (ErrorDetails details : error.getDetails()) {
if (ErrorType.INVALID_VALUE_FORMAT.equals(details.getErrorType())) {
return false;
}
}
return true;
}
/**
* Get the jwe/jwt header of the message. Header exists only if the message is deserialized from
* or serialized to jwe/jwt. If the message is serialized to, the header is the outermost header.
* If message is deserialized from, then header is the innermost header.
*
* @return header.
*/
public Map<String, Object> getHeader() {
return header;
}
/**
* Get error description of message parameter verification.
*
* @return Error an object representing the error status of message parameter verification.
*/
public Error getError() {
return error;
}
/**
* Get the message parameters.
*
* @return List of the list of claims for this message
*/
public Map<String, Object> getClaims() {
return this.claims;
}
/**
* add the claim to this instance of message.
*
* @param name
* the name of the claim
* @param value
* the value of the claim to add to this instance of Message
*/
public void addClaim(String name, Object value) {
this.claims.put(name, value);
verified = false;
}
/**
* Get parameter verification definitions.
*
* @return parameter verification definitions
*/
public Map<String, ParameterVerificationDefinition> getParameterVerificationDefinitions() {
return this.paramVerDefs;
}
/**
* Whether there is an error in verification.
*
* @return boolean for whether there is an error in verification.
*/
public boolean hasError() {
return !error.getDetails().isEmpty();
}
/**
* Whether the claims have been verified after last change.
*
* @return true if verified, false otherwise.
*/
public boolean isVerified() {
return verified;
}
/**
* Extending classes to set status.
*
* @param verified
* false if the verification has failed in the extending class.
*/
protected void setVerified(boolean verified) {
this.verified = verified;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
// Override to return user friendly value
return super.toString();
}
}