@@ -353,37 +353,48 @@ protected NodeList query (String query) throws XPathExpressionException {
353
353
return Util .query (this .logoutResponseDocument , query , null );
354
354
}
355
355
356
- /**
357
- * Generates a Logout Response XML string.
358
- *
359
- * @param inResponseTo
360
- * InResponseTo attribute value to bet set at the Logout Response.
361
- * @param statusCode
362
- * String StatusCode to be set on the LogoutResponse
363
- */
364
- public void build (String inResponseTo , String statusCode ) {
356
+ /**
357
+ * Generates a Logout Response XML string.
358
+ *
359
+ * @param inResponseTo
360
+ * InResponseTo attribute value to bet set at the Logout Response.
361
+ * @param responseStatus
362
+ * SamlResponseStatus response status to be set on the LogoutResponse
363
+ */
364
+ public void build (String inResponseTo , SamlResponseStatus responseStatus ) {
365
365
id = Util .generateUniqueID (settings .getUniqueIDPrefix ());
366
366
issueInstant = Calendar .getInstance ();
367
367
this .inResponseTo = inResponseTo ;
368
368
369
- StrSubstitutor substitutor = generateSubstitutor (settings , statusCode );
369
+ StrSubstitutor substitutor = generateSubstitutor (settings , responseStatus );
370
370
this .logoutResponseString = postProcessXml (substitutor .replace (getLogoutResponseTemplate ()), settings );
371
371
}
372
372
373
- /**
374
- * Generates a Logout Response XML string.
375
- *
376
- * @param inResponseTo
377
- * InResponseTo attribute value to bet set at the Logout Response.
378
- */
373
+ /**
374
+ * Generates a Logout Response XML string.
375
+ *
376
+ * @param inResponseTo
377
+ * InResponseTo attribute value to bet set at the Logout Response.
378
+ * @param statusCode
379
+ * String StatusCode to be set on the LogoutResponse
380
+ */
381
+ public void build (String inResponseTo , String statusCode ) {
382
+ build (inResponseTo , new SamlResponseStatus (statusCode ));
383
+ }
384
+
385
+ /**
386
+ * Generates a Logout Response XML string.
387
+ *
388
+ * @param inResponseTo
389
+ * InResponseTo attribute value to bet set at the Logout Response.
390
+ */
379
391
public void build (String inResponseTo ) {
380
392
build (inResponseTo , Constants .STATUS_SUCCESS );
381
393
}
382
394
383
- /**
384
- * Generates a Logout Response XML string.
385
- *
386
- */
395
+ /**
396
+ * Generates a Logout Response XML string.
397
+ */
387
398
public void build () {
388
399
build (null );
389
400
}
@@ -413,12 +424,12 @@ protected String postProcessXml(final String logoutResponseXml, final Saml2Setti
413
424
*
414
425
* @param settings
415
426
* Saml2Settings object. Setting data
416
- * @param statusCode
417
- * String StatusCode to be set on the LogoutResponse
427
+ * @param responseStatus
428
+ * SamlResponseStatus response status to be set on the LogoutResponse
418
429
*
419
430
* @return the StrSubstitutor object of the LogoutResponse
420
431
*/
421
- private StrSubstitutor generateSubstitutor (Saml2Settings settings , String statusCode ) {
432
+ private StrSubstitutor generateSubstitutor (Saml2Settings settings , SamlResponseStatus responseStatus ) {
422
433
Map <String , String > valueMap = new HashMap <String , String >();
423
434
424
435
valueMap .put ("id" , Util .toXml (id ));
@@ -439,29 +450,34 @@ private StrSubstitutor generateSubstitutor(Saml2Settings settings, String status
439
450
}
440
451
valueMap .put ("inResponseStr" , inResponseStr );
441
452
442
- String statusStr = "" ;
443
- if (statusCode != null ) {
444
- statusStr = "Value=\" " + Util .toXml (statusCode ) + "\" " ;
453
+ StringBuilder statusStr = new StringBuilder ("<samlp:StatusCode " );
454
+ if (responseStatus != null ) {
455
+ String statusCode = responseStatus .getStatusCode ();
456
+ if (statusCode != null ) {
457
+ statusStr .append ("Value=\" " ).append (Util .toXml (statusCode )).append ("\" " );
458
+ String subStatusCode = responseStatus .getSubStatusCode ();
459
+ if (subStatusCode != null ) {
460
+ statusStr .append ("><samlp:StatusCode Value=\" " )
461
+ .append (Util .toXml (subStatusCode ))
462
+ .append ("\" /></samlp:StatusCode>" );
463
+ } else {
464
+ statusStr .append (" />" );
465
+ }
466
+ String statusMessage = responseStatus .getStatusMessage ();
467
+ if (statusMessage != null ) {
468
+ statusStr .append ("<samlp:StatusMessage>" )
469
+ .append (Util .toXml (statusMessage ))
470
+ .append ("</samlp:StatusMessage>" );
471
+ }
472
+ }
445
473
}
446
- valueMap .put ("statusStr" , statusStr );
474
+ valueMap .put ("statusStr" , statusStr . toString () );
447
475
448
476
valueMap .put ("issuer" , Util .toXml (settings .getSpEntityId ()));
449
477
450
478
return new StrSubstitutor (valueMap );
451
479
}
452
480
453
- /**
454
- * Substitutes LogoutResponse variables within a string by values.
455
- *
456
- * @param settings
457
- * Saml2Settings object. Setting data
458
- *
459
- * @return the StrSubstitutor object of the LogoutResponse
460
- */
461
- private StrSubstitutor generateSubstitutor (Saml2Settings settings ) {
462
- return generateSubstitutor (settings , Constants .STATUS_SUCCESS );
463
- }
464
-
465
481
/**
466
482
* @return the LogoutResponse's template
467
483
*/
@@ -473,7 +489,7 @@ private static StringBuilder getLogoutResponseTemplate() {
473
489
template .append ("IssueInstant=\" ${issueInstant}\" ${destinationStr}${inResponseStr} >" );
474
490
template .append ("<saml:Issuer>${issuer}</saml:Issuer>" );
475
491
template .append ("<samlp:Status>" );
476
- template .append ("<samlp:StatusCode ${statusStr} /> " );
492
+ template .append ("${statusStr}" );
477
493
template .append ("</samlp:Status>" );
478
494
template .append ("</samlp:LogoutResponse>" );
479
495
return template ;
0 commit comments