Java 使用LDAP和SpringLDAP API进行身份验证,而不使用SpringSecurity
我在Sprint启动应用程序中使用SpringLDAP核心插件。 基本上,LDAP模板- 我基本上希望使用SpringLDAP API将下面的xml配置转换为java,并希望避免使用SpringSecurity 我要转换的xml配置是-Java 使用LDAP和SpringLDAP API进行身份验证,而不使用SpringSecurity,java,authentication,spring-boot,ldap,spring-ldap,Java,Authentication,Spring Boot,Ldap,Spring Ldap,我在Sprint启动应用程序中使用SpringLDAP核心插件。 基本上,LDAP模板- 我基本上希望使用SpringLDAP API将下面的xml配置转换为java,并希望避免使用SpringSecurity 我要转换的xml配置是- <ldap-server id="ldapServer" url="ldap://ad.company.com:389" manager-dn="CN=serviceaccount,OU
<ldap-server id="ldapServer"
url="ldap://ad.company.com:389"
manager-dn="CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com"
manager-password="password"/>
<authentication-manager>
<ldap-authentication-provider
server-ref="ldapServer"
user-search-base="dc=ad,dc=company,dc=com"
user-search-filter="sAMAccountName={0}"
group-search-filter="member={0}"
group-search-base="ou=Groups,dc=ad,dc=company,dc=com"
group-role-attribute="cn"/>
</authentication-manager>
这就是我试图调用身份验证的方式-
如果发生身份验证,此代码段所属的方法将返回布尔值
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("sAMAccountName", userloginName));
return ldapTemplate.authenticate("OU=Service Accounts", filter.encode(), userPassword);
这不起作用,我得到的错误是:
No results found for search, base: 'OU=Service Accounts'; filter: '(sAMAccountName=usernameIinput)'.
我想知道如何使用LDAP API配置以下xml属性
group-search-filter="member={0}"
group-search-base="ou=Groups,dc=ad,dc=company,dc=com"
group-role-attribute="cn"/>
还有,我还缺少什么?为什么这不起作用?
任何帮助都将不胜感激 我能弄明白这一点 //使用LDAPTemplate的LDAP连接
@Configuration
public class LdapConfiguration {
@Bean
public LdapContextSource contextSource(){
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://companyurl.com:389");
contextSource.setUserDn("CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com");
contextSource.setPassword("secretpassword");
return contextSource;
}
@Bean
public LdapTemplate ldapTemplate(){
LdapTemplate template = new LdapTemplate(contextSource());
return template;
}
}
//认证部分
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("mailNickname", username));
Boolean authenticate = ldapTemplate.authenticate(base, filter.encode(), userpassword);
我能弄明白这一点 //使用LDAPTemplate的LDAP连接
@Configuration
public class LdapConfiguration {
@Bean
public LdapContextSource contextSource(){
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://companyurl.com:389");
contextSource.setUserDn("CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com");
contextSource.setPassword("secretpassword");
return contextSource;
}
@Bean
public LdapTemplate ldapTemplate(){
LdapTemplate template = new LdapTemplate(contextSource());
return template;
}
}
//认证部分
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("mailNickname", username));
Boolean authenticate = ldapTemplate.authenticate(base, filter.encode(), userpassword);
我们是否可以在不设置contextSource.setUserDN()和contextSource.setPassword()的情况下执行ldapTemplate.authenticate()。@TXT,contextSource中的userDN参数是必需的参数。如果不传递此参数,您将无法获取ldap连接。我们是否可以在不设置contextSource.setUserDN()和contextSource.setPassword()的情况下执行ldapTemplate.authenticate()。@TXT,contextSource中的userDN参数是必需的参数。如果不传递此参数,您将无法获取ldap连接。