diff --git a/shiro-faces/pom.xml b/shiro-faces/pom.xml index 851095a..80fa7a1 100644 --- a/shiro-faces/pom.xml +++ b/shiro-faces/pom.xml @@ -36,6 +36,10 @@ ${elapi.version} provided + + javax + javaee-api + \ No newline at end of file diff --git a/shiro-faces/src/main/java/de/muehlencord/shirofaces/filter/FacesAjaxAwarePassThruAuthenticationFilter.java b/shiro-faces/src/main/java/de/muehlencord/shirofaces/filter/FacesAjaxAwarePassThruAuthenticationFilter.java new file mode 100644 index 0000000..d14e48a --- /dev/null +++ b/shiro-faces/src/main/java/de/muehlencord/shirofaces/filter/FacesAjaxAwarePassThruAuthenticationFilter.java @@ -0,0 +1,35 @@ +package de.muehlencord.shirofaces.filter; + +import java.io.IOException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter; + +/** + * found at http://balusc.omnifaces.org/2013/01/apache-shiro-is-it-ready-for-java-ee-6.html#MakeShiroJSFAjaxAware) + * source by BalusC, adjusted to PassThruAuthenticationFilter by Joern Muehlencord + * @author BalusC + * @author Joern Muehlencord + */ +public class FacesAjaxAwarePassThruAuthenticationFilter extends PassThruAuthenticationFilter { + + private static final String FACES_REDIRECT_XML = "" + + ""; + + + @Override + protected void redirectToLogin(ServletRequest req, ServletResponse res) throws IOException { + HttpServletRequest request = (HttpServletRequest) req; + + if ("partial/ajax".equals(request.getHeader("Faces-Request"))) { + res.setContentType("text/xml"); + res.setCharacterEncoding("UTF-8"); + res.getWriter().printf(FACES_REDIRECT_XML, request.getContextPath() + getLoginUrl()); + } + else { + super.redirectToLogin(req, res); + } + } + +}