从security-constraint中排除欢迎页面或webroot(/ only)

时间:2012-07-12 07:03:35

标签: java security struts2

我正在努力使用web.xml配置 这就是我所拥有的

<welcome-file-list> 
<welcome-file>/jsp/index.jsp</welcome-file> 
</welcome-file-list> 

<security-constraint> 
<display-name>Unsecure pages</display-name> 
<web-resource-collection> 
<web-resource-name>Unsecure pages</web-resource-name> 
<url-pattern>/jsp/index.jsp</url-pattern> 
</web-resource-collection> 
</security-constraint> 


<security-constraint> 
<display-name>Secure root resources</display-name> 
<web-resource-collection> 
<web-resource-name>Secure root resources</web-resource-name> 
<url-pattern>/*</url-pattern> 
</web-resource-collection> 
<auth-constraint> 
<role-name>RoleA</role-name> 
</auth-constraint> 
</security-constraint> 


<security-constraint> 
<display-name>Specific secure recourses</display-name> 
<web-resource-collection> 
<web-resource-name>Specific secure recourses</web-resource-name> 
<url-pattern>/home</url-pattern> 
<url-pattern>/search</url-pattern> 
</web-resource-collection> 
<auth-constraint> 
<role-name>RoleA</role-name> 
<role-name>RoleB</role-name> 
</auth-constraint> 
</security-constraint> 

and in the index.jsp i have this 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<title>TITLE</title> 
<meta http-equiv="REFRESH" content="0; url=/mpbo/home"></HEAD> 
</HTML> 

我想要实现的是RoleA应该具有对站点的完全访问权限,而RoleB应该只能访问主页和搜索页面 主页是RoleA和RoleB的默认值

我遇到的问题只与RoleB中的用户有关 当我作为RoleB的用户去了 http://localhost:8080/mpbo/我被提示登录页面,我登录工作正常,然后重定向到/jsp/index.jsp(欢迎文件),尝试将我重定向到/ mpbo / home文件夹,但在这里,我得到访问被拒绝。 如果我在登录后直接浏览到/ mpbo / home文件夹,则成功 如果我直接浏览到/jsp/index.jsp文件,它会成功地将我重定向到/ mpbo / home页面

所以我认为问题在于它实际上有一个约束。 我尝试使用/ only和no约束添加url模式,甚至使用RoleA和RoleB,但它也不起作用。

任何想法我怎么能让这个工作?

0 个答案:

没有答案