java - Tomcat 的 LDAP 身份验证 - 403 错误

标签 java tomcat ldap

我想使用 LDAP 保护我的 Tomcat 服务器。

首先,我针对在线 LDAP 测试服务器进行了尝试,它的详细信息存在于 http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ 中。 .

我的 tomcat 服务器将所有请求从端口 8080 重定向到端口 8433,然后它询问用户名和密码,然后(当我输入正确的数据时)返回 403 错误页面。

问题是什么?

server.xml 中的相关部分:

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.JNDIRealm" debug="10"
                            connectionURL="ldap://ldap.forumsys.com:389"
                            alternateURL="ldaps://ldap.forumsys.com:636"
                            userBase="dc=example,dc=com"
                            userSearch="(uid={0})"
                            userSubtree="true"
                            userRoleName="l"
                            connectionName="cn=read-only-admin,dc=example,dc=com"
                            connectionPassword="password"
            /> 
  </Realm>

web.xml 中的相关部分:

    <welcome-file-list>
        <welcome-file>main.html</welcome-file>
    </welcome-file-list>

   <security-constraint>
       <web-resource-collection>
           <web-resource-name>Authenticated area</web-resource-name>
           <url-pattern>/main.html</url-pattern>
           <http-method>DELETE</http-method>
           <http-method>GET</http-method>
           <http-method>HEAD</http-method>
           <http-method>POST</http-method>
           <http-method>PUT</http-method>
       </web-resource-collection>

       <auth-constraint>
    <role-name>tomcat</role-name>
           <role-name>Admin</role-name>
           <role-name>Authenticated</role-name>
           <role-name>mathematicians</role-name>
           <role-name>gauss</role-name>
           <role-name>galieleo</role-name>
       </auth-constraint>

   </security-constraint>

   <login-config>
       <auth-method>BASIC</auth-method>
   </login-config>

   <security-role>
       <description>
           This logical role includes all authenticated users
       </description>
    <role-name>tomcat</role-name>
       <role-name>site-users</role-name>
       <role-name>Authenticated</role-name>
       <role-name>mathematicians</role-name>
       <role-name>gauss</role-name>
       <role-name>galieleo</role-name>
   </security-role>  
</web-app>

tomcat-users.xml 中的相关部分:

<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
  <role rolename="mathematicians"/>
  <role rolename="site-users"/>
  <role rolename="tomcat"/>
  <user username="gauss" roles="site-users,user,tomcat" />
</tomcat-users>

我使用用户名“gauss”和密码“password”

最佳答案

什么是 userRoleName="l"这应该是 LDAP 中用户条目的 l=locale 属性,值必须是其中之一

<role-name>tomcat</role-name>
<role-name>site-users</role-name>
<role-name>Authenticated</role-name>
<role-name>mathematicians</role-name>
<role-name>gauss</role-name>
<role-name>galieleo</role-name>

如果您想要任何经过身份验证的用户,只需:

<role-name>*</role-name>

Try looking here for more information.

关于java - Tomcat 的 LDAP 身份验证 - 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35437454/

相关文章:

java - 使用框架状态变量更新 JFrame 中的 JPanel 内容

tomcat - 从错误页面屏蔽/隐藏 tomcat 版本的最佳方法是什么?

java - 使用 Java 的 LDAP 身份验证

SQL LDAP 查询问题

java - 替换变量时 Oracle OpenScript "Error reading file"

java - 如何使用 Selenium webdriver 在组合框中输入信息并进行查找?

security - Tomcat 文件正在上传 - 安全漏洞

jsp - 在另一台服务器上运行 Tomcat

php - PHP 中的 LDAP 身份验证 - 在不提供密码的情况下进行身份验证

java - 从 Java 启动文件