Tomcat JNDIRealm 验证并忽略所有角色

标签 tomcat authentication ldap authorization jndi

Tomcat 容器使用 LDAP 来验证用户

我正在尝试用 LDAP 身份验证替换 Tomcat 的 inMemory 用户数据库。在 conf/server.xml 中进行更改

当用户登录弹出窗口时,我想将用户凭据与 ldap 进行比较。

 <Realm className="org.apache.catalina.realm.JNDIRealm" 
 connectionName="abcusername" 
 connectionPassword="mypassword" 
 connectionURL="ldap://ada.cab.ast.com:389" 
 debug="10" userBase="DC=cab,DC=ast,DC=com" 
 userSearch="(cn={0})" 
 userSubtree="true"/>  

我的web.xml,如果用户通过身份验证则没有角色限制

<security-constraint>
    <web-resource-collection>
        <web-resource-name>HTML Manager interface (for humans)</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Tomcat Manager Application</realm-name>
</login-config>

当我提供正确的用户名和密码时,我在下面的日志中看到用户已通过身份验证但我猜授权失败,但失败了。 任何帮助表示赞赏。

AuthenticatorBase.register Authenticated 'fkhan002c' with type 'BASIC'
AuthenticatorBase.invoke  Calling accessControl()
hasResourcePermission   Checking roles GenericPrincipal[fkhan002c()]
AuthenticatorBase.invoke  Failed accessControl() test

最佳答案

发现问题

Web-resource-collection 用于 java 资源,因为我正在尝试授权静态内容,正如您在下面看到的那样,我也需要静态内容。

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Secure contents</web-resource-name>
            <url-pattern>/index.html</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
    </security-constraint>

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Secure content</realm-name>
    </login-config>


<security-role>
       <description>
           This logical role includes all administrative users
       </description>
       <role-name>*</role-name>
   </security-role>

关于Tomcat JNDIRealm 验证并忽略所有角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26765948/

相关文章:

tomcat - 部署war时 'asset'后双斜杠

c# - 如何以编程方式登录到 ASP.NET Identity 2?

python - Python 中的 NTLM 身份验证

linux - 使用 Active Directory 的 Subversion 服务器

kubernetes - 无法从 Ldapmain 对您进行身份验证,因为 "Invalid credentials for <username>"- 通过 Helm Chart 安装的 Gitlab 社区版

Java 8 顺序流非常高地增加了 CPU 使用率

java - 将启用 Jersey 的 servlet 部署到 Tomcat : Exceptions

Spring Tomcat 部署 : Soap call returns "405: Method not allowed"

authentication - 当 mqtt 客户端在 TLS 握手期间不提供公钥证书时,是否存在任何可以预期的安全问题?

active-directory - 用户可以成为Active Directory中多个组织单位(OU)的成员吗?