【发布时间】:2013-05-16 02:28:45
【问题描述】:
目前我想重构我的项目并从网址中删除/faces/。原因很简单,我想避免,用户可以“删除”面部部分并查看底层 xhtml 文件的来源。
我正在使用 Shiro 进行身份验证。我将首先描述以前的情况(有效),然后描述新的情况,这会造成麻烦。
之前的情况:
web.xml:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
shiro.ini
[urls]
/faces/index.xhtml = authc
/faces/pages/** = authc
/faces/templates/** = authc
/faces/resources/** = authc
现状:
web.xml:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
shiro.ini
[urls]
/index.xhtml = authc
/pages/** = authc
/templates/** = authc
/resources/** = authc
对于那些可能还有“面孔”书签的人,我添加了一个过滤器,并且这样做:
HttpServletRequest srequest = (HttpServletRequest) request;
HttpServletResponse sresponse = (HttpServletResponse) response;
String url = srequest.getRequestURI().trim();
System.out.println("Filtering url: " + url);
if (url.contains("/faces/")){
url = url.replace("/faces/", "/");
System.out.println("Redirecting to: " + url);
sresponse.setStatus(HttpResponseCodes.SC_MOVED_PERMANENTLY);
sresponse.sendRedirect(url);
}else{
//no filtering required, proceed with chain.
chain.doFilter(request, response);
}
现在,当我清除浏览器的缓存并调用 http://localhost/project/login.xhtml 时,我收到大量尝试在各种资源文件夹中查找 xhtml 文件:
12:27:46,735 INFO [stdout] (http--0.0.0.0-8090-6) 过滤网址:/project/resources/css/login.xhtml
12:27:46,737 INFO [stdout] (http--0.0.0.0-8090-6) 过滤网址:/project/resources/css/login.xhtml
12:27:46,836 INFO [stdout] (http--0.0.0.0-8090-6) 过滤网址:/project/resources/js/login.xhtml
12:27:46,837 INFO [stdout] (http--0.0.0.0-8090-1) 过滤网址:/project/resources/js/login.xhtml
...
这显然是错误的。切换回 prior 布局,但保留重定向过滤器不会导致任何无效请求。
【问题讨论】:
标签: jsf servlet-filters shiro