简体   繁体   English

针对散列密码在Apache上进行LDAP身份验证

[英]LDAP authentication on Apache against hashed password

I have a setup with an apache HTTP server front facing tomcat server. 我有一个面向Tomcat服务器的Apache HTTP服务器前端安装程序。 The Apache server uses LDAP for authentication. Apache服务器使用LDAP进行身份验证。

I am using an Embedded LDAP server (Apache DS) and have configured to disable anonymous bind using 我正在使用嵌入式LDAP服务器(Apache DS),并已配置为使用禁用匿名绑定

service.setAllowAnonymousAccess(false); // Disable Anonymous Access

service.setAccessControlEnabled(true); // Enable basic access control check (allow only  System Admin to login to LDAP Server)

My application uses Spring LDAP to connect and perform user operations like Adding a user. 我的应用程序使用Spring LDAP连接并执行用户操作,例如添加用户。 I have configured it in spring.xml as follows: 我已经在spring.xml中将其配置如下:

  <bean id="ldapContextSource" class="org.springframework.ldap.core.support.LdapContextSource">
           <property name="url" value="ldap://localhost:389" />
           <property name="base" value="dc=test,dc=com" />
           <property name="userDn" value="uid=admin,ou=system" />
           <property name="password" value="secret" />
      </bean>

Apache httpd.conf is configured to use basic auth Apache httpd.conf配置为使用基本身份验证

AuthLDAPBindDN "uid=admin,ou=system"
AuthLDAPBindPassword "{SHA}<Hash for secret>"

ISSUE 1 : When trying to login to ldap server using a client (say jexplorer), I am able to login using both Hashed password and using the plain text "secret". 问题1:当尝试使用客户端(例如jexplorer)登录ldap服务器时,我能够使用哈希密码和纯文本“ secret”登录。 How is that possible? 那怎么可能?

In this case , if someone gets to know the AuthLDAPBindDN and AuthLDAPBindPassword which is a hashed one in my case, They will be able to login using the same to the LDAP server with full access which is a security threat. 在这种情况下,如果有人知道AuthLDAPBindDN和AuthLDAPBindPassword(在我的情况下是散列的),则他们将能够使用该帐户登录到具有完全访问权限的LDAP服务器,这是安全威胁。

Also, I want to replace the password in spring.xml with a hashed one. 另外,我想用一个散列密码替换spring.xml中的密码。 Since, admin can change the LDAP password, How do I ensure my application to use the updated hashed password as we are hard-coding it in spring.xml? 由于admin可以更改LDAP密码,因此当我们在spring.xml中对它进行硬编码时,如何确保我的应用程序使用更新的哈希密码?

With regards to your second question: you should typically never hardcode stuff like server URLs, user names, passwords, etc in your XML file. 关于第二个问题:您通常不应在XML文件中对服务器URL,用户名,密码等内容进行硬编码。 These things should typically be externalized to a property file and processed using <context:property-placeholder> . 这些东西通常应该外部化到属性文件中,并使用<context:property-placeholder> Say, for instance, that you have a property file with the following contents: 举例来说,假设您有一个包含以下内容的属性文件:

ldap.server.url=ldap://localhost:389
ldap.base=dc=test,dc=com
ldap.userDn=uid=admin,ou=system
ldap.password=secret

You can then refer to these properties in your configuration file, eg: 然后,您可以在配置文件中引用这些属性,例如:

 <context:property-placeholder ignore-resource-not-found="true"
                               location="classpath:/ldap.properties,
                                         file:/etc/mysystem/ldap.properties" />

 <bean id="ldapContextSource" class="org.springframework.ldap.core.support.LdapContextSource">
       <property name="url" value="${ldap.server.url}" />
       <property name="base" value="${ldap.base}" />
       <property name="userDn" value="${ldap.userDn}" />
       <property name="password" value="${ldap.password}" />
  </bean>

Spring will automatically replace the stuff within ${} with the corresponding values from your properties file. Spring会自动使用属性文件中的相应值替换${}的内容。

Note that I specified two property file locations in the <context:property-placeholder> element, and that I also included ignore-resource-not-found="true" . 请注意,我在<context:property-placeholder>元素中指定了两个属性文件位置,并且还包括了ignore-resource-not-found="true" This is useful, because it enables you to include a properties file with your source for simple development setup, but in production, if you place a properties file under /etc/mysystem/ldap.properties , this will override the stuff in the bundled properties file. 这很有用,因为它使您可以在源代码中包含属性文件以进行简单的开发设置,但是在生产中,如果将属性文件放在/etc/mysystem/ldap.properties下,则会覆盖捆绑属性中的内容文件。

This way, if the password is changed by admin in production environment, all you need to do is change the properties file; 这样,如果在生产环境中由admin更改了密码,则只需更改属性文件即可; you don't need to rebuild the application. 您无需重建应用程序。

With regards to why the apache DS accepts the hashed password; 关于为什么Apache DS接受哈希密码; one reason might be that your LDAP server is set up to accept anonymous access for read operation, which means that it actually doesn't authenticate at all when you're just reading. 原因之一可能是您的LDAP服务器设置为接受匿名访问以进行读取操作,这意味着在您仅读取内容时,它实际上根本不进行身份验证。 Might be something else though, you'll have to direct the question to Apache DS support. 但是,可能还有其他事情,您必须将问题转给Apache DS支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM