Sprintブートアプリケーションでspring-ldap-coreプラグインを使用しています。基本的に、LDAPTemplate- http://docs.spring.io/spring-ldap/docs/current/apidocs/org/springframework/ldap/core/LdapTemplate.html
基本的に、Spring LDAP APIを使用して以下のxml構成をJavaに変換し、Springセキュリティの使用を避けたいと考えています。
変換したいxml構成は-
<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>
これが私のJavaコードです-
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.ldap.authentication.DefaultValuesAuthenticationSourceDecorator;
@Configuration
public class LdapConfiguration {
@Bean
public LdapContextSource contextSource(){
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://ad.company.com:389");
contextSource.setBase("DC=ad,DC=company,DC=com");
contextSource.setUserDn("CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com");
contextSource.setPassword("password");
contextSource.afterPropertiesSet();
return contextSource;
}
@Bean
public LdapTemplate ldapTemplate(){
LdapTemplate template = new LdapTemplate(contextSource());
try {
template.afterPropertiesSet();
} catch (Exception e) {
e.printStackTrace();
}
return template;
}
}
これが私が認証を呼び出そうとしている方法です-このスニペットが含まれているメソッドは、認証が発生した場合にブール値を返します
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);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加