我正在使用 SPRING URL 安全性来保护我的 url 资源。
这在我的部署描述符(web.xml)中配置如下:
<filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
SPRING SECURITY XML 配置文件中的配置。
<http use-expressions="true" auto-config="false" disable-url-rewriting="true" access-decision-manager-ref="urlSecurityAccessDecisionManager" > <access-denied-handler ref="accessDeniedHandler" /> <!--if access is denied (false) I'll be redirected to some JSP--> <intercept-url pattern="/getGroupMembers.action*" access="isAuthenticated() and (request.getParameter('groupId')!= null ? amIAMemberOfThisGroup(request.getParameter('groupId')) : true)"/>
amIAMemberOfThisGroup(int groupId) 的实现如下:
public boolean amIAMemberOfThisGroup(int groupId) throws Exception { Group group = getEntityManager().find(Group.class, groupId); if (group == null) { throw new Exception("Group not found. Invalid Group Id:" + groupId + ."); } //if logged in user is member of this group return true else false }
这对结果 true 和 false true 都适用——它返回我的 URL false 请求的资源/数据——它将我重定向到 accessDenied 页面。
如果我传递诸如 /getGroupMembers.action?groupId=678342 之类的值,而 DB 中没有任何组退出,则该方法会适当地抛出异常,因为与 groupId 相对应的组为空。但是我的 Web 应用程序只是将我重定向到空白页面。我的 URL 安全性中是否缺少任何配置,以便如果执行访问检查的方法抛出任何异常,我可以重定向到常见错误页面?