我一直在尝试在我的项目中获取身份验证,但似乎Tomcat的安全约束中的 url-pattern 要么只接受'/ *'或任何其他根级别模式 - 意思是 - 我可以使用
“保护”所有页面<url-pattern>/*</url-pattern>
但如果我尝试类似
的话<url-pattern>/privateClinic/*</url-pattern>
它甚至没有注册,所有页面都“打开”
同样适用于锁定所有页面并添加另一个更具体的安全约束,而不对公用文件夹使用auth-constraint
<url-pattern>/WEB-INF/*</url-pattern>
无法识别模式并且未“解锁”文件夹
提前致谢!
这是整个XML文件,因为它没有锁定任何东西(虽然我喜欢它!):
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>MyClinic</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>MyClinicControl</servlet-name>
<servlet-class>ICM.WelcomeControl</servlet-class>
</servlet>
<!--
<servlet-mapping>
<servlet-name>MyClinicControl</servlet-name>
<url-pattern>/myclinic</url-pattern>
</servlet-mapping>
-->
<welcome-file-list>
<welcome-file>ClinicWelcome.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<security-constraint>
<web-resource-collection>
<web-resource-name>private</web-resource-name>
<url-pattern>/privateClinic/*</url-pattern> <!-- PROBLEM-->
</web-resource-collection>
<auth-constraint>
<role-name>doctor</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>doctor</role-name>
</security-role>
<security-role>
<role-name>estudante</role-name>
</security-role>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/login-error.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>