LDAP-аутентификация Active Directory с использованием spirng boot - PullRequest
0 голосов
/ 28 января 2019

Как сделать аутентификацию LDAP в активном каталоге с помощью весенней загрузки.Я новичок в весенней загрузке, кто-нибудь может мне помочь?Кто-нибудь может дать мне полный пример?

Я пытался понять следующий код, но мне нужна полная поддержка, например, как мы связываем имя пользователя и пароль из формы входа в систему, а затем как мы выполняем аутентификацию.

Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String userName = auth.getName();
String password = (String)auth.getCredentials();


package com.mycompany;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider;

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
{

    @Value("${ldap.url:ldap://mycompany.com:389}") private String url;
    @Value("${ldap.domain}:mycompany.com") private String domain;
    @Value("${ldap.userDNPattern:}") private String userDNPattern;

    @Override
    protected void configure(HttpSecurity http) throws Exception
    {
        http
                .authorizeRequests()
                .anyRequest().fullyAuthenticated()
                .httpBasic();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        ActiveDirectoryLdapAuthenticationProvider adProvider = 
                    new ActiveDirectoryLdapAuthenticationProvider(domain,url);
        adProvider.setConvertSubErrorCodesToExceptions(true);
        adProvider.setUseAuthenticationRequestCredentials(true);

        // set pattern if it exists
        // The following example would authenticate a user if they were a member
        // of the ServiceAccounts group
        // (&(objectClass=user)(userPrincipalName={0})
        //   (memberof=CN=ServiceAccounts,OU=alfresco,DC=mycompany,DC=com))
        if (userDNPattern != null && userDNPattern.trim().length() > 0)
        {
            adProvider.setSearchFilter(userDNPattern);
        }
        auth.authenticationProvider(adProvider);

        // don't erase credentials if you plan to get them later
        // (e.g using them for another web service call)
        auth.eraseCredentials(false);
     }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...