You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lp...@apache.org on 2023/04/11 00:58:25 UTC
[shiro] branch main updated: enh(jakarta-ee): Jakarta Faces ajax resubmit remember-me stateless doesn't require page reload
This is an automated email from the ASF dual-hosted git repository.
lprimak pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shiro.git
The following commit(s) were added to refs/heads/main by this push:
new 38eca14e enh(jakarta-ee): Jakarta Faces ajax resubmit remember-me stateless doesn't require page reload
38eca14e is described below
commit 38eca14ebc970421ed1c2de0d4d1733b17198fde
Author: lprimak <le...@flowlogix.com>
AuthorDate: Mon Apr 10 19:57:18 2023 -0500
enh(jakarta-ee): Jakarta Faces ajax resubmit remember-me stateless doesn't require page reload
---
.gitignore | 1 +
.../org/apache/shiro/ee/filters/FormResubmitSupport.java | 16 ++++++++++------
.../org/apache/shiro/ee/filters/FormSupportTest.java | 9 +++++----
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/.gitignore b/.gitignore
index 173f87a1..6536a976 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,3 +51,4 @@ target/
release.properties
pom.xml.*
-
+.sdkmanrc
diff --git a/support/jakarta-ee/src/main/java/org/apache/shiro/ee/filters/FormResubmitSupport.java b/support/jakarta-ee/src/main/java/org/apache/shiro/ee/filters/FormResubmitSupport.java
index fb7e9b95..3c8d8090 100644
--- a/support/jakarta-ee/src/main/java/org/apache/shiro/ee/filters/FormResubmitSupport.java
+++ b/support/jakarta-ee/src/main/java/org/apache/shiro/ee/filters/FormResubmitSupport.java
@@ -122,6 +122,7 @@ public class FormResubmitSupport {
static class PartialAjaxResult {
public final String result;
public final boolean isPartialAjaxRequest;
+ public final boolean isStatelessRequest;
}
static void savePostDataForResubmit(HttpServletRequest request, HttpServletResponse response, @NonNull String loginUrl) {
@@ -362,7 +363,7 @@ public class FormResubmitSupport {
.build();
HttpResponse<String> response = client.send(postRequest, HttpResponse.BodyHandlers.ofString());
log.debug("Resubmit request: {}, response: {}", postRequest, response);
- if (rememberedAjaxResubmit) {
+ if (rememberedAjaxResubmit && !decodedFormData.isStatelessRequest) {
HttpRequest redirectRequest = HttpRequest.newBuilder().uri(URI.create(savedRequest))
.POST(HttpRequest.BodyPublishers.ofString(savedFormData))
.headers(CONTENT_TYPE, APPLICATION_FORM_URLENCODED)
@@ -375,19 +376,22 @@ public class FormResubmitSupport {
deleteCookie(originalResponse, servletContext, SHIRO_FORM_DATA_KEY);
return processResubmitResponse(response, originalRequest, originalResponse,
response.headers(), savedRequest, servletContext,
- decodedFormData.isPartialAjaxRequest, rememberedAjaxResubmit);
+ decodedFormData.isStatelessRequest ? false : decodedFormData.isPartialAjaxRequest,
+ rememberedAjaxResubmit);
}
}
private static PartialAjaxResult parseFormData(String savedFormData, String savedRequest,
HttpClient client, ServletContext servletContext) throws IOException, InterruptedException {
+ boolean isStateless = true;
if (!isJSFClientStateSavingMethod(servletContext)) {
String decodedFormData = URLDecoder.decode(savedFormData, StandardCharsets.UTF_8);
if (isJSFStatefulForm(decodedFormData)) {
+ isStateless = false;
savedFormData = getJSFNewViewState(savedRequest, client, decodedFormData);
}
}
- return noJSFAjaxRequests(savedFormData);
+ return noJSFAjaxRequests(savedFormData, isStateless);
}
@SuppressWarnings("fallthrough")
@@ -495,11 +499,11 @@ public class FormResubmitSupport {
return savedFormData;
}
- static PartialAjaxResult noJSFAjaxRequests(String savedFormData) {
+ static PartialAjaxResult noJSFAjaxRequests(String savedFormData, boolean isStateless) {
var partialMatcher = PARTIAL_REQUEST_PATTERN.matcher(savedFormData);
boolean hasPartialAjax = partialMatcher.find();
- return new PartialAjaxResult(INITIAL_AMPERSAND.matcher(partialMatcher
- .replaceAll("")).replaceFirst(""), hasPartialAjax);
+ return new PartialAjaxResult(isStateless ? savedFormData : INITIAL_AMPERSAND.matcher(partialMatcher
+ .replaceAll("")).replaceFirst(""), hasPartialAjax, isStateless);
}
static boolean isJSFStatefulForm(@NonNull String savedFormData) {
diff --git a/support/jakarta-ee/src/test/java/org/apache/shiro/ee/filters/FormSupportTest.java b/support/jakarta-ee/src/test/java/org/apache/shiro/ee/filters/FormSupportTest.java
index 27f2332e..2d68b8ed 100644
--- a/support/jakarta-ee/src/test/java/org/apache/shiro/ee/filters/FormSupportTest.java
+++ b/support/jakarta-ee/src/test/java/org/apache/shiro/ee/filters/FormSupportTest.java
@@ -126,13 +126,14 @@ public class FormSupportTest {
void noAjaxRequests() {
assertEquals(
new PartialAjaxResult(
- jakartify("aaa=bbb&javax.faces.ViewState=-123:-456&hello=bye"), true),
+ jakartify("aaa=bbb&javax.faces.ViewState=-123:-456&hello=bye"),
+ true, false),
noJSFAjaxRequests(jakartify("aaa=bbb&javax.faces.ViewState=-123:-456")
- + jakartify("&javax.faces.partial.ajax=true&hello=bye")));
+ + jakartify("&javax.faces.partial.ajax=true&hello=bye"), false));
assertEquals(new PartialAjaxResult("j_idt12=j_idt12&j_idt12:j_idt14=asdf&j_idt12:j_idt16=asdf"
+ jakartify("&javax.faces.ViewState=7709788254588873136:-8052771455757429917")
+ jakartify("&javax.faces.source=j_idt12:j_idt18")
- + jakartify("&javax.faces.behavior.event=action"), true),
+ + jakartify("&javax.faces.behavior.event=action"), true, false),
noJSFAjaxRequests("j_idt12=j_idt12&j_idt12:j_idt14=asdf&j_idt12:j_idt16=asdf"
+ jakartify("&javax.faces.ViewState=7709788254588873136:-8052771455757429917")
+ jakartify("&javax.faces.source=j_idt12:j_idt18")
@@ -140,7 +141,7 @@ public class FormSupportTest {
+ jakartify("&javax.faces.partial.execute=j_idt12:j_idt18 j_idt12")
+ jakartify("&javax.faces.partial.render=j_idt12")
+ jakartify("&javax.faces.behavior.event=action")
- + jakartify("&javax.faces.partial.ajax=false")));
+ + jakartify("&javax.faces.partial.ajax=false"), false));
}
@Test