Skip to content

Commit

Permalink
Faces/Ajax aware redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzi80 committed May 17, 2022
1 parent 12e37bd commit b8eefb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
19 changes: 9 additions & 10 deletions impl/src/main/java/org/glassfish/soteria/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ public static String getBaseURL(HttpServletRequest request) {
return url.substring(0, url.length() - request.getRequestURI().length()) + request.getContextPath();
}

public static void redirect(HttpServletResponse response, String location) {
try {
response.sendRedirect(location);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}

public static ELProcessor getELProcessor(String name, Object bean) {
ELProcessor elProcessor = new ELProcessor();
elProcessor.defineBean(name, bean);
Expand Down Expand Up @@ -247,6 +239,14 @@ public static CallerPrincipal toCallerPrincipal(Principal principal) {
return new WrappingCallerPrincipal(principal);
}

public static void redirect(HttpServletResponse response, String location) {
try {
response.sendRedirect(location);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}

public static void redirect(HttpServletRequest request, HttpServletResponse response, String location) {
try {
if (isFacesAjaxRequest(request)) {
Expand All @@ -266,8 +266,7 @@ public static void redirect(HttpServletRequest request, HttpServletResponse resp
}

private static final Set<String> FACES_AJAX_HEADERS = Set.of("partial/ajax", "partial/process");
private static final String FACES_AJAX_REDIRECT_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<partial-response><redirect url=\"%s\"></redirect></partial-response>";
private static final String FACES_AJAX_REDIRECT_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><partial-response><redirect url=\"%s\"></redirect></partial-response>";

public static boolean isFacesAjaxRequest(HttpServletRequest request) {
return FACES_AJAX_HEADERS.contains(request.getHeader("Faces-Request"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public void setResponse(HttpServletResponse response) {

@Override
public AuthenticationStatus redirect(String location) {
Utils.redirect(getResponse(), location);
//Utils.redirect(getResponse(), location);
Utils.redirect(getRequest(),getResponse(),location);

return SEND_CONTINUE;
}
Expand Down

0 comments on commit b8eefb6

Please sign in to comment.