Как настроить Spring Security PasswordComparisonAuthenticator

Я могу привязаться к встроенному серверу ldap на моей локальной машине с помощью следующего bean-компонента:

<b:bean id="secondLdapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <b:constructor-arg>
        <b:bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
            <b:constructor-arg ref="contextSource" />
            <b:property name="userSearch">
                <b:bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
                  <b:constructor-arg index="0" value="ou=people"/>
                  <b:constructor-arg index="1" value="(uid={0})"/>
                  <b:constructor-arg index="2" ref="contextSource" />
                </b:bean>
            </b:property>
        </b:bean>
    </b:constructor-arg>
    <b:constructor-arg>
        <b:bean class="com.company.security.ldap.BookinLdapAuthoritiesPopulator">
        </b:bean>
    </b:constructor-arg>
</b:bean>

однако, когда я пытаюсь пройти аутентификацию с помощью PasswordComparisonAuthenticator, он неоднократно терпит неудачу в событии с неверными учетными данными:

 <b:bean id="ldapAuthProvider"
    class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <b:constructor-arg>
        <b:bean
            class="org.springframework.security.ldap.authentication.PasswordComparisonAuthenticator">
            <b:constructor-arg ref="contextSource" />
            <b:property name="userDnPatterns">
                <b:list>
                    <b:value>uid={0},ou=people</b:value>
                </b:list>
            </b:property>
        </b:bean>
    </b:constructor-arg>
    <b:constructor-arg>
        <b:bean class="com.company.security.ldap.BookinLdapAuthoritiesPopulator">
        </b:bean>
    </b:constructor-arg>
</b:bean>

С помощью отладки я вижу, что метод аутентификации получает DN из файла ldif, но затем пытается сравнить пароли, однако он использует LdapShaPasswordEncoder (по умолчанию), где пароль хранится в виде открытого текста в файле, и здесь аутентификация не проходит.

Вот bean-компонент диспетчера аутентификации, ссылающийся на предпочтительный bean-компонент аутентификации:

<authentication-manager>

    <authentication-provider ref="ldapAuthProvider"/>

    <authentication-provider user-service-ref="userDetailsService">
        <password-encoder hash="md5" base64="true">
            <salt-source system-wide="secret"/>
        </password-encoder>
    </authentication-provider>
</authentication-manager>

С другой стороны, устанавливаю ли я кодировщик паролей в ldapAuthProvider в открытый текст или просто оставляю его пустым, похоже, это не имеет значения. Любая помощь будет принята с благодарностью.

Спасибо


person denlab    schedule 20.04.2010    source источник


Ответы (1)


Мне удалось переопределить LdapShaPasswordEncoder по умолчанию в PasswordComparisonAuthenticator, внедрив PlainTextPasswordEncoder в свойство passwordEncoder:

 <b:bean id="ldapAuthProvider"
    class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <b:constructor-arg>
        <b:bean
            class="org.springframework.security.ldap.authentication.PasswordComparisonAuthenticator">
            <b:constructor-arg ref="contextSource" />
            <b:property name="passwordEncoder">
                <b:bean class="org.springframework.security.authentication.encoding.PlaintextPasswordEncoder"></b:bean>
            </b:property>
            <b:property name="userDnPatterns">
                <b:list>
                    <b:value>uid={0},ou=people</b:value>
                </b:list>
            </b:property>
        </b:bean>
    </b:constructor-arg><b:constructor-arg>
        <b:bean class="com.company.security.ldap.BookinLdapAuthoritiesPopulator">
        </b:bean>
    </b:constructor-arg>
</b:bean>

И теперь он не преобразует предоставленный ввод в SHA перед сравнением...

person denlab    schedule 21.04.2010