我不知道我是否帮到你!由于我的知识有限,我认为为了实现安全性,使用一个或多个web-resource-collection元素声明要保护的内容。每个web-resource-collection元素都包含一系列可选的url-pattern元素,后跟一系列可选的http-method元素。 url-pattern元素值指定一个URL模式,请求URL必须与该模式匹配,以便与尝试访问受保护内容相对应。 http-method元素值指定要允许的HTTP请求的类型。
<security-constraint> <web-resource-collection> <web-resource-name>Secure Content</web-resource-name> <url-pattern>/restricted/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>AuthorizedUser</role-name> </auth-constraint> <user-data-constraint> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> </security-constraint> <!-- ... --> <login-config> <auth-method>BASIC</auth-method> <realm-name>The Restricted Zone</realm-name> </login-config> <!-- ... --> <security-role> <description>The role required to access restricted content </description> <role-name>AuthorizedUser</role-name> </security-role>
位于Web应用程序/受限路径下的URL需要AuthorizedUser角色。
解决方案是使用类似的备用安全框架 Apache Shiro 而不是基于容器的安全性。然后,很容易从受保护的内容中排除资源。使用Shiro你会投入 WEB-INF/shiro.ini :
WEB-INF/shiro.ini
[urls] /info = anon /** = authc
我已经尝试过@ user517491解释的上述方法,但是我的tomcat 7过滤了/ https下的所有流量,但忽略了之前的异常...
<security-constraint> <web-resource-collection> <web-resource-name>app1</web-resource-name> <url-pattern>/webservice/*</url-pattern> </web-resource-collection> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>Protected Context</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>
我如何添加一个例外与http和所有其他流量与https ???