@@ -87,6 +87,14 @@ private SamlAttributes authenticateResponse(Element element, Collection<String>
87
87
if (logger .isTraceEnabled ()) {
88
88
logger .trace (SamlUtils .describeSamlObject (response ));
89
89
}
90
+ final boolean requireSignedAssertions ;
91
+ if (response .isSigned ()) {
92
+ validateSignature (response .getSignature ());
93
+ requireSignedAssertions = false ;
94
+ } else {
95
+ requireSignedAssertions = true ;
96
+ }
97
+
90
98
if (Strings .hasText (response .getInResponseTo ()) && allowedSamlRequestIds .contains (response .getInResponseTo ()) == false ) {
91
99
logger .debug ("The SAML Response with ID {} is unsolicited. A user might have used a stale URL or the Identity Provider " +
92
100
"incorrectly populates the InResponseTo attribute" , response .getID ());
@@ -102,10 +110,10 @@ private SamlAttributes authenticateResponse(Element element, Collection<String>
102
110
throw samlException ("SAML Response is not a 'success' response: Code={} Message={} Detail={}" ,
103
111
status .getStatusCode ().getValue (), getMessage (status ), getDetail (status ));
104
112
}
105
-
113
+ checkIssuer ( response . getIssuer (), response );
106
114
checkResponseDestination (response );
107
115
108
- Tuple <Assertion , List <Attribute >> details = extractDetails (response , allowedSamlRequestIds );
116
+ Tuple <Assertion , List <Attribute >> details = extractDetails (response , allowedSamlRequestIds , requireSignedAssertions );
109
117
final Assertion assertion = details .v1 ();
110
118
final SamlNameId nameId = SamlNameId .forSubject (assertion .getSubject ());
111
119
final String session = getSessionIndex (assertion );
@@ -156,17 +164,8 @@ private void checkResponseDestination(Response response) {
156
164
}
157
165
}
158
166
159
- private Tuple <Assertion , List <Attribute >> extractDetails (Response response , Collection <String > allowedSamlRequestIds ) {
160
- final boolean requireSignedAssertions ;
161
- if (response .isSigned ()) {
162
- validateSignature (response .getSignature ());
163
- requireSignedAssertions = false ;
164
- } else {
165
- requireSignedAssertions = true ;
166
- }
167
-
168
- checkIssuer (response .getIssuer (), response );
169
-
167
+ private Tuple <Assertion , List <Attribute >> extractDetails (Response response , Collection <String > allowedSamlRequestIds ,
168
+ boolean requireSignedAssertions ) {
170
169
final int assertionCount = response .getAssertions ().size () + response .getEncryptedAssertions ().size ();
171
170
if (assertionCount > 1 ) {
172
171
throw samlException ("Expecting only 1 assertion, but response contains multiple (" + assertionCount + ")" );
@@ -328,5 +327,4 @@ private void checkLifetimeRestrictions(Conditions conditions) {
328
327
private void checkLifetimeRestrictions (SubjectConfirmationData subjectConfirmationData ) {
329
328
validateNotOnOrAfter (subjectConfirmationData .getNotOnOrAfter ());
330
329
}
331
-
332
330
}
0 commit comments