有效用户的Tomcat安全约束

我正在尝试保护tomcat中的资源,以便只有“有效用户”(在域中具有有效登录名和密码的用户)才能访问它。 它们不一定属于领域中的一个群体。 我已尝试使用指令的许多组合而没有成功。 有任何想法吗?

除了auth-constraint,您还要添加到security-constraint:

   *  

您需要在Web应用程序中指定安全角色:

   *  

tomcat中有几个领域实现 – 内存,数据库,JAAS等。 最容易配置(尽管不是最安全)内存的一个,它包含一个XML文件,通常位于conf / tomcat-users.xml下:

      

领域配置在上下文,主机或引擎配置下,如下所示:

  

然后,在web.xml中放置以下定义:

    MRC Customer Care /protected/*   role1     DIGEST YOUR REALM NAME    The role that is required to access the application. Should be on from the realm (the tomcat-users.xml file).  role1  

web.xml部分是从我们的一个Web应用程序中获取(稍作更改)。

如果我们使用Tomcat 8.x,因为提供的server.xml将出现在嵌套的Realm元素中,请在“最外层”Realm元素中添加“allRolesMode =”authOnly“’并更改上述web.xml以进行测试。 例如

      

有关详细信息,请阅读org.apache.catalina.realm.RealmBase.java。

此外,logging.properties中的以下设置非常有用。

 org.apache.catalina.realm.level=ALL org.apache.catalina.realm.useParentHandlers=true org.apache.catalina.authenticator.level=ALL org.apache.catalina.authenticator.useParentHandlers=true