@@ -357,15 +357,7 @@ protected boolean isContinuationRequired(Request request) {
357357 // a resource is protected for some HTTP methods but not protected for
358358 // GET which is used after authentication when redirecting to the
359359 // protected resource.
360- // TODO: This is similar to the FormAuthenticator.matchRequest() logic
361- // Is there a way to remove the duplication?
362- Session session = request .getSessionInternal (false );
363- if (session != null ) {
364- SavedRequest savedRequest = (SavedRequest ) session .getNote (Constants .FORM_REQUEST_NOTE );
365- return savedRequest != null && decodedRequestURI .equals (savedRequest .getDecodedRequestURI ());
366- }
367-
368- return false ;
360+ return matchRequest (request , false );
369361 }
370362
371363
@@ -499,15 +491,21 @@ protected void forwardToErrorPage(Request request, HttpServletResponse response,
499491 }
500492
501493
494+ protected boolean matchRequest (Request request ) {
495+ return matchRequest (request , true );
496+ }
497+
502498 /**
503499 * Does this request match the saved one (so that it must be the redirect we signaled after successful
504500 * authentication?)
505501 *
506502 * @param request The request to be verified
503+ * @param strict <code>true</code> to check for a valid Principal and valid Session ID, <code>false</code> to only
504+ * check for a valid saved request and matching URI
507505 *
508506 * @return <code>true</code> if the requests matched the saved one
509507 */
510- protected boolean matchRequest (Request request ) {
508+ protected boolean matchRequest (Request request , boolean strict ) {
511509 // Has a session been created?
512510 Session session = request .getSessionInternal (false );
513511 if (session == null ) {
@@ -520,17 +518,19 @@ protected boolean matchRequest(Request request) {
520518 return false ;
521519 }
522520
523- // Is there a saved principal?
524- if (cache && session .getPrincipal () == null || !cache && request .getPrincipal () == null ) {
525- return false ;
526- }
527-
528- // Does session id match?
529- if (getChangeSessionIdOnAuthentication ()) {
530- String expectedSessionId = (String ) session .getNote (Constants .SESSION_ID_NOTE );
531- if (expectedSessionId == null || !expectedSessionId .equals (request .getRequestedSessionId ())) {
521+ if (strict ) {
522+ // Is there a saved principal?
523+ if (cache && session .getPrincipal () == null || !cache && request .getPrincipal () == null ) {
532524 return false ;
533525 }
526+
527+ // Does session id match?
528+ if (getChangeSessionIdOnAuthentication ()) {
529+ String expectedSessionId = (String ) session .getNote (Constants .SESSION_ID_NOTE );
530+ if (expectedSessionId == null || !expectedSessionId .equals (request .getRequestedSessionId ())) {
531+ return false ;
532+ }
533+ }
534534 }
535535
536536 // Does the request URI match?
0 commit comments